dialysis_api_controller.go 448KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. }
  2591. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 {
  2592. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2593. if adminUserInfo.Org.Id != 10702 {
  2594. if evaluation.SystolicBloodPressure == 0 {
  2595. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2596. if adminUserInfo.Org.Id == 10693 {
  2597. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2598. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2599. }
  2600. pre := models.PredialysisEvaluation{
  2601. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2602. }
  2603. fmt.Println("prew", pre)
  2604. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2605. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2606. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2607. redis := service.RedisClient()
  2608. redis.Set(key, "", time.Second)
  2609. redis.Set(keyOne, "", time.Second)
  2610. defer redis.Close()
  2611. fmt.Println(getNurseErr)
  2612. }
  2613. }
  2614. if adminUserInfo.Org.Id != 10702 {
  2615. if evaluation.DiastolicBloodPressure == 0 {
  2616. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2617. if adminUserInfo.Org.Id == 10693 {
  2618. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2619. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2620. }
  2621. pres := models.PredialysisEvaluation{
  2622. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2623. }
  2624. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2625. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2626. redis := service.RedisClient()
  2627. redis.Set(key, "", time.Second)
  2628. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2629. redis.Set(keyOne, "", time.Second)
  2630. defer redis.Close()
  2631. fmt.Println(getNurseErr)
  2632. }
  2633. }
  2634. if adminUserInfo.Org.Id != 10702 {
  2635. if evaluation.PulseFrequency == 0 {
  2636. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2637. if adminUserInfo.Org.Id == 10693 {
  2638. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2639. evaluation.PulseFrequency = pulseFrequency
  2640. }
  2641. press := models.PredialysisEvaluation{
  2642. PulseFrequency: evaluation.PulseFrequency,
  2643. }
  2644. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2646. redis := service.RedisClient()
  2647. redis.Set(key, "", time.Second)
  2648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2649. redis.Set(keyOne, "", time.Second)
  2650. defer redis.Close()
  2651. fmt.Println(getNurseErr)
  2652. }
  2653. }
  2654. if evaluation.Temperature == 0 {
  2655. evaluation.Temperature = fmonitorRecords.Temperature
  2656. press := models.PredialysisEvaluation{
  2657. Temperature: evaluation.Temperature,
  2658. }
  2659. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. redis := service.RedisClient()
  2662. redis.Set(key, "", time.Second)
  2663. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id == 9583 {
  2670. //获取透析处方的最后一条数据
  2671. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2672. if diaerr != nil {
  2673. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. }
  2677. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2678. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2679. }
  2680. }
  2681. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2682. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2694. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2695. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2696. }
  2697. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2698. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2699. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2700. }
  2701. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2702. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2703. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2704. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2705. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2708. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2709. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2710. }
  2711. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2712. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2713. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2714. }
  2715. if lastAssessmentAfterDislysis != nil {
  2716. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2717. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2718. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2719. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2720. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2721. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2722. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2723. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2724. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2725. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2726. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2727. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2728. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2729. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2730. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2731. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2732. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2733. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2734. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2735. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2736. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2737. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2738. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2739. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2740. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2741. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2742. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2743. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2744. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2745. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2746. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2747. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2748. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2749. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2750. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2751. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2752. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2753. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2754. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2755. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2756. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2757. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2758. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2759. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2760. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2761. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2762. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2763. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2764. if tempassessmentAfterDislysis.PatientId == 18695 {
  2765. tempassessmentAfterDislysis.ActualDisplacement = 0
  2766. }
  2767. if adminUserInfo.Org.Id != 10375 {
  2768. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2769. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2774. }
  2775. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2776. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2777. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2778. }
  2779. }
  2780. finish := models.XtDialysisFinish{
  2781. IsFinish: 1,
  2782. UserOrgId: adminUserInfo.Org.Id,
  2783. Status: 1,
  2784. Ctime: time.Now().Unix(),
  2785. Mtime: 0,
  2786. Module: 9,
  2787. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2788. Sourse: 1,
  2789. PatientId: tempassessmentAfterDislysis.PatientId,
  2790. }
  2791. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2792. if dialysisFinish.ID == 0 {
  2793. service.CreateDialysisFinish(finish)
  2794. }
  2795. //孝康
  2796. if adminUserInfo.Org.Id == 10693 {
  2797. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2798. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2799. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2800. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2801. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2802. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2803. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2804. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2805. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2806. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2807. }
  2808. if adminUserInfo.Org.Id == 10697 {
  2809. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2810. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2811. lastWeightAfter.LastAfterWeight = floatAfeter
  2812. }
  2813. if adminUserInfo.Org.Id == 10721 {
  2814. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2815. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2816. }
  2817. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2818. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2819. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2820. redis := service.RedisClient()
  2821. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2822. redis.Set(keyOne, "", time.Second)
  2823. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2824. redis.Set(keyTwo, "", time.Second)
  2825. defer redis.Close()
  2826. //清空key 值
  2827. redis.Set(key, "", time.Second)
  2828. if err != nil {
  2829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2830. return
  2831. }
  2832. if dialysisOrder == nil {
  2833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2834. return
  2835. }
  2836. if dialysisOrder.Stage == 2 {
  2837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2838. return
  2839. }
  2840. if dialysisOrder.Stage == 1 {
  2841. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2842. finish := models.XtDialysisFinish{
  2843. IsFinish: 1,
  2844. UserOrgId: adminUserInfo.Org.Id,
  2845. Status: 1,
  2846. Ctime: time.Now().Unix(),
  2847. Mtime: 0,
  2848. Module: 8,
  2849. RecordDate: recordDate.Unix(),
  2850. Sourse: 1,
  2851. PatientId: id,
  2852. }
  2853. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2854. if dialysisFinish.ID == 0 {
  2855. service.CreateDialysisFinish(finish)
  2856. }
  2857. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2858. redis := service.RedisClient()
  2859. defer redis.Close()
  2860. //清空key 值
  2861. redis.Set(key, "", time.Second)
  2862. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2863. redis.Set(keyOne, "", time.Second)
  2864. //结束时候透析次数加1
  2865. service.UpdateSolutionByPatientId(id)
  2866. //下机完自动消毒,针对长沙南雅
  2867. if dialysisOrder.Stage == 1 {
  2868. 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 {
  2869. //根据床位号获取设备型号
  2870. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2871. //查询使用消毒最后一条消毒记录
  2872. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2873. fmt.Println("err", err)
  2874. if err == gorm.ErrRecordNotFound {
  2875. //查找排班
  2876. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2877. //查询改设备是否有消毒计划
  2878. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2879. //根据床位号获取设备id
  2880. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2881. //查询病人信息
  2882. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2883. var con = ""
  2884. if patients.IsInfectious == 0 {
  2885. con = ""
  2886. }
  2887. if patients.IsInfectious == 1 {
  2888. con = "无"
  2889. }
  2890. if patients.IsInfectious == 2 {
  2891. con = "有"
  2892. }
  2893. if errcode == nil {
  2894. var end_time int64
  2895. end_time = endDate.Unix() + plan.DisinfecTime*60
  2896. //新增消毒
  2897. information := models.DeviceInformation{
  2898. Date: dialysisOrder.DialysisDate,
  2899. Zone: dialysisOrder.ZoneId,
  2900. Class: dialysisOrder.SchedualType,
  2901. BedNumber: dialysisOrder.BedID,
  2902. PatientId: dialysisOrder.PatientId,
  2903. DialysisMode: scheduleByPatient.ModeId,
  2904. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2905. Disinfection: 1,
  2906. DialysisConcentration: 1,
  2907. DisinfectionStatus: 1,
  2908. Move: 1,
  2909. UserOrgId: dialysisOrder.UserOrgId,
  2910. DisinfectType: plan.Way,
  2911. DisinfectantType: plan.MachineDisinfectant,
  2912. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2913. Disinfectant: plan.Disinfectant,
  2914. Ctime: time.Now().Unix(),
  2915. Status: 1,
  2916. SignName: nurseID,
  2917. EquimentId: addmacher.ID,
  2918. DisinfectionResidue: 2,
  2919. Bed: addmacher.BedNumber,
  2920. StartTime: dialysisOrder.StartTime,
  2921. EndTime: dialysisOrder.EndTime,
  2922. Contagion: con,
  2923. WeightLoss: 0,
  2924. Hyperfiltratio: 0,
  2925. DialysisHour: "",
  2926. MachineRun: 1,
  2927. DisinfecStartime: endDate.Unix(),
  2928. DisinfecEndtime: end_time,
  2929. }
  2930. err := service.CreateInformationTwo(&information)
  2931. fmt.Println("报错", err)
  2932. }
  2933. }
  2934. }
  2935. }
  2936. dialysisOrder.Stage = 2
  2937. dialysisOrder.FinishNurse = nurseID
  2938. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2939. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2940. dialysisOrder.EndTime = endDate.Unix()
  2941. // 长沙南雅需求
  2942. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2943. //获取最后1条监测的数据
  2944. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2945. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2946. var accumulatedBloodVolume float64
  2947. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2948. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2949. fmt.Println(err)
  2950. // 查询未执行的医嘱
  2951. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2952. for _, item := range doctorAdvice {
  2953. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2954. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2955. redis := service.RedisClient()
  2956. //清空key 值
  2957. redis.Set(key, "", time.Second)
  2958. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2959. redis.Set(keyTwo, "", time.Second)
  2960. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2961. redis.Set(keyThree, "", time.Second)
  2962. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2963. theTime := toTime.Format("2006-01-02")
  2964. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2965. redis.Set(keyFour, "", time.Second)
  2966. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2967. redis.Set(keyFive, "", time.Second)
  2968. defer redis.Close()
  2969. }
  2970. }
  2971. go func() {
  2972. ssoDomain := beego.AppConfig.String("call_domain")
  2973. api := ssoDomain + "/index/downpatient"
  2974. values := make(url.Values)
  2975. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2976. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2977. values.Set("patient_id", strconv.FormatInt(id, 10))
  2978. http.PostForm(api, values)
  2979. }()
  2980. if err == nil {
  2981. c.ServeSuccessJSON(map[string]interface{}{
  2982. "dialysisOrder": dialysisOrder,
  2983. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2984. })
  2985. } else {
  2986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2987. }
  2988. }
  2989. }
  2990. func (c *DialysisAPIController) GetAllZone() {
  2991. adminUserInfo := c.GetMobileAdminUserInfo()
  2992. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2993. if err == nil {
  2994. c.ServeSuccessJSON(map[string]interface{}{
  2995. "zone": zone,
  2996. })
  2997. }
  2998. }
  2999. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3000. adminUserInfo := c.GetMobileAdminUserInfo()
  3001. page, _ := c.GetInt64("page", 1)
  3002. limit, _ := c.GetInt64("limit", 10)
  3003. schedulType, _ := c.GetInt64("schedul_type", 0)
  3004. startTime, _ := c.GetInt64("schedul_time", 0)
  3005. partitionType, _ := c.GetInt64("partition_type", 0)
  3006. keywords := c.GetString("keywords")
  3007. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3008. if err == nil {
  3009. c.ServeSuccessJSON(map[string]interface{}{
  3010. "schedule": dialysisSchedule,
  3011. })
  3012. }
  3013. return
  3014. }
  3015. // /m/api/dialysis/start [post]
  3016. // @param patient_id:int
  3017. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3018. // @param nurse:int 上机护士
  3019. // @param bed:int 床位号
  3020. func (this *DialysisAPIController) StartDialysis() {
  3021. patientID, _ := this.GetInt64("patient_id")
  3022. recordDateStr := this.GetString("record_date")
  3023. nurseID, _ := this.GetInt64("start_nurse")
  3024. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3025. blood_drawing, _ := this.GetInt64("blood_drawing")
  3026. schedual_type, _ := this.GetInt64("schedual_type")
  3027. bedID, _ := this.GetInt64("bed")
  3028. start_time := this.GetString("start_time")
  3029. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3030. change_nurse, _ := this.GetInt64("change_nurse")
  3031. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3032. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3033. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3034. puncture_needle := this.GetString("puncture_needle")
  3035. puncture_way := this.GetString("puncture_way")
  3036. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3037. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3038. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3039. zone_id, _ := this.GetInt64("zone_id")
  3040. elecsign := this.GetString("url")
  3041. nuclein_date_str := this.GetString("nuclein_date_str")
  3042. schedule_remark := this.GetString("schedule_remark")
  3043. order_remark := this.GetString("order_remark")
  3044. catheter_operation := this.GetString("catheter_operation")
  3045. blood_flow_volume := this.GetString("blood_flow_volume")
  3046. dialysis_strainer := this.GetString("dialysis_strainer")
  3047. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3049. return
  3050. }
  3051. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3052. if parseStartDateErr != nil {
  3053. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3055. return
  3056. }
  3057. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3058. if parseErr != nil {
  3059. this.ErrorLog("时间解析失败:%v", parseErr)
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3061. return
  3062. }
  3063. adminUserInfo := this.GetMobileAdminUserInfo()
  3064. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3065. if getPatientErr != nil {
  3066. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3068. return
  3069. } else if patient == nil {
  3070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3071. return
  3072. }
  3073. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3074. if getNurseErr != nil {
  3075. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. } else if nurse == nil {
  3079. this.ErrorLog("护士不存在")
  3080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3081. return
  3082. }
  3083. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3084. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3085. if getDeviceNumberErr != nil {
  3086. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3088. return
  3089. } else if deviceNumber == nil {
  3090. this.ErrorLog("床位号不存在")
  3091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3092. return
  3093. }
  3094. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3095. if getRecordErr != nil {
  3096. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3098. return
  3099. } else if dialysisRecord != nil {
  3100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3101. return
  3102. }
  3103. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3104. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3105. timeLayout := "2006-01-02 15:04:05"
  3106. loc, _ := time.LoadLocation("Local")
  3107. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3108. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3109. schedulestartTime := theStartTime.Unix()
  3110. scheduleendTime := theEndTime.Unix()
  3111. var theNucleinDate int64
  3112. timeLayoutOne := "2006-01-02"
  3113. if len(nuclein_date_str) > 0 {
  3114. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3115. if err != nil {
  3116. utils.ErrorLog(err.Error())
  3117. }
  3118. theNucleinDate = theTime.Unix()
  3119. }
  3120. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3121. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3122. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3123. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3124. //查询该床位是否有人用了
  3125. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3126. if err == gorm.ErrRecordNotFound { //空床位
  3127. // 修改了床位逻辑
  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. xtSchedule := models.Schedule{
  3135. PartitionId: deviceNumber.ZoneID,
  3136. BedId: bedID,
  3137. ScheduleType: schedual_type,
  3138. UpdatedTime: time.Now().Unix(),
  3139. }
  3140. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3141. if err != nil {
  3142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3143. return
  3144. }
  3145. }
  3146. } else if err == nil {
  3147. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3148. if order.ID > 0 { //该机位被其他人占用了
  3149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3150. return
  3151. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3152. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3153. if daySchedule.ID > 0 {
  3154. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3155. if err != nil {
  3156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3157. return
  3158. }
  3159. }
  3160. }
  3161. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3163. return
  3164. }
  3165. //else if order.ID == 0 { //该床位没被占用
  3166. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3167. // if daySchedule.ID > 0 {
  3168. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3169. // //daySchedule.BedId = bedID
  3170. // //daySchedule.ScheduleType = schedual_type
  3171. // //daySchedule.UpdatedTime = time.Now().Unix()
  3172. // //err := service.UpdateSchedule(&daySchedule)
  3173. // xtSchedule := models.Schedule{
  3174. // PartitionId: deviceNumber.ZoneID,
  3175. // BedId: bedID,
  3176. // ScheduleType: schedual_type,
  3177. // UpdatedTime: time.Now().Unix(),
  3178. // }
  3179. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3180. // if err != nil {
  3181. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3182. // return
  3183. // }
  3184. // }
  3185. //}
  3186. //}
  3187. } else if err != nil {
  3188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3189. return
  3190. }
  3191. // 查询信息规挡的设置天数
  3192. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3193. if infor.ID > 0 && infor.WeekDay > 0 {
  3194. var cha_time int64
  3195. timeNowStr := time.Now().Format("2006-01-02")
  3196. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3197. //今日的日期减去设置的日期
  3198. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3199. if cha_time >= recordDate.Unix() {
  3200. //查询审核是否允许
  3201. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3202. //申请状态不允许的情况 拒绝修改
  3203. if infor.ApplicationStatus != 1 {
  3204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3205. return
  3206. }
  3207. }
  3208. }
  3209. dialysisRecord = &models.DialysisOrder{
  3210. DialysisDate: recordDate.Unix(),
  3211. UserOrgId: adminUserInfo.Org.Id,
  3212. PatientId: patientID,
  3213. Stage: 1,
  3214. BedID: bedID,
  3215. StartNurse: nurseID,
  3216. Status: 1,
  3217. StartTime: startDate.Unix(),
  3218. CreatedTime: time.Now().Unix(),
  3219. UpdatedTime: time.Now().Unix(),
  3220. PunctureNurse: puncture_nurse,
  3221. Creator: adminUserInfo.AdminUser.Id,
  3222. Modifier: adminUserInfo.AdminUser.Id,
  3223. SchedualType: schedual_type,
  3224. WashpipeNurse: washpipe_nurse,
  3225. ChangeNurse: change_nurse,
  3226. DifficultPunctureNurse: difficult_puncture_nurse,
  3227. NewFistulaNurse: new_fistula_nurse,
  3228. ZoneId: zone_id,
  3229. QualityNurseId: quality_nurse_id,
  3230. PunctureNeedle: puncture_needle,
  3231. PunctureWay: puncture_way,
  3232. DialysisIrrigation: dialysis_irrigation,
  3233. DialysisDialyszers: dialysis_dialyszers,
  3234. BloodAccessId: blood_access_id,
  3235. Url: elecsign,
  3236. NucleinDate: theNucleinDate,
  3237. ScheduleRemark: schedule_remark,
  3238. OrderRemark: order_remark,
  3239. CatheterOperation: catheter_operation,
  3240. BloodFlowVolume: blood_flow_volume,
  3241. BloodDrawing: blood_drawing,
  3242. DialysisStrainer: dialysis_strainer,
  3243. }
  3244. //查询该床位是否有人用了
  3245. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3246. if errorscode == gorm.ErrRecordNotFound {
  3247. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3248. finish := models.XtDialysisFinish{
  3249. IsFinish: 1,
  3250. UserOrgId: adminUserInfo.Org.Id,
  3251. Status: 1,
  3252. Ctime: time.Now().Unix(),
  3253. Mtime: 0,
  3254. Module: 6,
  3255. RecordDate: schedulestartTime,
  3256. Sourse: 1,
  3257. PatientId: patientID,
  3258. }
  3259. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3260. if dialysisFinish.ID == 0 {
  3261. service.CreateDialysisFinish(finish)
  3262. }
  3263. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3264. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3265. //统计该患者总次数
  3266. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3267. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3268. }
  3269. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3270. //统计该患者总次数
  3271. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3272. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3273. }
  3274. redis := service.RedisClient()
  3275. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3276. redis.Set(key, "", time.Second)
  3277. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3278. //清空key 值
  3279. redis.Set(keyOne, "", time.Second)
  3280. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3281. //清空key 值
  3282. redis.Set(keyTwo, "", time.Second)
  3283. if createErr != nil {
  3284. this.ErrorLog("上机失败:%v", createErr)
  3285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3286. return
  3287. }
  3288. }
  3289. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3290. var tempdispose string
  3291. // 只针对中能建
  3292. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3293. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3294. }
  3295. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3296. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3297. }
  3298. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3299. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3300. //}
  3301. var ultrafiltration_rate float64
  3302. var ultrafiltration_rate_one string
  3303. var replacement_rate float64
  3304. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3305. //后期预增脱水量
  3306. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3307. if prescription.ID > 0 {
  3308. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3309. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3310. 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
  3311. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3312. }
  3313. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3314. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3315. }
  3316. //针对医师汇
  3317. if adminUserInfo.Org.Id == 10121 {
  3318. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3319. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3320. }
  3321. //针对通道
  3322. if adminUserInfo.Org.Id == 10234 {
  3323. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3324. }
  3325. //针对监利大垸医院
  3326. if template.TemplateId == 41 {
  3327. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3328. }
  3329. //针对肇庆三鹤血液透析中心
  3330. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3331. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3332. }
  3333. if adminUserInfo.Org.Id == 10469 {
  3334. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3335. }
  3336. if adminUserInfo.Org.Id == 10667 {
  3337. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3338. }
  3339. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3340. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3341. }
  3342. // 只针对方济医院
  3343. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3344. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3345. ultrafiltration_rate = value
  3346. }
  3347. //针对
  3348. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3349. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3350. ultrafiltration_rate = ultrafiltration_rate / 1000
  3351. }
  3352. if adminUserInfo.Org.Id == 10551 {
  3353. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3354. ultrafiltration_rate = ultrafiltration_rate / 1000
  3355. }
  3356. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3357. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3358. ultrafiltration_rate = ultrafiltration_rate / 1000
  3359. }
  3360. if adminUserInfo.Org.Id == 10580 {
  3361. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3362. ultrafiltration_rate = ultrafiltration_rate / 1000
  3363. }
  3364. if adminUserInfo.Org.Id == 10629 {
  3365. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3366. ultrafiltration_rate = ultrafiltration_rate / 1000
  3367. }
  3368. if adminUserInfo.Org.Id == 10644 {
  3369. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3370. ultrafiltration_rate = ultrafiltration_rate / 1000
  3371. }
  3372. if adminUserInfo.Org.Id == 10667 {
  3373. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3374. ultrafiltration_rate = ultrafiltration_rate / 1000
  3375. }
  3376. if adminUserInfo.Org.Id == 10693 {
  3377. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3378. ultrafiltration_rate = ultrafiltration_rate
  3379. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3380. }
  3381. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3382. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3383. ultrafiltration_rate = ultrafiltration_rate
  3384. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3385. }
  3386. if adminUserInfo.Org.Id == 10206 {
  3387. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3388. ultrafiltration_rate = ultrafiltration_rate
  3389. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3390. }
  3391. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3392. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3393. ultrafiltration_rate = ultrafiltration_rate
  3394. }
  3395. if adminUserInfo.Org.Id == 10702 {
  3396. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3397. ultrafiltration_rate = ultrafiltration_rate / 1000
  3398. }
  3399. if adminUserInfo.Org.Id == 10723 {
  3400. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3401. ultrafiltration_rate = ultrafiltration_rate / 1000
  3402. }
  3403. if adminUserInfo.Org.Id == 10721 {
  3404. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3405. ultrafiltration_rate = ultrafiltration_rate / 1000
  3406. }
  3407. if adminUserInfo.Org.Id == 10721 {
  3408. if prescription.ModeId == 2 {
  3409. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3410. if totalMin == 0 {
  3411. totalMin = 240
  3412. }
  3413. if prescription.ReplacementTotal == 0 {
  3414. prescription.ReplacementTotal = 15
  3415. }
  3416. //乘10 除10是为了保留一位小数
  3417. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3418. }
  3419. }
  3420. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3421. if prescription.ModeId == 2 {
  3422. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3423. if totalMin == 0 {
  3424. totalMin = 240
  3425. }
  3426. if prescription.DisplaceLiquiValue == 0 {
  3427. prescription.ReplacementTotal = 32
  3428. }
  3429. //乘10 除10是为了保留一位小数
  3430. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3431. }
  3432. }
  3433. }
  3434. }
  3435. if adminUserInfo.Org.Id == 10172 {
  3436. if prescription.ID == 0 {
  3437. if prescription.ModeId == 2 {
  3438. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3439. if totalMin == 0 {
  3440. totalMin = 240
  3441. }
  3442. if prescription.ReplacementTotal == 0 {
  3443. prescription.ReplacementTotal = 15
  3444. }
  3445. //乘10 除10是为了保留一位小数
  3446. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3447. }
  3448. }
  3449. }
  3450. record := models.MonitoringRecord{
  3451. UserOrgId: adminUserInfo.Org.Id,
  3452. PatientId: patientID,
  3453. DialysisOrderId: dialysisRecord.ID,
  3454. MonitoringDate: schedulestartTime,
  3455. OperateTime: startDate.Unix(),
  3456. // MonitoringTime: recordTime,
  3457. MonitoringNurse: nurseID,
  3458. Dispose: tempdispose,
  3459. UltrafiltrationRate: ultrafiltration_rate,
  3460. UltrafiltrationVolume: 0,
  3461. Status: 1,
  3462. CreatedTime: time.Now().Unix(),
  3463. UpdatedTime: time.Now().Unix(),
  3464. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3465. ReplacementRate: replacement_rate,
  3466. }
  3467. //只针对广慈医院
  3468. 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 {
  3469. // 查询病人是否有透前评估数据
  3470. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3471. //如果有数据就插入
  3472. if errcode == nil {
  3473. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3474. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3475. record.BreathingRate = befor.BreathingRate
  3476. record.PulseFrequency = befor.PulseFrequency
  3477. record.Temperature = befor.Temperature
  3478. }
  3479. }
  3480. //孝昌
  3481. if adminUserInfo.Org.Id == 10693 {
  3482. // 查询病人是否有透前评估数据
  3483. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3484. //如果有数据就插入
  3485. if errcode == nil {
  3486. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3487. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3488. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3489. record.BreathingRate = befor.BreathingRate
  3490. }
  3491. }
  3492. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3493. if newdialysisRecord.ID > 0 {
  3494. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3495. record.Temperature = 36.5
  3496. record.ArterialPressure = -100
  3497. record.DialysateTemperature = 36.5
  3498. record.Conductivity = 14
  3499. record.BreathingRate = "20"
  3500. record.VenousPressure = 80
  3501. record.TransmembranePressure = 60
  3502. record.Dispose = catheter_operation
  3503. }
  3504. //针对新化博翔
  3505. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3506. record.BloodOxygenSaturation = "99"
  3507. record.Conductivity = 14
  3508. record.DialysateTemperature = 36.5
  3509. record.BreathingRate = "20"
  3510. }
  3511. //针对兰溪人民医院的需求
  3512. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3513. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3514. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3515. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3516. record.Temperature = befor.Temperature
  3517. record.PulseFrequency = befor.PulseFrequency
  3518. record.BreathingRate = befor.BreathingRate
  3519. }
  3520. //针对乐山友谊医院的需求
  3521. if adminUserInfo.Org.Id == 10677 {
  3522. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3523. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3524. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3525. record.Temperature = befor.Temperature
  3526. record.PulseFrequency = befor.PulseFrequency
  3527. record.BreathingRate = befor.BreathingRate
  3528. }
  3529. //新化博翔
  3530. if adminUserInfo.Org.Id == 10447 {
  3531. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3532. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3533. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3534. record.BreathingRate = befor.BreathingRate
  3535. }
  3536. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3537. record.PulseFrequency = 80
  3538. record.Temperature = 36.5
  3539. }
  3540. //诊断灵山圣康
  3541. if adminUserInfo.Org.Id == 10375 {
  3542. record.Conductivity = 13.8
  3543. record.DialysateTemperature = 37
  3544. record.DialysateFlow = 500
  3545. record.BloodFlowVolume = 200
  3546. record.BreathingRate = "18"
  3547. record.SodiumConcentration = 140
  3548. }
  3549. //江成肾病医院
  3550. if adminUserInfo.Org.Id == 10517 {
  3551. record.SodiumConcentration = 138
  3552. record.DialysateTemperature = 36.5
  3553. }
  3554. //濉溪杏康血液透析中心
  3555. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3556. record.BloodFlowVolume = prescription.BloodFlowVolume
  3557. }
  3558. if adminUserInfo.Org.Id != 10683 {
  3559. err = service.CreateMonitor(&record)
  3560. }
  3561. //记录日志
  3562. byterequest, _ := json.Marshal(record)
  3563. monitorRecordLog := models.XtMonitorRecordLog{
  3564. RecordDate: record.MonitoringDate,
  3565. PatientId: record.PatientId,
  3566. Module: 1,
  3567. AdminUserId: adminUserInfo.AdminUser.Id,
  3568. Ctime: time.Now().Unix(),
  3569. Mtime: 0,
  3570. Status: 1,
  3571. UserOrgId: record.UserOrgId,
  3572. ErrLog: string(byterequest),
  3573. Source: "执行上机时新增监测",
  3574. }
  3575. service.CreateMonitorRecordLog(monitorRecordLog)
  3576. finish := models.XtDialysisFinish{
  3577. IsFinish: 1,
  3578. UserOrgId: adminUserInfo.Org.Id,
  3579. Status: 1,
  3580. Ctime: time.Now().Unix(),
  3581. Mtime: 0,
  3582. Module: 7,
  3583. RecordDate: schedulestartTime,
  3584. Sourse: 1,
  3585. PatientId: patientID,
  3586. }
  3587. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3588. if dialysisFinish.ID == 0 {
  3589. service.CreateDialysisFinish(finish)
  3590. }
  3591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3592. redis := service.RedisClient()
  3593. //清空key 值
  3594. redis.Set(key, "", time.Second)
  3595. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3596. redis.Set(keyOne, "", time.Second)
  3597. defer redis.Close()
  3598. if err != nil {
  3599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3600. return
  3601. }
  3602. }
  3603. go func() {
  3604. ssoDomain := beego.AppConfig.String("call_domain")
  3605. api := ssoDomain + "/index/uppatient"
  3606. values := make(url.Values)
  3607. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3608. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3609. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3610. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3611. http.PostForm(api, values)
  3612. }()
  3613. this.ServeSuccessJSON(map[string]interface{}{
  3614. "dialysis_order": newdialysisRecord,
  3615. "monitor": record,
  3616. })
  3617. return
  3618. }
  3619. func (c *DialysisAPIController) PostSolution() {
  3620. id, _ := c.GetInt64("patient", 0)
  3621. recordDateStr := c.GetString("record_date")
  3622. if id <= 0 {
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. adminUserInfo := c.GetMobileAdminUserInfo()
  3627. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3628. if patient.ID == 0 {
  3629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3630. return
  3631. }
  3632. if len(recordDateStr) == 0 {
  3633. recordDateStr = time.Now().Format("2006-01-02")
  3634. }
  3635. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3636. if parseDateErr != nil {
  3637. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3639. return
  3640. }
  3641. mode_id, _ := c.GetInt64("mode_id", 0)
  3642. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3643. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3644. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3645. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3646. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3647. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3648. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3649. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3650. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3651. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3652. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3653. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3654. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3655. kalium, _ := c.GetFloat("kalium", 0)
  3656. sodium, _ := c.GetFloat("sodium", 0)
  3657. calcium, _ := c.GetFloat("calcium", 0)
  3658. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3659. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3660. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3661. glucose, _ := c.GetFloat("glucose", 0)
  3662. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3663. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3664. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3665. conductivity, _ := c.GetFloat("conductivity", 0)
  3666. remark := c.GetString("remark")
  3667. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3668. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3669. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3670. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3671. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3672. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3673. special_medicine_other := c.GetString("special_medicine_other")
  3674. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3675. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3676. blood_access, _ := c.GetInt64("blood_access", 0)
  3677. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3678. body_fluid_other := c.GetString("body_fluid_other")
  3679. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3680. niprocart, _ := c.GetInt64("niprocart", 0)
  3681. jms, _ := c.GetInt64("jms", 0)
  3682. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3683. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3684. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3685. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3686. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3687. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3688. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3689. injector, _ := c.GetInt64("injector", 0)
  3690. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3691. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3692. safe_package, _ := c.GetInt64("package", 0)
  3693. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3694. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3695. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3696. blood := c.GetString("blood")
  3697. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3698. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3699. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3700. displace_speed := c.GetString("displace_speed")
  3701. illness, _ := c.GetInt64("illness")
  3702. amylaceum := c.GetString("amylaceum")
  3703. single_time := c.GetString("single_time")
  3704. single_water := c.GetString("single_water")
  3705. replacement_flow := c.GetString("replacement_flow")
  3706. plasma_separator := c.GetString("plasma_separator")
  3707. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3708. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3709. oxygen_flow := c.GetString("oxygen_flow")
  3710. oxygen_time := c.GetString("oxygen_time")
  3711. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3712. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3713. puncture_needle := c.GetString("puncture_needle")
  3714. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3715. epo := c.GetString("epo")
  3716. epo_count, _ := c.GetFloat("epo_count", 0)
  3717. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3718. pre_impulse := c.GetString("pre_impulse")
  3719. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3720. admin_user_id, _ := c.GetInt64("admin_user_id")
  3721. is_water := c.GetString("is_water")
  3722. add_amount, _ := c.GetFloat("add_amount")
  3723. reduce_amount, _ := c.GetFloat("reduce_amount")
  3724. prescribing_number, _ := c.GetFloat("prescribing_number")
  3725. treatment_remark := c.GetString("treatment_remark")
  3726. prescription_sodium := c.GetString("prescription_sodium")
  3727. start_sodium := c.GetString("start_sodium")
  3728. sodium_curve := c.GetString("sodium_curve")
  3729. var is_war int64
  3730. if is_water == "是" {
  3731. is_war = 1
  3732. }
  3733. if is_water == "否" {
  3734. is_war = 2
  3735. }
  3736. if is_water == "请选择" {
  3737. is_war = 0
  3738. }
  3739. drhy_water := c.GetString("drhy_water")
  3740. dry_water_hour := c.GetString("dry_water_hour")
  3741. water_machine := c.GetString("water_machine")
  3742. dialysis_remark := c.GetString("dialysis_remark")
  3743. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3744. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3745. prescription_water, _ := c.GetFloat("prescription_water")
  3746. dialysis_strainer := c.GetString("dialysis_strainer")
  3747. chaptalization := c.GetString("chaptalization")
  3748. washing_time := c.GetString("washing_time")
  3749. warsh_count := c.GetString("warsh_count")
  3750. blood_access_part_id := c.GetString("blood_access_part_id")
  3751. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3752. dialyzate := c.GetString("dialyzate")
  3753. first_super := c.GetString("first_super")
  3754. is_sequential := c.GetString("is_sequential")
  3755. var fisrt_sup int64
  3756. if first_super == "是" {
  3757. fisrt_sup = 1
  3758. }
  3759. if first_super == "否" {
  3760. fisrt_sup = 2
  3761. }
  3762. if first_super == "请选择" {
  3763. fisrt_sup = 0
  3764. }
  3765. var is_sequen int64
  3766. if is_sequential == "是" {
  3767. is_sequen = 1
  3768. }
  3769. if is_sequential == "否" {
  3770. is_sequen = 2
  3771. }
  3772. if is_sequential == "请选择" {
  3773. is_sequen = 0
  3774. }
  3775. conduct := c.GetString("conduct")
  3776. if mode_id > 0 {
  3777. var str string
  3778. //查找该机构用的是什么透析器
  3779. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3780. if filedConfig.ID > 0 {
  3781. str = dialyzerPerfusionApparatus
  3782. } else {
  3783. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3784. }
  3785. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3786. }
  3787. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3788. //
  3789. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3790. // if appRole.UserType == 3 {
  3791. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3792. // if getPermissionErr != nil {
  3793. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3794. // return
  3795. // } else if headNursePermission == nil {
  3796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3797. // return
  3798. // }
  3799. // }
  3800. //}
  3801. // 查询信息规挡的设置天数
  3802. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3803. if infor.ID > 0 && infor.WeekDay > 0 {
  3804. var cha_time int64
  3805. timeNowStr := time.Now().Format("2006-01-02")
  3806. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3807. //今日的日期减去设置的日期
  3808. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3809. if cha_time >= recordDate.Unix() {
  3810. //查询审核是否允许
  3811. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3812. //申请状态不允许的情况 拒绝修改
  3813. if infor.ApplicationStatus != 1 {
  3814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3815. return
  3816. }
  3817. }
  3818. }
  3819. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3820. var dialysis_dialyszers_id int64
  3821. var dialysis_strainer_id int64
  3822. var dialysis_irrigation_id int64
  3823. if len(goodList) > 0 {
  3824. for _, item := range goodList {
  3825. if item.SpecificationName == dialysis_dialyszers {
  3826. dialysis_dialyszers_id = item.ID
  3827. }
  3828. if item.SpecificationName == dialysis_irrigation {
  3829. dialysis_irrigation_id = item.ID
  3830. }
  3831. if item.SpecificationName == dialysis_strainer {
  3832. dialysis_strainer_id = item.ID
  3833. }
  3834. }
  3835. }
  3836. prescription := models.DialysisPrescription{
  3837. UserOrgId: adminUserInfo.Org.Id,
  3838. PatientId: id,
  3839. RecordDate: recordDate.Unix(),
  3840. ModeId: mode_id,
  3841. DialysisDuration: dialysis_duration,
  3842. Dialyzer: dialyzer,
  3843. PerfusionApparatus: perfusion_apparatus,
  3844. BloodFlowVolume: blood_flow_volume,
  3845. DewaterAmount: dewater_amount,
  3846. DisplaceLiqui: displace_liqui,
  3847. ReplacementWay: replacement_way,
  3848. Anticoagulant: anticoagulant,
  3849. AnticoagulantShouji: anticoagulant_shouji,
  3850. AnticoagulantWeichi: anticoagulant_weichi,
  3851. AnticoagulantZongliang: anticoagulant_zongliang,
  3852. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3853. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3854. Kalium: kalium,
  3855. Sodium: sodium,
  3856. Calcium: calcium,
  3857. Bicarbonate: bicarbonate,
  3858. Glucose: glucose,
  3859. // DryWeight: dry_weight,
  3860. DialysateFlow: dialysate_flow,
  3861. DialysateTemperature: dialysate_temperature,
  3862. Conductivity: conductivity,
  3863. Remark: remark,
  3864. Status: 1,
  3865. CreatedTime: time.Now().Unix(),
  3866. UpdatedTime: time.Now().Unix(),
  3867. DialysisDurationMinute: dialysisDurationMinute,
  3868. DialysisDurationHour: dialysisDurationHour,
  3869. TargetUltrafiltration: targetUltrafiltration,
  3870. DialysateFormulation: dialysateFormulation,
  3871. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3872. BodyFluid: body_fluid,
  3873. SpecialMedicine: special_medicine,
  3874. SpecialMedicineOther: special_medicine_other,
  3875. DisplaceLiquiPart: displace_liqui_part,
  3876. DisplaceLiquiValue: displace_liqui_value,
  3877. BloodAccess: blood_access,
  3878. Ultrafiltration: ultrafiltration,
  3879. BodyFluidOther: body_fluid_other,
  3880. ReplacementTotal: replacement_total,
  3881. Niprocart: niprocart,
  3882. Jms: jms,
  3883. FistulaNeedleSet: fistula_needle_set,
  3884. FistulaNeedleSet16: fistula_needle_set_16,
  3885. Hemoperfusion: hemoperfusion,
  3886. DialyserSterilised: dialyser_sterilised,
  3887. Filtryzer: filtryzer,
  3888. TargetKtv: target_ktv,
  3889. Dialyzers: dialyzers,
  3890. Injector: injector,
  3891. Bloodlines: bloodlines,
  3892. TubingHemodialysis: tubing_hemodialysis,
  3893. Package: safe_package,
  3894. ALiquid: a_liquid,
  3895. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3896. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3897. Blood: blood,
  3898. DialysisDialyszers: dialysis_dialyszers,
  3899. DialysisIrrigation: dialysis_irrigation,
  3900. AntioxidantCommodityName: antioxidant_commodity_name,
  3901. DisplaceSpeed: displace_speed,
  3902. Illness: illness,
  3903. Amylaceum: amylaceum,
  3904. SingleWater: single_water,
  3905. SingleTime: single_time,
  3906. ReplacementFlow: replacement_flow,
  3907. PlasmaSeparator: plasma_separator,
  3908. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3909. OxygenUptake: oxygen_uptake,
  3910. OxygenTime: oxygen_time,
  3911. OxygenFlow: oxygen_flow,
  3912. HemodialysisPipelines: hemodialysis_pipelines,
  3913. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3914. PunctureNeedle: puncture_needle,
  3915. PunctureNeedleCount: puncture_needle_count,
  3916. Epo: epo,
  3917. EpoCount: epo_count,
  3918. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3919. PreImpulse: impulse,
  3920. AdminUserId: admin_user_id,
  3921. IsWater: is_war,
  3922. DrhyWater: drhy_water,
  3923. DryWaterHour: dry_water_hour,
  3924. WaterMachine: water_machine,
  3925. AddAmount: add_amount,
  3926. ReduceAmount: reduce_amount,
  3927. DialysisRemark: dialysis_remark,
  3928. PrescribingNumber: prescribing_number,
  3929. PrescriptionSodium: prescription_sodium,
  3930. StartSodium: start_sodium,
  3931. SodiumCurve: sodium_curve,
  3932. TreatmentRemark: treatment_remark,
  3933. DialysisFluidFlow: dialysis_fluid_flow,
  3934. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3935. PrescriptionWater: prescription_water,
  3936. DialysisStrainer: dialysis_strainer,
  3937. Chaptalization: chaptalization,
  3938. WashingTime: washing_time,
  3939. WarshCount: warsh_count,
  3940. BloodAccessPartId: blood_access_part_id,
  3941. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3942. Dialyzate: dialyzate,
  3943. DialysisDialyszersId: dialysis_dialyszers_id,
  3944. DialysisIrrigationId: dialysis_irrigation_id,
  3945. DialysisStrainerId: dialysis_strainer_id,
  3946. FirstSuper: fisrt_sup,
  3947. IsSequential: is_sequen,
  3948. Conduct: conduct,
  3949. }
  3950. if adminUserInfo.Org.Id == 10721 {
  3951. if prescription.ModeId == 2 {
  3952. if prescription.ReplacementTotal == 0 {
  3953. prescription.ReplacementTotal = 15
  3954. }
  3955. }
  3956. }
  3957. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3958. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3959. //
  3960. if appRole.UserType == 2 || appRole.UserType == 1 {
  3961. prescription_doctor = adminUserInfo.AdminUser.Id
  3962. prescription.PrescriptionDoctor = prescription_doctor
  3963. }
  3964. if dialysisPrescription.ID == 0 { //新增
  3965. prescription.Creater = adminUserInfo.AdminUser.Id
  3966. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3967. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3968. }
  3969. } else { //修改
  3970. if dialysisPrescription.Creater == 0 {
  3971. prescription.Creater = adminUserInfo.AdminUser.Id
  3972. } else {
  3973. prescription.Creater = dialysisPrescription.Creater
  3974. if adminUserInfo.Org.Id == 9882 {
  3975. if appRole.UserType == 2 || appRole.UserType == 1 {
  3976. prescription.Creater = adminUserInfo.AdminUser.Id
  3977. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3978. }
  3979. }
  3980. }
  3981. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3982. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3983. }
  3984. //if/**/
  3985. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3986. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3987. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3988. // if getPermissionErr != nil {
  3989. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3990. // return
  3991. // } else if headNursePermission == nil {
  3992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3993. // return
  3994. // }
  3995. //}
  3996. //prescription.Creater = dialysisPrescription.Creater
  3997. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3998. prescription.Modifier = adminUserInfo.AdminUser.Id
  3999. prescription.ID = dialysisPrescription.ID
  4000. }
  4001. solution := models.DialysisSolution{
  4002. RegistrarsId: adminUserInfo.AdminUser.Id,
  4003. UserOrgId: adminUserInfo.Org.Id,
  4004. Doctor: prescription_doctor,
  4005. PatientId: id,
  4006. ModeId: mode_id,
  4007. DialysisDuration: dialysis_duration,
  4008. PerfusionApparatus: perfusion_apparatus,
  4009. BloodFlowVolume: blood_flow_volume,
  4010. Dewater: dewater_amount,
  4011. DisplaceLiqui: displace_liqui,
  4012. ReplacementWay: replacement_way,
  4013. Anticoagulant: anticoagulant,
  4014. AnticoagulantShouji: anticoagulant_shouji,
  4015. AnticoagulantWeichi: anticoagulant_weichi,
  4016. AnticoagulantZongliang: anticoagulant_zongliang,
  4017. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4018. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4019. Kalium: kalium,
  4020. Sodium: sodium,
  4021. Calcium: calcium,
  4022. Bicarbonate: bicarbonate,
  4023. Glucose: glucose,
  4024. // DryWeight: dry_weight,
  4025. DialysateFlow: dialysate_flow,
  4026. DialysateTemperature: dialysate_temperature,
  4027. Conductivity: conductivity,
  4028. Remark: remark,
  4029. Status: 1,
  4030. CreatedTime: time.Now().Unix(),
  4031. UpdatedTime: time.Now().Unix(),
  4032. DialysisDurationMinute: dialysisDurationMinute,
  4033. DialysisDurationHour: dialysisDurationHour,
  4034. TargetUltrafiltration: targetUltrafiltration,
  4035. DialysateFormulation: dialysateFormulation,
  4036. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4037. BodyFluid: body_fluid,
  4038. SpecialMedicine: special_medicine,
  4039. SpecialMedicineOther: special_medicine_other,
  4040. DisplaceLiquiPart: displace_liqui_part,
  4041. DisplaceLiquiValue: displace_liqui_value,
  4042. BloodAccess: blood_access,
  4043. Ultrafiltration: ultrafiltration,
  4044. BodyFluidOther: body_fluid_other,
  4045. ReplacementTotal: replacement_total,
  4046. TargetKtv: target_ktv,
  4047. DialysisDialyszers: dialysis_dialyszers,
  4048. DialysisIrrigation: dialysis_irrigation,
  4049. HemodialysisPipelines: hemodialysis_pipelines,
  4050. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4051. PunctureNeedle: puncture_needle,
  4052. PunctureNeedleCount: puncture_needle_count,
  4053. Epo: epo,
  4054. EpoCount: epo_count,
  4055. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4056. PreImpulse: impulse,
  4057. SolutionStatus: 1,
  4058. DialysisRemark: dialysis_remark,
  4059. PrescribingNumber: prescribing_number,
  4060. PrescriptionSodium: prescription_sodium,
  4061. StartSodium: start_sodium,
  4062. SodiumCurve: sodium_curve,
  4063. TreatmentRemark: treatment_remark,
  4064. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4065. DialysisFluidFlow: dialysis_fluid_flow,
  4066. PrescriptionWater: prescription_water,
  4067. DialysisStrainer: dialysis_strainer,
  4068. Chaptalization: chaptalization,
  4069. WashingTime: washing_time,
  4070. WarshCount: warsh_count,
  4071. BloodAccessPartId: blood_access_part_id,
  4072. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4073. Dialyzate: dialyzate,
  4074. DialysisDialyszersId: dialysis_dialyszers_id,
  4075. DialysisIrrigationId: dialysis_irrigation_id,
  4076. DialysisStrainerId: dialysis_strainer_id,
  4077. FirstSuper: fisrt_sup,
  4078. IsSequential: is_sequen,
  4079. Conduct: conduct,
  4080. }
  4081. //针对河间咸的
  4082. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4083. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4084. solution.DisplaceLiquiPart = 0
  4085. solution.DisplaceLiquiValue = 0
  4086. }
  4087. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4088. prescription.DisplaceLiquiPart = 0
  4089. prescription.DisplaceLiquiValue = 0
  4090. }
  4091. }
  4092. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4093. if solution.PrescribingNumber == 0 {
  4094. solution.PrescribingNumber = 1
  4095. }
  4096. if prescription.PrescribingNumber == 0 {
  4097. prescription.PrescribingNumber = 1
  4098. }
  4099. if solution.PrescribingNumber == 0 && id == 14682 {
  4100. solution.PrescribingNumber = 2
  4101. }
  4102. if solution.PrescribingNumber == 0 && id == 18560 {
  4103. solution.PrescribingNumber = 2
  4104. }
  4105. if prescription.PrescribingNumber == 0 && id == 14682 {
  4106. prescription.PrescribingNumber = 2
  4107. }
  4108. if prescription.PrescribingNumber == 0 && id == 18560 {
  4109. prescription.PrescribingNumber = 2
  4110. }
  4111. }
  4112. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4113. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4114. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4115. if len(monitorList) > 0 {
  4116. var ultrafiltration_rate float64
  4117. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4118. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4119. var replacement_rate float64
  4120. //乘10 除10是为了保留一位小数
  4121. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4122. var firstOpeateTime = monitorList[0].OperateTime
  4123. for _, item := range monitorList {
  4124. //超滤率
  4125. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4126. //置换率
  4127. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4128. //超滤量
  4129. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4130. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4131. //置换量
  4132. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4133. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4134. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4135. }
  4136. }
  4137. }
  4138. //记录日志
  4139. byterequest, _ := json.Marshal(prescription)
  4140. prescriptionLog := models.XtDialysisPrescriptionLog{
  4141. UserOrgId: prescription.UserOrgId,
  4142. Ctime: time.Now().Unix(),
  4143. Mtime: 0,
  4144. ErrLog: string(byterequest),
  4145. AdminUserId: adminUserInfo.AdminUser.Id,
  4146. RecordDate: prescription.RecordDate,
  4147. PatientId: prescription.PatientId,
  4148. Source: "手机端新增长期处方",
  4149. Status: 1,
  4150. }
  4151. service.CreatePrescriptionLog(prescriptionLog)
  4152. finish := models.XtDialysisFinish{
  4153. IsFinish: 1,
  4154. UserOrgId: adminUserInfo.Org.Id,
  4155. Status: 1,
  4156. Ctime: time.Now().Unix(),
  4157. Mtime: 0,
  4158. Module: 1,
  4159. RecordDate: recordDate.Unix(),
  4160. Sourse: 1,
  4161. PatientId: id,
  4162. }
  4163. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4164. if dialysisFinish.ID == 0 {
  4165. service.CreateDialysisFinish(finish)
  4166. }
  4167. //获取最新1条
  4168. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4169. //更新状态
  4170. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4171. //长沙南雅医院,自动生成抗凝剂的临时处方
  4172. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4173. if prescribing_number == 0 {
  4174. prescribing_number = 1
  4175. }
  4176. advice := models.DoctorAdvice{
  4177. UserOrgId: adminUserInfo.Org.Id,
  4178. PatientId: id,
  4179. GroupNo: 0,
  4180. AdviceType: 2,
  4181. RecordDate: recordDate.Unix(),
  4182. AdviceDate: recordDate.Unix(),
  4183. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4184. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4185. AdviceDesc: "",
  4186. ReminderDate: 0,
  4187. SingleDose: prescription.AnticoagulantZongliang,
  4188. SingleDoseUnit: "iu",
  4189. DrugSpec: 0,
  4190. DrugSpecUnit: "",
  4191. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4192. PrescribingNumberUnit: "支",
  4193. DeliveryWay: "静脉注射",
  4194. ExecutionFrequency: "上机前",
  4195. AdviceDoctor: 0,
  4196. Status: 1,
  4197. CreatedTime: time.Now().Unix(),
  4198. UpdatedTime: time.Now().Unix(),
  4199. IsPrescription: 1,
  4200. ExecutionState: 2,
  4201. StopState: 2,
  4202. IsSettle: 2,
  4203. }
  4204. // 查询排班信息
  4205. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4206. if schedulePatient.ID > 0 {
  4207. if schedulePatient.ScheduleType == 1 {
  4208. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4209. }
  4210. if schedulePatient.ScheduleType == 2 {
  4211. advice.StartTime = recordDate.Unix() + 9*60*60
  4212. }
  4213. }
  4214. // 抗凝剂名称
  4215. switch anticoagulant {
  4216. case 1:
  4217. advice.AdviceName = "无肝素"
  4218. break
  4219. case 2:
  4220. advice.AdviceName = "普通肝素"
  4221. break
  4222. case 3:
  4223. advice.AdviceName = "低分子肝素"
  4224. break
  4225. case 4:
  4226. advice.AdviceName = "阿加曲班"
  4227. break
  4228. case 5:
  4229. advice.AdviceName = "枸橼酸钠"
  4230. break
  4231. case 6:
  4232. advice.AdviceName = "低分子肝素钙"
  4233. break
  4234. case 7:
  4235. advice.AdviceName = "低分子肝素钠"
  4236. break
  4237. case 8:
  4238. advice.AdviceName = "依诺肝素"
  4239. break
  4240. case 9:
  4241. advice.AdviceName = "达肝素"
  4242. break
  4243. case 10:
  4244. advice.AdviceName = "体外抗凝"
  4245. break
  4246. case 11:
  4247. advice.AdviceName = "那曲肝素"
  4248. break
  4249. case 12:
  4250. advice.AdviceName = "无抗凝剂"
  4251. break
  4252. }
  4253. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4254. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4255. advice.AdviceDoctor = appRole.AdminUserId
  4256. }
  4257. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4258. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4259. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4260. advice.AdviceName = "低分子肝素钠注射液"
  4261. // 修改患者临时医嘱里的抗凝剂医嘱
  4262. advice.ID = advicePrescription.ID
  4263. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4264. } else {
  4265. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4266. advice.AdviceName = "低分子肝素钠注射液"
  4267. service.CreateDoctorAdvice(&advice)
  4268. }
  4269. }
  4270. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4271. redis := service.RedisClient()
  4272. defer redis.Close()
  4273. //清空key 值
  4274. redis.Set(key, "", time.Second)
  4275. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4276. redis.Set(keyOne, "", time.Second)
  4277. }
  4278. //获取key,清空redis
  4279. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4280. redis := service.RedisClient()
  4281. defer redis.Close()
  4282. //清空key 值
  4283. redis.Set(key, "", time.Second)
  4284. //清空长期医嘱的key
  4285. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4286. redis.Set(soulution_key, "", time.Second)
  4287. //查询最近透析准备表里是否存在 透析器 灌流器
  4288. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4289. redis.Set(keyOne, "", time.Second)
  4290. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4291. redis.Set(keyTwo, "", time.Second)
  4292. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4293. redis.Set(keyThree, "", time.Second)
  4294. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4295. redis.Set(keyFour, "", time.Second)
  4296. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4297. //
  4298. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4299. //
  4300. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4301. //if len(mation)>0{
  4302. // for _, item := range splitStr {
  4303. // for _,it := range mation{
  4304. // if(item == it.SpecificationName){
  4305. //
  4306. // //查询最近一次的透析器
  4307. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4308. //
  4309. // if errcode == gorm.ErrRecordNotFound{
  4310. // //插入数据
  4311. // prepare := models.DialysisBeforePrepare{
  4312. // UserOrgId: adminUserInfo.Org.Id,
  4313. // PatientId: id,
  4314. // RecordDate: recordDate.Unix(),
  4315. // GoodTypeId: it.GoodTypeId,
  4316. // GoodId: it.ID,
  4317. // Count: 1,
  4318. // Ctime: time.Now().Unix(),
  4319. // Creater: adminUserInfo.AdminUser.Id,
  4320. // Status:1,
  4321. //
  4322. // }
  4323. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4324. // fmt.Println("",errcode)
  4325. // }
  4326. // }
  4327. // }
  4328. //
  4329. // }
  4330. //
  4331. // for _, item := range splitIrrigation {
  4332. // for _,it := range mation{
  4333. // if(item == it.SpecificationName){
  4334. // //查询最近一次的透析器
  4335. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4336. // if errcode == gorm.ErrRecordNotFound{
  4337. // //插入数据
  4338. // prepare := models.DialysisBeforePrepare{
  4339. // UserOrgId: adminUserInfo.Org.Id,
  4340. // PatientId: id,
  4341. // RecordDate: recordDate.Unix(),
  4342. // GoodTypeId: it.GoodTypeId,
  4343. // GoodId: it.ID,
  4344. // Count: 1,
  4345. // Ctime: time.Now().Unix(),
  4346. // Creater: adminUserInfo.AdminUser.Id,
  4347. // Status:1,
  4348. //
  4349. // }
  4350. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4351. // fmt.Println(errcode)
  4352. // }
  4353. // }
  4354. // }
  4355. // }
  4356. //}
  4357. c.ServeSuccessJSON(map[string]interface{}{
  4358. "solution": &solution,
  4359. "prescription": &prescription,
  4360. })
  4361. }
  4362. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4363. patient, _ := c.GetInt64("patient", 0)
  4364. adminUserInfo := c.GetMobileAdminUserInfo()
  4365. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4366. c.ServeSuccessJSON(map[string]interface{}{
  4367. "receiveTreatmentAsses": receiveTreatmentAsses,
  4368. })
  4369. }
  4370. func (this *DialysisAPIController) PostSignInfo() {
  4371. patientID, _ := this.GetInt64("patient_id")
  4372. recordDateStr := this.GetString("date")
  4373. if patientID <= 0 {
  4374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4375. return
  4376. }
  4377. if len(recordDateStr) == 0 {
  4378. recordDateStr = time.Now().Format("2006-01-02")
  4379. }
  4380. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4381. if parseDateErr != nil {
  4382. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4384. return
  4385. }
  4386. adminInfo := this.GetMobileAdminUserInfo()
  4387. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4388. if err != nil {
  4389. this.ErrorLog("签名失败:%v", err)
  4390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4391. return
  4392. }
  4393. this.ServeSuccessJSON(map[string]interface{}{
  4394. "doctor_id": adminInfo.AdminUser.Id,
  4395. })
  4396. }
  4397. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4398. patientID, _ := this.GetInt64("patient_id")
  4399. adminInfo := this.GetMobileAdminUserInfo()
  4400. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4401. this.ServeSuccessJSON(map[string]interface{}{
  4402. "monitor": record,
  4403. })
  4404. }
  4405. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4406. thisTime := time.Now()
  4407. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4408. timeLayout := "2006-01-02 15:04:05"
  4409. loc, _ := time.LoadLocation("Local")
  4410. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4411. theAssessmentDateTime := theStartTime.Unix()
  4412. patientID, _ := this.GetInt64("patient_id")
  4413. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4414. adminInfo := this.GetMobileAdminUserInfo()
  4415. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4416. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4417. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4418. var ultrafiltration_rate float64
  4419. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4420. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4421. fmt.Println(evaluation)
  4422. fmt.Println("prescription.ID", prescription.ID)
  4423. if prescription.ID > 0 {
  4424. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4425. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4426. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4427. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4428. record.UltrafiltrationRate = ultrafiltration_rate
  4429. }
  4430. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4431. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4432. record.UltrafiltrationRate = ultrafiltration_rate
  4433. }
  4434. if adminInfo.Org.Id == 10510 {
  4435. record.UltrafiltrationRate = 0
  4436. }
  4437. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4438. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4439. record.UltrafiltrationRate = ultrafiltration_rate
  4440. }
  4441. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4442. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4443. record.UltrafiltrationRate = ultrafiltration_rate
  4444. }
  4445. // 只针对方济医院
  4446. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4447. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4448. ultrafiltration_rate = value
  4449. record.UltrafiltrationRate = ultrafiltration_rate
  4450. }
  4451. if template.TemplateId == 41 || template.TemplateId == 47 {
  4452. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4453. record.UltrafiltrationRate = ultrafiltration_rate
  4454. }
  4455. if template.TemplateId == 43 {
  4456. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4457. record.UltrafiltrationRate = ultrafiltration_rate
  4458. }
  4459. if template.TemplateId == 46 || template.TemplateId == 54 {
  4460. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4461. record.UltrafiltrationRate = ultrafiltration_rate
  4462. }
  4463. 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 {
  4464. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4465. record.UltrafiltrationRate = ultrafiltration_rate
  4466. }
  4467. if adminInfo.Org.Id == 10469 {
  4468. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4469. record.UltrafiltrationRate = ultrafiltration_rate
  4470. }
  4471. if adminInfo.Org.Id == 10667 {
  4472. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4473. record.UltrafiltrationRate = ultrafiltration_rate
  4474. }
  4475. if adminInfo.Org.Id == 10471 {
  4476. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4477. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4478. }
  4479. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4480. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4481. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4482. }
  4483. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4484. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4485. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4486. }
  4487. if adminInfo.Org.Id == 10721 {
  4488. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4489. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4490. }
  4491. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4492. record.UltrafiltrationRate = 0
  4493. }
  4494. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4495. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4496. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4497. }
  4498. if adminInfo.Org.Id == 10206 {
  4499. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4500. fmt.Println("ultrafiltration_rate------------------", ultrafiltration_rate)
  4501. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4502. }
  4503. //if template.TemplateId == 47 {
  4504. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4505. // record.UltrafiltrationRate = ultrafiltration_rate
  4506. //}
  4507. }
  4508. }
  4509. // record.UltrafiltrationRate = ultrafiltration_rate
  4510. record.UltrafiltrationVolume = 0
  4511. 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
  4512. if ultrafiltration_rate > 0 {
  4513. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4514. record.UltrafiltrationVolume = value
  4515. }
  4516. }
  4517. 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
  4518. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4519. if adminInfo.Org.Id != 10735 {
  4520. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4521. record.UltrafiltrationVolume = ultrafiltration_volume
  4522. }
  4523. //胶州少海医院
  4524. if adminInfo.Org.Id == 10735 {
  4525. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4526. record.UltrafiltrationVolume = ultrafiltration_volume / 2
  4527. }
  4528. }
  4529. }
  4530. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4531. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4532. record.UltrafiltrationVolume = ultrafiltration_volume
  4533. }
  4534. //长沙南雅
  4535. 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 {
  4536. if ultrafiltration_rate > 0 {
  4537. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4538. record.UltrafiltrationVolume = ultrafiltration_volume
  4539. }
  4540. }
  4541. if adminInfo.Org.Id == 10471 {
  4542. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4543. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4544. }
  4545. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4546. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4547. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4548. }
  4549. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4550. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4551. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4552. }
  4553. //长沙南雅累计血容量自动计算
  4554. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4555. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4556. //}
  4557. if template.TemplateId == 47 || template.TemplateId == 54 {
  4558. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4559. }
  4560. if adminInfo.Org.Id == 10510 {
  4561. record.UltrafiltrationVolume = 0
  4562. }
  4563. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4564. if ultrafiltration_rate > 0 {
  4565. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4566. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4567. }
  4568. }
  4569. //古镇乐生
  4570. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4571. if ultrafiltration_rate > 0 {
  4572. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4573. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4574. }
  4575. }
  4576. if adminInfo.Org.Id == 10206 {
  4577. if ultrafiltration_rate > 0 {
  4578. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4579. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4580. }
  4581. }
  4582. if adminInfo.Org.Id == 10721 {
  4583. var replacement_rate float64
  4584. var displacement_quantity float64
  4585. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4586. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4587. record.ReplacementRate = replacement_rate
  4588. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4589. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4590. record.DisplacementQuantity = displacement_quantity
  4591. }
  4592. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4593. var replacement_rate float64
  4594. var displacement_quantity float64
  4595. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4596. if totalMin == 0 {
  4597. totalMin = 240
  4598. }
  4599. if prescription.DisplaceLiquiValue == 0 {
  4600. prescription.ReplacementTotal = 32
  4601. }
  4602. //乘10 除10是为了保留一位小数
  4603. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4604. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4605. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4606. record.DisplacementQuantity = displacement_quantity
  4607. }
  4608. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4609. this.ServeSuccessJSON(map[string]interface{}{
  4610. "monitor": record,
  4611. "lastMonitorRecordList": lastMonitorRecordList,
  4612. })
  4613. }
  4614. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4615. record_id, _ := this.GetInt64("id")
  4616. nurseID, _ := this.GetInt64("start_nurse")
  4617. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4618. bedID, _ := this.GetInt64("bed")
  4619. start_time := this.GetString("start_time")
  4620. schedual_type, _ := this.GetInt64("schedual_type")
  4621. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4622. change_nurse, _ := this.GetInt64("change_nurse")
  4623. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4624. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4625. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4626. patient_id, _ := this.GetInt64("patient_id")
  4627. record_date, _ := this.GetInt64("record_date")
  4628. puncture_needle := this.GetString("puncture_needle")
  4629. puncture_way := this.GetString("puncture_way")
  4630. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4631. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4632. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4633. nuclein_date_str := this.GetString("nuclein_date_str")
  4634. order_remark := this.GetString("order_remark")
  4635. schedule_remark := this.GetString("schedule_remark")
  4636. catheter_operation := this.GetString("catheter_operation")
  4637. blood_flow_volume := this.GetString("blood_flow_volume")
  4638. blood_drawing, _ := this.GetInt64("blood_drawing")
  4639. dialysis_strainer := this.GetString("dialysis_strainer")
  4640. if record_id == 0 {
  4641. this.ErrorLog("id:%v", record_id)
  4642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4643. return
  4644. }
  4645. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4646. if parseStartDateErr != nil {
  4647. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4649. return
  4650. }
  4651. adminUserInfo := this.GetMobileAdminUserInfo()
  4652. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4653. if getNurseErr != nil {
  4654. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4656. return
  4657. } else if nurse == nil {
  4658. this.ErrorLog("护士不存在")
  4659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4660. return
  4661. }
  4662. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4663. //if getNurseErr != nil {
  4664. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4665. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4666. // return
  4667. //} else if nurse == nil {
  4668. // this.ErrorLog("护士不存在")
  4669. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4670. // return
  4671. //}
  4672. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4673. if getDeviceNumberErr != nil {
  4674. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4676. return
  4677. } else if deviceNumber == nil {
  4678. this.ErrorLog("床位号不存在")
  4679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4680. return
  4681. }
  4682. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4683. //
  4684. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4685. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4686. // if getPermissionErr != nil {
  4687. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4688. // return
  4689. // } else if headNursePermission == nil {
  4690. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4691. // return
  4692. // }
  4693. //}
  4694. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4695. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4696. timeLayout := "2006-01-02 15:04:05"
  4697. loc, _ := time.LoadLocation("Local")
  4698. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4699. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4700. schedulestartTime := theStartTime.Unix()
  4701. scheduleendTime := theEndTime.Unix()
  4702. var theNucleinDate int64
  4703. timeLayoutOne := "2006-01-02"
  4704. if len(nuclein_date_str) > 0 {
  4705. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4706. if err != nil {
  4707. utils.ErrorLog(err.Error())
  4708. }
  4709. theNucleinDate = theTime.Unix()
  4710. }
  4711. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4712. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4713. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4714. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4715. if err == gorm.ErrRecordNotFound { //空床位
  4716. // 修改了床位逻辑
  4717. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4718. if daySchedule.ID > 0 {
  4719. //daySchedule.BedId = bedID
  4720. //daySchedule.PartitionId = deviceNumber.ZoneID
  4721. //daySchedule.ScheduleType = schedual_type
  4722. //daySchedule.UpdatedTime = time.Now().Unix()
  4723. //err := service.UpdateSchedule(&daySchedule)
  4724. xtSchedule := models.Schedule{
  4725. PartitionId: deviceNumber.ZoneID,
  4726. BedId: bedID,
  4727. ScheduleType: schedual_type,
  4728. UpdatedTime: time.Now().Unix(),
  4729. }
  4730. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4731. if err != nil {
  4732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4733. return
  4734. }
  4735. }
  4736. } else if err == nil {
  4737. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4738. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4739. if daySchedule.ID > 0 {
  4740. //daySchedule.BedId = bedID
  4741. //daySchedule.PartitionId = deviceNumber.ZoneID
  4742. //
  4743. //daySchedule.ScheduleType = schedual_type
  4744. //daySchedule.UpdatedTime = time.Now().Unix()
  4745. //err := service.UpdateSchedule(&daySchedule)
  4746. xtSchedule := models.Schedule{
  4747. PartitionId: deviceNumber.ZoneID,
  4748. BedId: bedID,
  4749. ScheduleType: schedual_type,
  4750. UpdatedTime: time.Now().Unix(),
  4751. }
  4752. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4753. if err != nil {
  4754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4755. return
  4756. }
  4757. }
  4758. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4760. return
  4761. }
  4762. } else if err != nil {
  4763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4764. return
  4765. }
  4766. }
  4767. dialysisRecord := &models.DialysisOrder{
  4768. ID: record_id,
  4769. UserOrgId: adminUserInfo.Org.Id,
  4770. BedID: bedID,
  4771. StartNurse: nurseID,
  4772. StartTime: startDate.Unix(),
  4773. PunctureNurse: puncture_nurse,
  4774. Creator: adminUserInfo.AdminUser.Id,
  4775. Modifier: adminUserInfo.AdminUser.Id,
  4776. WashpipeNurse: washpipe_nurse,
  4777. SchedualType: schedual_type,
  4778. ChangeNurse: change_nurse,
  4779. DifficultPunctureNurse: difficult_puncture_nurse,
  4780. NewFistulaNurse: new_fistula_nurse,
  4781. QualityNurseId: quality_nurse_id,
  4782. PunctureNeedle: puncture_needle,
  4783. PunctureWay: puncture_way,
  4784. DialysisDialyszers: dialysis_dialyszers,
  4785. DialysisIrrigation: dialysis_irrigation,
  4786. BloodAccessId: blood_access_id,
  4787. NucleinDate: theNucleinDate,
  4788. OrderRemark: order_remark,
  4789. ScheduleRemark: schedule_remark,
  4790. CatheterOperation: catheter_operation,
  4791. BloodFlowVolume: blood_flow_volume,
  4792. BloodDrawing: blood_drawing,
  4793. DialysisStrainer: dialysis_strainer,
  4794. }
  4795. //修改床位号需要重新消毒
  4796. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4797. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4798. //查询第一条监测
  4799. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4800. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4801. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4802. redis := service.RedisClient()
  4803. //清空key 值
  4804. redis.Set(key, "", time.Second)
  4805. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4806. redis.Set(keyOne, "", time.Second)
  4807. defer redis.Close()
  4808. }
  4809. // 查询信息规挡的设置天数
  4810. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4811. if infor.ID > 0 && infor.WeekDay > 0 {
  4812. var cha_time int64
  4813. timeNowStr := time.Now().Format("2006-01-02")
  4814. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4815. //今日的日期减去设置的日期
  4816. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4817. if cha_time >= record_date {
  4818. //查询审核是否允许
  4819. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4820. //申请状态不允许的情况 拒绝修改
  4821. if infor.ApplicationStatus != 1 {
  4822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4823. return
  4824. }
  4825. }
  4826. }
  4827. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4828. //修改床位后重新生成消毒计划
  4829. if adminUserInfo.Org.Id == 10340 {
  4830. //根据床位号获取设备型号
  4831. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4832. //查询使用消毒最后一条消毒记录
  4833. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4834. fmt.Println("err", err)
  4835. if err == gorm.ErrRecordNotFound {
  4836. //查找排班
  4837. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4838. //查询改设备是否有消毒计划
  4839. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4840. //根据床位号获取设备id
  4841. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4842. //查询病人信息
  4843. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4844. var con = ""
  4845. if patients.IsInfectious == 0 {
  4846. con = ""
  4847. }
  4848. if patients.IsInfectious == 1 {
  4849. con = "无"
  4850. }
  4851. if patients.IsInfectious == 2 {
  4852. con = "有"
  4853. }
  4854. if errcode == nil {
  4855. var end_time int64
  4856. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4857. //新增消毒
  4858. information := models.DeviceInformation{
  4859. Date: dialysisRecord.DialysisDate,
  4860. Zone: dialysisRecord.ZoneId,
  4861. Class: dialysisRecord.SchedualType,
  4862. BedNumber: dialysisRecord.BedID,
  4863. PatientId: dialysisRecord.PatientId,
  4864. DialysisMode: scheduleByPatient.ModeId,
  4865. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4866. Disinfection: 1,
  4867. DialysisConcentration: 1,
  4868. DisinfectionStatus: 1,
  4869. Move: 1,
  4870. UserOrgId: dialysisRecord.UserOrgId,
  4871. DisinfectType: plan.Way,
  4872. DisinfectantType: plan.MachineDisinfectant,
  4873. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4874. Disinfectant: plan.Disinfectant,
  4875. Ctime: time.Now().Unix(),
  4876. Status: 1,
  4877. SignName: nurseID,
  4878. EquimentId: addmacher.ID,
  4879. DisinfectionResidue: 2,
  4880. Bed: addmacher.BedNumber,
  4881. StartTime: dialysisRecord.StartTime,
  4882. EndTime: dialysisRecord.EndTime,
  4883. Contagion: con,
  4884. WeightLoss: 0,
  4885. Hyperfiltratio: 0,
  4886. DialysisHour: "",
  4887. MachineRun: 1,
  4888. DisinfecStartime: dialysisRecord.EndTime,
  4889. DisinfecEndtime: end_time,
  4890. }
  4891. err := service.CreateInformationTwo(&information)
  4892. fmt.Println("报错", err)
  4893. }
  4894. }
  4895. }
  4896. order, _ := service.GetLastPatientOrder(record_id)
  4897. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4898. redis := service.RedisClient()
  4899. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4900. redis.Set(key, "", time.Second)
  4901. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4902. //清空key 值
  4903. redis.Set(keyOne, "", time.Second)
  4904. scheduleDateStartOne := startDate.Format("2006-01-02")
  4905. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4906. redis.Set(keyTwo, "", time.Second)
  4907. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4908. redis.Set(keyThree, "", time.Second)
  4909. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4910. redis.Set(keyFour, "", time.Second)
  4911. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4912. redis.Set(keyFive, "", time.Second)
  4913. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4914. redis.Set(keySix, "", time.Second)
  4915. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4916. redis.Set(keySeven, "", time.Second)
  4917. if updateErr != nil {
  4918. this.ErrorLog("修改上机失败:%v", updateErr)
  4919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4920. return
  4921. }
  4922. if updateErr == nil {
  4923. if tempDialysisRecord.Stage == 2 {
  4924. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4925. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4926. fmt.Println(value)
  4927. a, b := math.Modf(value)
  4928. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4929. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4930. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4931. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4932. redis := service.RedisClient()
  4933. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4934. redis.Set(key, "", time.Second)
  4935. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4936. redis.Set(keyOne, "", time.Second)
  4937. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4938. //清空key 值
  4939. redis.Set(keySix, "", time.Second)
  4940. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4941. redis.Set(keySeven, "", time.Second)
  4942. redis.Close()
  4943. if updateAssessmentErr != nil {
  4944. utils.ErrorLog("%v", updateAssessmentErr)
  4945. }
  4946. }
  4947. }
  4948. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4949. this.ServeSuccessJSON(map[string]interface{}{
  4950. "dialysis_order": dialysisRecords,
  4951. })
  4952. }
  4953. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4954. record_id, _ := c.GetInt64("id")
  4955. nurseID, _ := c.GetInt64("nurse")
  4956. end_time := c.GetString("end_time")
  4957. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4958. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4959. catheter := c.GetString("catheter")
  4960. cruor := c.GetString("cruor")
  4961. mission := c.GetString("mission")
  4962. condenser := c.GetString("condenser")
  4963. if record_id <= 0 || nurseID <= 0 {
  4964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4965. return
  4966. }
  4967. adminUserInfo := c.GetMobileAdminUserInfo()
  4968. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4969. if getNurseErr != nil {
  4970. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4972. return
  4973. } else if nurse == nil {
  4974. c.ErrorLog("护士不存在")
  4975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4976. return
  4977. }
  4978. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4979. if parseEndDateErr != nil {
  4980. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4982. return
  4983. }
  4984. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4985. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4986. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4987. // if getPermissionErr != nil {
  4988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4989. // return
  4990. // } else if headNursePermission == nil {
  4991. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4992. // return
  4993. // }
  4994. //}
  4995. // 查询信息规挡的设置天数
  4996. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4997. if infor.ID > 0 {
  4998. var cha_time int64
  4999. timeNowStr := time.Now().Format("2006-01-02")
  5000. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5001. //今日的日期减去设置的日期
  5002. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5003. if cha_time >= tempDialysisRecords.DialysisDate {
  5004. //查询审核是否允许
  5005. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5006. //申请状态不允许的情况 拒绝修改
  5007. if infor.ApplicationStatus != 1 {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5009. return
  5010. }
  5011. }
  5012. }
  5013. dialysisRecord := &models.DialysisOrder{
  5014. ID: record_id,
  5015. UserOrgId: adminUserInfo.Org.Id,
  5016. EndTime: endDate.Unix(),
  5017. FinishNurse: nurseID,
  5018. FinishModifier: adminUserInfo.AdminUser.Id,
  5019. PuncturePointHaematoma: puncture_point_haematoma,
  5020. BloodAccessInternalFistula: blood_access_internal_fistula,
  5021. Catheter: catheter,
  5022. Cruor: cruor,
  5023. Mission: mission,
  5024. Condenser: condenser,
  5025. }
  5026. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5027. redis := service.RedisClient()
  5028. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5029. //清空key 值
  5030. redis.Set(key, "", time.Second)
  5031. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5032. //清空key 值
  5033. redis.Set(keyOne, "", time.Second)
  5034. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5035. redis.Set(keySeven, "", time.Second)
  5036. redis.Close()
  5037. if updateErr != nil {
  5038. c.ErrorLog("修改下机失败:%v", updateErr)
  5039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5040. return
  5041. }
  5042. if updateErr == nil {
  5043. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5044. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5045. a, b := math.Modf(value)
  5046. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5047. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5048. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5049. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5050. redis := service.RedisClient()
  5051. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5052. redis.Set(keyTen, "", time.Second)
  5053. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5054. redis.Set(keyTwo, "", time.Second)
  5055. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5056. redis.Set(key, "", time.Second)
  5057. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5058. redis.Set(keyThree, "", time.Second)
  5059. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5060. redis.Set(keySeven, "", time.Second)
  5061. defer redis.Close()
  5062. if updateAssessmentErr != nil {
  5063. utils.ErrorLog("%v", updateAssessmentErr)
  5064. }
  5065. }
  5066. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5067. c.ServeSuccessJSON(map[string]interface{}{
  5068. "dialysis_order": dialysisRecords,
  5069. })
  5070. }
  5071. func (c *DialysisAPIController) GetLongAdvice() {
  5072. patient_id, _ := c.GetInt64("id")
  5073. adminUserInfo := c.GetMobileAdminUserInfo()
  5074. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5075. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5076. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5077. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5078. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5079. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5080. c.ServeSuccessJSON(map[string]interface{}{
  5081. "status": "1",
  5082. })
  5083. return
  5084. } else { //开启推送提醒
  5085. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5086. var advice_three []*models.DoctorAdvice
  5087. recordDateStr := time.Now().Format("2006-01-02")
  5088. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5089. nowtime := recordDate.Unix()
  5090. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5091. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5092. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5093. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5094. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5095. for _, advice := range advices {
  5096. if advice.FrequencyType == 3 {
  5097. t := time.Now()
  5098. week := int(t.Weekday())
  5099. fmt.Println(t.Weekday())
  5100. fmt.Println(week)
  5101. switch week {
  5102. case 1:
  5103. if strings.Index(advice.WeekDay, "周一") == -1 {
  5104. advice_three = append(advice_three, advice)
  5105. }
  5106. break
  5107. case 2:
  5108. if strings.Index(advice.WeekDay, "周二") == -1 {
  5109. advice_three = append(advice_three, advice)
  5110. }
  5111. break
  5112. case 3:
  5113. if strings.Index(advice.WeekDay, "周三") == -1 {
  5114. advice_three = append(advice_three, advice)
  5115. }
  5116. break
  5117. case 4:
  5118. if strings.Index(advice.WeekDay, "周四") == -1 {
  5119. advice_three = append(advice_three, advice)
  5120. }
  5121. break
  5122. case 5:
  5123. if strings.Index(advice.WeekDay, "周五") == -1 {
  5124. advice_three = append(advice_three, advice)
  5125. }
  5126. break
  5127. case 6:
  5128. if strings.Index(advice.WeekDay, "周六") == -1 {
  5129. advice_three = append(advice_three, advice)
  5130. }
  5131. break
  5132. case 0:
  5133. if strings.Index(advice.WeekDay, "周日") == -1 {
  5134. advice_three = append(advice_three, advice)
  5135. }
  5136. break
  5137. }
  5138. }
  5139. }
  5140. for _, advice := range advices_two {
  5141. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5142. now := p.Unix()
  5143. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5144. dayStr2 := "-" + dayStr
  5145. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5146. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5147. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5148. for _, ad := range advices {
  5149. advice_three = append(advice_three, ad)
  5150. }
  5151. }
  5152. if err == nil {
  5153. c.ServeSuccessJSON(map[string]interface{}{
  5154. "status": "2",
  5155. "advices": advices,
  5156. "advices_two": RemoveRepeatedElement(advice_three),
  5157. "is_open_remind": config.IsOpenRemind,
  5158. "his_config_open": hisConfig.IsOpen,
  5159. "is_advice_open": is_advice_open.IsAdviceOpen,
  5160. "prescription_open": prescription_open.IsOpen,
  5161. })
  5162. }
  5163. }
  5164. }
  5165. func (c *DialysisAPIController) GetLongAdviceOne() {
  5166. patient_id, _ := c.GetInt64("id")
  5167. startTime := c.GetString("schedule_date")
  5168. timeLayout := "2006-01-02"
  5169. loc, _ := time.LoadLocation("Local")
  5170. var theStartTime int64
  5171. if len(startTime) > 0 {
  5172. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5173. if err != nil {
  5174. utils.ErrorLog(err.Error())
  5175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. theStartTime = theTime.Unix()
  5179. }
  5180. adminUserInfo := c.GetMobileAdminUserInfo()
  5181. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5182. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5183. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5184. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5185. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5186. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5187. c.ServeSuccessJSON(map[string]interface{}{
  5188. "status": "1",
  5189. })
  5190. return
  5191. } else { //开启推送提醒
  5192. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5193. var advice_three []*models.DoctorAdvice
  5194. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5195. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5196. for _, advice := range advices {
  5197. if advice.FrequencyType == 3 {
  5198. t := time.Now()
  5199. week := int(t.Weekday())
  5200. fmt.Println(t.Weekday())
  5201. fmt.Println(week)
  5202. switch week {
  5203. case 1:
  5204. if strings.Index(advice.WeekDay, "周一") == -1 {
  5205. advice_three = append(advice_three, advice)
  5206. }
  5207. break
  5208. case 2:
  5209. if strings.Index(advice.WeekDay, "周二") == -1 {
  5210. advice_three = append(advice_three, advice)
  5211. }
  5212. break
  5213. case 3:
  5214. if strings.Index(advice.WeekDay, "周三") == -1 {
  5215. advice_three = append(advice_three, advice)
  5216. }
  5217. break
  5218. case 4:
  5219. if strings.Index(advice.WeekDay, "周四") == -1 {
  5220. advice_three = append(advice_three, advice)
  5221. }
  5222. break
  5223. case 5:
  5224. if strings.Index(advice.WeekDay, "周五") == -1 {
  5225. advice_three = append(advice_three, advice)
  5226. }
  5227. break
  5228. case 6:
  5229. if strings.Index(advice.WeekDay, "周六") == -1 {
  5230. advice_three = append(advice_three, advice)
  5231. }
  5232. break
  5233. case 0:
  5234. if strings.Index(advice.WeekDay, "周日") == -1 {
  5235. advice_three = append(advice_three, advice)
  5236. }
  5237. break
  5238. }
  5239. }
  5240. }
  5241. for _, advice := range advices_two {
  5242. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5243. now := p.Unix()
  5244. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5245. dayStr2 := "-" + dayStr
  5246. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5247. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5248. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5249. for _, ad := range advices {
  5250. advice_three = append(advice_three, ad)
  5251. }
  5252. }
  5253. if err == nil {
  5254. c.ServeSuccessJSON(map[string]interface{}{
  5255. "status": "2",
  5256. "advices": advices,
  5257. "advices_two": RemoveRepeatedElement(advice_three),
  5258. "is_open_remind": config.IsOpenRemind,
  5259. "his_config_open": hisConfig.IsOpen,
  5260. "is_advice_open": is_advice_open.IsAdviceOpen,
  5261. "prescription_open": prescription_open.IsOpen,
  5262. })
  5263. }
  5264. }
  5265. }
  5266. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5267. newArr = make([]*models.DoctorAdvice, 0)
  5268. for i := 0; i < len(arr); i++ {
  5269. repeat := false
  5270. for j := i + 1; j < len(arr); j++ {
  5271. if arr[i].ID == arr[j].ID {
  5272. repeat = true
  5273. break
  5274. }
  5275. }
  5276. if !repeat {
  5277. newArr = append(newArr, arr[i])
  5278. }
  5279. }
  5280. return
  5281. }
  5282. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5283. patient, _ := c.GetInt64("id", 0)
  5284. groupNo, _ := c.GetInt64("groupno", 0)
  5285. if patient <= 0 {
  5286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5287. return
  5288. }
  5289. adminUserInfo := c.GetMobileAdminUserInfo()
  5290. dataBody := make(map[string]interface{}, 0)
  5291. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5292. if err != nil {
  5293. utils.ErrorLog(err.Error())
  5294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5295. return
  5296. }
  5297. utils.ErrorLog("%v", dataBody)
  5298. timeLayout := "2006-01-02 15:04"
  5299. loc, _ := time.LoadLocation("Local")
  5300. timeLayout2 := "2006-01-02"
  5301. loc2, _ := time.LoadLocation("Local")
  5302. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5303. utils.ErrorLog("advice_type")
  5304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5305. return
  5306. }
  5307. adviceType := int64(2)
  5308. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5309. utils.ErrorLog("advice_date")
  5310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5311. return
  5312. }
  5313. adviceDate, _ := dataBody["advice_date"].(string)
  5314. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5315. AdviceDate := theTime.Unix()
  5316. RecordDate := theTime.Unix()
  5317. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5318. utils.ErrorLog("start_time")
  5319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5320. return
  5321. }
  5322. startTime, _ := dataBody["start_time"].(string)
  5323. if len(startTime) == 0 {
  5324. utils.ErrorLog("len(start_time) == 0")
  5325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5326. return
  5327. }
  5328. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5329. if err != nil {
  5330. utils.ErrorLog(err.Error())
  5331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5332. return
  5333. }
  5334. StartTime := theTime.Unix()
  5335. Remark := ""
  5336. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5337. remark, _ := dataBody["remark"].(string)
  5338. Remark = remark
  5339. }
  5340. var advices []*models.GroupAdvice
  5341. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5342. utils.ErrorLog("advices")
  5343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5344. return
  5345. }
  5346. adviceNames := dataBody["advices"].([]interface{})
  5347. for _, adviceNameMap := range adviceNames {
  5348. adviceNameM := adviceNameMap.(map[string]interface{})
  5349. var advice models.GroupAdvice
  5350. advice.Remark = Remark
  5351. advice.AdviceType = adviceType
  5352. advice.StartTime = StartTime
  5353. advice.AdviceDate = AdviceDate
  5354. advice.RecordDate = RecordDate
  5355. advice.Status = 1
  5356. advice.CreatedTime = time.Now().Unix()
  5357. advice.UpdatedTime = time.Now().Unix()
  5358. advice.StopState = 2
  5359. advice.ExecutionState = 2
  5360. advice.UserOrgId = adminUserInfo.Org.Id
  5361. advice.PatientId = patient
  5362. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5363. advice.IsSettle = 2
  5364. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5365. utils.ErrorLog("advice_name")
  5366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5367. return
  5368. }
  5369. adviceName, _ := adviceNameM["advice_name"].(string)
  5370. if len(adviceName) == 0 {
  5371. utils.ErrorLog("len(advice_name) == 0")
  5372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5373. return
  5374. }
  5375. advice.AdviceName = adviceName
  5376. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5377. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5378. advice.DrugSpec = drugSpec
  5379. }
  5380. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5381. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5382. advice.AdviceDesc = adviceDesc
  5383. }
  5384. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5385. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5386. advice.DrugSpecUnit = drugSpecUnit
  5387. }
  5388. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5389. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5390. // advice.SingleDose = singleDose
  5391. //}
  5392. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5393. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5394. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5395. }
  5396. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5397. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5398. advice.SingleDoseUnit = singleDoseUnit
  5399. }
  5400. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5401. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5402. // advice.PrescribingNumber = prescribingNumber
  5403. //}
  5404. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5405. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5406. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5407. }
  5408. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5409. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5410. advice.PrescribingNumberUnit = prescribingNumberUnit
  5411. }
  5412. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5413. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5414. advice.DeliveryWay = deliveryWay
  5415. }
  5416. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5417. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5418. advice.ExecutionFrequency = executionFrequency
  5419. }
  5420. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5421. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5422. advice.FrequencyType = frequency_type
  5423. }
  5424. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5425. day_count := int64(adviceNameM["day_count"].(float64))
  5426. advice.DayCount = day_count
  5427. }
  5428. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5429. week_day, _ := adviceNameM["week_day"].(string)
  5430. advice.WeekDay = week_day
  5431. }
  5432. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5433. way := int64(adviceNameM["way"].(float64))
  5434. advice.Way = way
  5435. }
  5436. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5437. drug_id := int64(adviceNameM["drug_id"].(float64))
  5438. advice.DrugId = drug_id
  5439. }
  5440. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5441. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5442. advice.DrugNameId = drug_name_id
  5443. }
  5444. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5445. remark, _ := adviceNameM["remark"].(string)
  5446. advice.Remark = remark
  5447. }
  5448. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5449. groupno := int64(adviceNameM["groupno"].(float64))
  5450. advice.GroupNo = groupno
  5451. }
  5452. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5453. template_id, _ := adviceNameM["template_id"].(string)
  5454. advice.TemplateId = template_id
  5455. }
  5456. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5457. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5458. advice.ExecutionFrequency = executionFrequency
  5459. }
  5460. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5461. children := adviceNameM["child"].([]interface{})
  5462. if len(children) > 0 {
  5463. for _, childrenMap := range children {
  5464. childMap := childrenMap.(map[string]interface{})
  5465. var child models.GroupAdvice
  5466. child.Remark = Remark
  5467. child.AdviceType = adviceType
  5468. child.StartTime = StartTime
  5469. child.AdviceDate = AdviceDate
  5470. child.RecordDate = RecordDate
  5471. child.Status = 1
  5472. child.CreatedTime = time.Now().Unix()
  5473. child.UpdatedTime = time.Now().Unix()
  5474. child.StopState = 2
  5475. child.ExecutionState = 2
  5476. child.UserOrgId = adminUserInfo.Org.Id
  5477. child.PatientId = patient
  5478. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5479. child.IsSettle = 1
  5480. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5481. utils.ErrorLog("child advice_name")
  5482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5483. return
  5484. }
  5485. childAdviceName, _ := childMap["advice_name"].(string)
  5486. if len(childAdviceName) == 0 {
  5487. utils.ErrorLog("len(child advice_name) == 0")
  5488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5489. return
  5490. }
  5491. child.AdviceName = childAdviceName
  5492. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5493. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5494. child.AdviceDesc = childAdviceDesc
  5495. }
  5496. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5497. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5498. child.DrugSpec = childDrugSpec
  5499. }
  5500. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5501. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5502. child.DrugSpecUnit = childDrugSpecUnit
  5503. }
  5504. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5505. child.SingleDose = childMap["single_dose"].(float64)
  5506. }
  5507. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5508. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5509. child.SingleDoseUnit = childSingleDoseUnit
  5510. }
  5511. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5512. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5513. }
  5514. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5515. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5516. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5517. }
  5518. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5519. groupno := int64(childMap["groupno"].(float64))
  5520. advice.GroupNo = groupno
  5521. }
  5522. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5523. remark, _ := childMap["remark"].(string)
  5524. child.Remark = remark
  5525. }
  5526. child.DeliveryWay = advice.DeliveryWay
  5527. child.ExecutionFrequency = advice.ExecutionFrequency
  5528. advice.Children = append(advice.Children, &child)
  5529. }
  5530. }
  5531. }
  5532. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5533. if temp_advice.ID == 0 {
  5534. advices = append(advices, &advice)
  5535. }
  5536. }
  5537. if len(advices) > 0 {
  5538. finish := models.XtDialysisFinish{
  5539. IsFinish: 1,
  5540. UserOrgId: adminUserInfo.Org.Id,
  5541. Status: 1,
  5542. Ctime: time.Now().Unix(),
  5543. Mtime: 0,
  5544. Module: 4,
  5545. RecordDate: AdviceDate,
  5546. Sourse: 1,
  5547. PatientId: patient,
  5548. }
  5549. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5550. if dialysisFinish.ID == 0 {
  5551. service.CreateDialysisFinish(finish)
  5552. }
  5553. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5554. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5555. for _, item := range advices {
  5556. byterequest, _ := json.Marshal(item)
  5557. adviceLog := models.XtDoctorAdviceLog{
  5558. UserOrgId: adminUserInfo.Org.Id,
  5559. PatientId: patient,
  5560. AdminUserId: adminUserInfo.AdminUser.Id,
  5561. Module: 1,
  5562. ErrLog: string(byterequest),
  5563. Status: 1,
  5564. Ctime: time.Now().Unix(),
  5565. Mtime: 0,
  5566. Source: "手机端医嘱推送",
  5567. RecordDate: item.AdviceDate,
  5568. }
  5569. service.CreateDoctorAdviceLog(adviceLog)
  5570. }
  5571. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5572. redis := service.RedisClient()
  5573. //清空key 值
  5574. redis.Set(key, "", time.Second)
  5575. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5576. redis.Set(keyOne, "", time.Second)
  5577. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5578. defer redis.Close()
  5579. redis.Set(keyThree, "", time.Second)
  5580. if err != nil {
  5581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5582. return
  5583. }
  5584. c.ServeSuccessJSON(map[string]interface{}{
  5585. "msg": "ok",
  5586. "advices": list,
  5587. })
  5588. } else {
  5589. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5590. for _, item := range advices {
  5591. byterequest, _ := json.Marshal(item)
  5592. adviceLog := models.XtDoctorAdviceLog{
  5593. UserOrgId: adminUserInfo.Org.Id,
  5594. PatientId: patient,
  5595. AdminUserId: adminUserInfo.AdminUser.Id,
  5596. Module: 1,
  5597. ErrLog: string(byterequest),
  5598. Status: 1,
  5599. Ctime: time.Now().Unix(),
  5600. Mtime: 0,
  5601. Source: "手机端医嘱推送",
  5602. RecordDate: item.AdviceDate,
  5603. }
  5604. service.CreateDoctorAdviceLog(adviceLog)
  5605. }
  5606. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5607. redis := service.RedisClient()
  5608. //清空key 值
  5609. redis.Set(key, "", time.Second)
  5610. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5611. redis.Set(keyOne, "", time.Second)
  5612. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5613. defer redis.Close()
  5614. redis.Set(keyThree, "", time.Second)
  5615. if err != nil {
  5616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5617. return
  5618. }
  5619. c.ServeSuccessJSON(map[string]interface{}{
  5620. "msg": "ok",
  5621. "advices": list,
  5622. })
  5623. }
  5624. } else {
  5625. c.ServeSuccessJSON(map[string]interface{}{
  5626. "msg": "ok",
  5627. })
  5628. }
  5629. return
  5630. }
  5631. func (c *DialysisAPIController) UploadDryWeight() {
  5632. patient_id, _ := c.GetInt64("id")
  5633. dry_weight, _ := c.GetFloat("dry_weight")
  5634. doctor_id, _ := c.GetInt64("doctor_id")
  5635. remark := c.GetString("remark")
  5636. adminUserInfo := c.GetMobileAdminUserInfo()
  5637. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5638. if err == gorm.ErrRecordNotFound {
  5639. dryWeight := &models.SgjPatientDryweight{
  5640. PatientId: patient_id,
  5641. DryWeight: dry_weight,
  5642. Remakes: remark,
  5643. Ctime: time.Now().Unix(),
  5644. Mtime: time.Now().Unix(),
  5645. Creator: doctor_id,
  5646. Status: 1,
  5647. UserOrgId: adminUserInfo.Org.Id,
  5648. AdjustedValue: "/",
  5649. UserId: adminUserInfo.AdminUser.Id,
  5650. }
  5651. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5652. redis := service.RedisClient()
  5653. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5654. redis.Set(keyOne, "", time.Second)
  5655. loc, _ := time.LoadLocation("Local")
  5656. nowTime := time.Now()
  5657. nowDay := nowTime.Format("2006-01-02")
  5658. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5660. redis.Set(key, "", time.Second)
  5661. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5662. redis.Set(keyTwo, "", time.Second)
  5663. redis.Close()
  5664. if createErr == nil {
  5665. c.ServeSuccessJSON(map[string]interface{}{
  5666. "msg": "提交成功",
  5667. "weight": dryWeight,
  5668. })
  5669. }
  5670. } else {
  5671. dryWeight := &models.SgjPatientDryweight{
  5672. PatientId: patient_id,
  5673. DryWeight: dry_weight,
  5674. Remakes: remark,
  5675. Ctime: time.Now().Unix(),
  5676. Mtime: time.Now().Unix(),
  5677. Creator: doctor_id,
  5678. Status: 1,
  5679. UserOrgId: adminUserInfo.Org.Id,
  5680. AdjustedValue: "/",
  5681. UserId: adminUserInfo.AdminUser.Id,
  5682. }
  5683. var value float64
  5684. value = dry_weight - weightAdjust.DryWeight
  5685. if value < 0 {
  5686. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5687. } else if value == 0 {
  5688. dryWeight.AdjustedValue = "/"
  5689. } else if value > 0 {
  5690. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5691. }
  5692. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5693. //康桥
  5694. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5695. timeNowStr := time.Now().Format("2006-01-02")
  5696. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5697. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5698. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5699. if beforAssesment.ID > 0 {
  5700. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5701. var dewater_amount float64
  5702. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5703. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5704. //获取key,清空redis
  5705. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5706. redis := service.RedisClient()
  5707. //清空key 值
  5708. redis.Set(key, "", time.Second)
  5709. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5710. //清空key 值
  5711. redis.Set(keyOne, "", time.Second)
  5712. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5713. //清空key 值
  5714. redis.Set(keyTwo, "", time.Second)
  5715. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5716. redis.Set(keySix, "", time.Second)
  5717. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5718. redis.Set(keySeven, "", time.Second)
  5719. }
  5720. }
  5721. redis := service.RedisClient()
  5722. loc, _ := time.LoadLocation("Local")
  5723. nowTime := time.Now()
  5724. nowDay := nowTime.Format("2006-01-02")
  5725. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5726. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5727. redis.Set(keyOne, "", time.Second)
  5728. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5729. redis.Set(key, "", time.Second)
  5730. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5731. redis.Set(keyTwo, "", time.Second)
  5732. redis.Close()
  5733. if createErr == nil {
  5734. c.ServeSuccessJSON(map[string]interface{}{
  5735. "msg": "提交成功",
  5736. "weight": dryWeight,
  5737. })
  5738. }
  5739. }
  5740. }
  5741. func (c *DialysisAPIController) GetSolution() {
  5742. patient_id, _ := c.GetInt64("patient_id")
  5743. mode_id, _ := c.GetInt64("mode_id")
  5744. adminUserInfo := c.GetMobileAdminUserInfo()
  5745. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5746. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5747. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5748. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5749. if err != nil {
  5750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5751. return
  5752. }
  5753. c.ServeSuccessJSON(map[string]interface{}{
  5754. "solution": solution,
  5755. "prescription": prescription,
  5756. "system_prescription": system_prescription,
  5757. "dialysisPrescription": dialysisPrescription,
  5758. })
  5759. }
  5760. func (c *DialysisAPIController) GetSchedule() {
  5761. schedual_type, _ := c.GetInt64("schedual_type")
  5762. adminUserInfo := c.GetMobileAdminUserInfo()
  5763. scheduleTime, _ := c.GetInt64("record_date")
  5764. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5765. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5766. c.ServeSuccessJSON(map[string]interface{}{
  5767. "number": deviceNumber,
  5768. "list": list,
  5769. })
  5770. }
  5771. func (c *DialysisAPIController) GetPatientId() {
  5772. id, _ := c.GetInt64("id")
  5773. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5774. patientId, _ := service.GetPatientId(id)
  5775. //获取该患者的所有传染病
  5776. list, _ := service.GetPatientInfectious(id)
  5777. c.ServeSuccessJSON(map[string]interface{}{
  5778. "patient": patientId,
  5779. "infectioulist": list,
  5780. })
  5781. }
  5782. func (this *DialysisAPIController) GetDialysisSchedule() {
  5783. schedualDate := this.GetString("date")
  5784. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5785. if parseDateErr != nil {
  5786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5787. return
  5788. }
  5789. adminInfo := this.GetMobileAdminUserInfo()
  5790. orgID := adminInfo.Org.Id
  5791. redis := service.RedisClient()
  5792. defer redis.Close()
  5793. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5794. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5795. if len(scheduals) > 0 {
  5796. //缓存数据
  5797. scheduals_json, err := json.Marshal(scheduals)
  5798. if err == nil {
  5799. redis.Set(key, scheduals_json, time.Second*30)
  5800. }
  5801. }
  5802. this.ServeSuccessJSON(map[string]interface{}{
  5803. "scheduals": scheduals,
  5804. })
  5805. }
  5806. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5807. change_type, _ := this.GetInt64("type", 0)
  5808. record_date := this.GetString("record_time")
  5809. patient_id, _ := this.GetInt64("patient_id", 0)
  5810. timeLayout := "2006-01-02"
  5811. loc, _ := time.LoadLocation("Local")
  5812. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5813. record_time := theAdviceRecordTime.Unix()
  5814. adminUserInfo := this.GetMobileAdminUserInfo()
  5815. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5816. if err == nil {
  5817. if len(advices) == 0 {
  5818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5819. return
  5820. } else {
  5821. this.ServeSuccessJSON(map[string]interface{}{
  5822. "advices": advices,
  5823. "schedule": sch,
  5824. })
  5825. return
  5826. }
  5827. } else {
  5828. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5829. return
  5830. }
  5831. }
  5832. func (c *DialysisAPIController) CreateConsumables() {
  5833. record_date := c.GetString("record_time")
  5834. patient_id, _ := c.GetInt64("patient_id", 0)
  5835. active, _ := c.GetInt64("active")
  5836. adminUser := c.GetMobileAdminUserInfo()
  5837. timeLayout := "2006-01-02"
  5838. loc, _ := time.LoadLocation("Local")
  5839. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5840. record_time := theRecordTime.Unix()
  5841. // 查询信息规挡的设置天数
  5842. orgid := c.GetMobileAdminUserInfo().Org.Id
  5843. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5844. if infor.ID > 0 {
  5845. var cha_time int64
  5846. timeNowStr := time.Now().Format("2006-01-02")
  5847. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5848. //今日的日期减去设置的日期
  5849. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5850. if cha_time >= record_time {
  5851. //查询审核是否允许
  5852. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5853. //申请状态不允许的情况 拒绝修改
  5854. if infor.ApplicationStatus != 1 {
  5855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5856. return
  5857. }
  5858. }
  5859. }
  5860. dataBody := make(map[string]interface{}, 0)
  5861. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5862. if err != nil {
  5863. utils.ErrorLog(err.Error())
  5864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5865. return
  5866. }
  5867. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5868. var beforePrepares []*models.DialysisBeforePrepareGoods
  5869. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5870. var dialysisBefor []*models.DialysisBeforePrepare
  5871. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5872. goods, _ := dataBody["goods"].([]interface{})
  5873. if len(goods) > 0 {
  5874. for _, item := range goods {
  5875. items := item.(map[string]interface{})
  5876. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5877. utils.ErrorLog("good_id")
  5878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5879. return
  5880. }
  5881. good_id := int64(items["good_id"].(float64))
  5882. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5883. utils.ErrorLog("good_type_id")
  5884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5885. return
  5886. }
  5887. good_type_id := int64(items["good_type_id"].(float64))
  5888. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5889. utils.ErrorLog("count")
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5891. return
  5892. }
  5893. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5894. commdity_code := items["commdity_code"].(string)
  5895. fmt.Println("commdity", commdity_code)
  5896. prepareGoods := &models.DialysisBeforePrepareGoods{
  5897. GoodTypeId: good_type_id,
  5898. GoodId: good_id,
  5899. Count: count,
  5900. StorehouseId: houseConfig.StorehouseOutInfo,
  5901. }
  5902. beforePrepares = append(beforePrepares, prepareGoods)
  5903. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5904. GoodTypeId: good_type_id,
  5905. GoodId: good_id,
  5906. Count: count,
  5907. StorehouseId: houseConfig.StorehouseOutInfo,
  5908. }
  5909. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5910. prepare := &models.DialysisBeforePrepare{
  5911. GoodTypeId: good_type_id,
  5912. GoodId: good_id,
  5913. Count: count,
  5914. PatientId: patient_id,
  5915. RecordDate: record_time,
  5916. UserOrgId: adminUser.Org.Id,
  5917. Status: 1,
  5918. Ctime: time.Now().Unix(),
  5919. Creater: adminUser.AdminUser.Id,
  5920. CommdityCode: commdity_code,
  5921. StorehouseId: houseConfig.StorehouseOutInfo,
  5922. }
  5923. dialysisBefor = append(dialysisBefor, prepare)
  5924. }
  5925. }
  5926. //查询是否有库存
  5927. for _, item := range dialysisBefor {
  5928. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5929. if err == gorm.ErrRecordNotFound {
  5930. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5931. c.ServeSuccessJSON(map[string]interface{}{
  5932. "message": "1",
  5933. "good_name": goodObj.GoodName,
  5934. "specification_name": goodObj.SpecificationName,
  5935. })
  5936. return
  5937. }
  5938. if err != nil {
  5939. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5940. c.ServeSuccessJSON(map[string]interface{}{
  5941. "message": "1",
  5942. "good_name": goodObj.GoodName,
  5943. "specification_name": goodObj.SpecificationName,
  5944. })
  5945. return
  5946. }
  5947. }
  5948. fmt.Println("active-----------------------", active)
  5949. fmt.Println("len(goods)-----------------------", len(goods))
  5950. //新增
  5951. if active == 1 && len(goods) > 0 {
  5952. for _, item := range dialysisBefor {
  5953. dialyPrepareOne := models.DialysisBeforePrepare{
  5954. GoodTypeId: item.GoodTypeId,
  5955. GoodId: item.GoodId,
  5956. PatientId: item.PatientId,
  5957. RecordDate: item.RecordDate,
  5958. UserOrgId: item.UserOrgId,
  5959. Count: item.Count,
  5960. Ctime: time.Now().Unix(),
  5961. Creater: item.Creater,
  5962. CommdityCode: item.CommdityCode,
  5963. Status: 1,
  5964. StorehouseId: houseConfig.StorehouseOutInfo,
  5965. }
  5966. //先清除再插入
  5967. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5968. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5969. //查询默认仓库
  5970. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5971. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5972. var total_count int64
  5973. for _, it := range stockList {
  5974. total_count += it.StockCount
  5975. }
  5976. //基础库插入数据
  5977. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5978. //更新库存
  5979. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5980. var flush_count int64
  5981. for _, it := range goodList {
  5982. flush_count += it.StockCount
  5983. }
  5984. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5985. }
  5986. if err == nil {
  5987. c.ServeSuccessJSON(map[string]interface{}{
  5988. "msg": "保存成功",
  5989. "message": "2",
  5990. })
  5991. return
  5992. } else {
  5993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5994. return
  5995. }
  5996. }
  5997. if len(beforePrepares) > 0 && active == 2 {
  5998. for _, item := range beforePrepares {
  5999. //1.查看该患者该耗材型号最后一次出库数量
  6000. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6001. //判断当前出库数量和最后一次出库数量的大小
  6002. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6003. if item.Count <= goodInfo.Count {
  6004. //退库
  6005. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6006. //查询今日出库数据
  6007. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6008. for _, it := range list {
  6009. prepare := models.DialysisBeforePrepare{
  6010. UserOrgId: it.OrgId,
  6011. PatientId: patient_id,
  6012. RecordDate: it.RecordTime,
  6013. GoodId: it.GoodId,
  6014. GoodTypeId: it.GoodTypeId,
  6015. Count: it.Count,
  6016. Ctime: time.Now().Unix(),
  6017. Creater: adminUser.AdminUser.Id,
  6018. Status: 1,
  6019. StorehouseId: houseConfig.StorehouseOutInfo,
  6020. }
  6021. //删除准备表数据
  6022. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6023. service.CreateDialysisBeforePrepareOne(&prepare)
  6024. }
  6025. }
  6026. var last_total int64
  6027. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6028. if item.Count >= goodInfo.Count {
  6029. //查询当前批次当前耗材最后一条出库数据
  6030. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6031. //计算当前出库和最后一次出库数据相差数据
  6032. last_total = item.Count - lastOutInfo.Count
  6033. //查询该批次剩余库存
  6034. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6035. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6036. if lastInfo.StockCount >= last_total {
  6037. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6038. //查询今日出库数据
  6039. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6040. for _, it := range list {
  6041. prepare := models.DialysisBeforePrepare{
  6042. UserOrgId: it.OrgId,
  6043. PatientId: patient_id,
  6044. RecordDate: it.RecordTime,
  6045. GoodId: it.GoodId,
  6046. GoodTypeId: it.GoodTypeId,
  6047. Count: it.Count,
  6048. Ctime: time.Now().Unix(),
  6049. Creater: adminUser.AdminUser.Id,
  6050. Status: 1,
  6051. StorehouseId: houseConfig.StorehouseOutInfo,
  6052. }
  6053. //删除准备表数据
  6054. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6055. service.CreateDialysisBeforePrepareOne(&prepare)
  6056. //查询默认仓库
  6057. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6058. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6059. var total_count int64
  6060. for _, it := range stockList {
  6061. total_count += it.StockCount
  6062. }
  6063. //基础库插入数据
  6064. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6065. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6066. var flush_count int64
  6067. for _, it := range goodList {
  6068. flush_count += it.StockCount
  6069. }
  6070. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6071. }
  6072. }
  6073. //如果库存不够,则出库到下一个批次
  6074. if lastInfo.StockCount < last_total {
  6075. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6076. //查询今日出库数据
  6077. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6078. for _, it := range list {
  6079. prepare := models.DialysisBeforePrepare{
  6080. UserOrgId: it.OrgId,
  6081. PatientId: patient_id,
  6082. RecordDate: it.RecordTime,
  6083. GoodId: it.GoodId,
  6084. GoodTypeId: it.GoodTypeId,
  6085. Count: it.Count,
  6086. Ctime: time.Now().Unix(),
  6087. Creater: adminUser.AdminUser.Id,
  6088. Status: 1,
  6089. StorehouseId: houseConfig.StorehouseOutInfo,
  6090. }
  6091. //删除准备表数据
  6092. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6093. service.CreateDialysisBeforePrepareOne(&prepare)
  6094. //查询默认仓库
  6095. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6096. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6097. var total_count int64
  6098. for _, it := range stockList {
  6099. total_count += it.StockCount
  6100. }
  6101. //基础库插入数据
  6102. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6103. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6104. var flush_count int64
  6105. for _, it := range goodList {
  6106. flush_count += it.StockCount
  6107. }
  6108. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6109. }
  6110. if err != nil {
  6111. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6112. c.ServeSuccessJSON(map[string]interface{}{
  6113. "message": "1",
  6114. "good_name": goodObj.GoodName,
  6115. "specification_name": goodObj.SpecificationName,
  6116. })
  6117. return
  6118. }
  6119. }
  6120. }
  6121. if err != nil {
  6122. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6123. c.ServeSuccessJSON(map[string]interface{}{
  6124. "message": "1",
  6125. "good_name": goodObj.GoodName,
  6126. "specification_name": goodObj.SpecificationName,
  6127. })
  6128. return
  6129. }
  6130. }
  6131. }
  6132. }
  6133. var errs error
  6134. if errs == nil {
  6135. c.ServeSuccessJSON(map[string]interface{}{
  6136. "msg": "提交成功",
  6137. "message": "2",
  6138. "good_name": "",
  6139. "specification_name": "",
  6140. })
  6141. return
  6142. } else {
  6143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6144. return
  6145. }
  6146. }
  6147. func (c *DialysisAPIController) CreateStockOutInfo() {
  6148. patient_id, _ := c.GetInt64("patient_id", 0)
  6149. record_date := c.GetString("record_time")
  6150. if patient_id <= 0 {
  6151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6152. return
  6153. }
  6154. adminInfo := c.GetMobileAdminUserInfo()
  6155. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6156. timeLayout := "2006-01-02"
  6157. loc, _ := time.LoadLocation("Local")
  6158. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6159. record_time := theRecordTime.Unix()
  6160. // 查询信息规挡的设置天数
  6161. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6162. if infor.ID > 0 && infor.WeekDay > 0 {
  6163. var cha_time int64
  6164. timeNowStr := time.Now().Format("2006-01-02")
  6165. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6166. //今日的日期减去设置的日期
  6167. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6168. if cha_time >= record_time {
  6169. //查询审核是否允许
  6170. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6171. //申请状态不允许的情况 拒绝修改
  6172. if infor.ApplicationStatus != 1 {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6174. return
  6175. }
  6176. }
  6177. }
  6178. //创建步骤表
  6179. finish := models.XtDialysisFinish{
  6180. IsFinish: 1,
  6181. UserOrgId: adminInfo.Org.Id,
  6182. Status: 1,
  6183. Ctime: time.Now().Unix(),
  6184. Mtime: 0,
  6185. Module: 11,
  6186. RecordDate: record_time,
  6187. Sourse: 1,
  6188. PatientId: patient_id,
  6189. }
  6190. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6191. if dialysisFinish.ID == 0 {
  6192. service.CreateDialysisFinish(finish)
  6193. }
  6194. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6195. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6196. //去重
  6197. consumables = RemoveRepeatedGood(consumables)
  6198. if adminInfo.Org.Id == 9919 {
  6199. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6200. //查询是否有库存
  6201. for _, item := range consumables {
  6202. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6203. if item.Count > warehouse.Count {
  6204. goodErrcode := models.XtGoodErrcode{
  6205. UserOrgId: item.UserOrgId,
  6206. Errcode: "自动出库库存不足",
  6207. GoodId: item.GoodId,
  6208. Status: 1,
  6209. Ctime: time.Now().Unix(),
  6210. Mtime: 0,
  6211. Count: 0,
  6212. StockCount: 0,
  6213. Creater: creator,
  6214. BatchNumberId: warehouse.ID,
  6215. WarehouseOutId: 0,
  6216. }
  6217. service.CreateGoodErrcode(goodErrcode)
  6218. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6219. c.ServeSuccessJSON(map[string]interface{}{
  6220. "message": "1",
  6221. "good_name": goodObj.GoodName,
  6222. "specification_name": goodObj.SpecificationName,
  6223. })
  6224. return
  6225. }
  6226. }
  6227. //查询是否有出库单
  6228. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6229. if err == gorm.ErrRecordNotFound {
  6230. //没有记录,则创建出库单
  6231. timeStr := time.Now().Format("2006-01-02")
  6232. timeArr := strings.Split(timeStr, "-")
  6233. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6234. total = total + 1
  6235. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6236. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6237. number = number + total
  6238. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6239. creater := adminInfo.AdminUser.Id
  6240. warehouseOut := models.WarehouseOut{
  6241. WarehouseOutOrderNumber: warehousing_out_order,
  6242. OperationTime: time.Now().Unix(),
  6243. OrgId: adminInfo.Org.Id,
  6244. Creater: creater,
  6245. Ctime: time.Now().Unix(),
  6246. Status: 1,
  6247. WarehouseOutTime: record_time,
  6248. Dealer: 0,
  6249. Manufacturer: 0,
  6250. Type: 1,
  6251. IsSys: 1,
  6252. StorehouseId: houseConfig.StorehouseOutInfo,
  6253. IsCheck: 1,
  6254. }
  6255. err := service.AddSigleWarehouseOut(&warehouseOut)
  6256. if err != nil {
  6257. goodErrcode := models.XtGoodErrcode{
  6258. UserOrgId: adminInfo.Org.Id,
  6259. Errcode: "创建出库单失败",
  6260. GoodId: 0,
  6261. Status: 1,
  6262. Ctime: time.Now().Unix(),
  6263. Mtime: 0,
  6264. Count: 0,
  6265. StockCount: 0,
  6266. Creater: creator,
  6267. BatchNumberId: 0,
  6268. WarehouseOutId: 0,
  6269. }
  6270. service.CreateGoodErrcode(goodErrcode)
  6271. utils.TraceLog("创建出库单失败 err = %v", err)
  6272. } else {
  6273. for _, item := range consumables {
  6274. //出库
  6275. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6276. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6277. if err == nil {
  6278. goodErrcode := models.XtGoodErrcode{
  6279. UserOrgId: adminInfo.Org.Id,
  6280. Errcode: "自动出库接口报错",
  6281. GoodId: 0,
  6282. Status: 1,
  6283. Ctime: time.Now().Unix(),
  6284. Mtime: 0,
  6285. Count: 0,
  6286. StockCount: 0,
  6287. Creater: creator,
  6288. BatchNumberId: 0,
  6289. WarehouseOutId: 0,
  6290. }
  6291. service.CreateGoodErrcode(goodErrcode)
  6292. utils.TraceLog("创建出库单失败 err = %v", err)
  6293. }
  6294. //查询
  6295. //出库数量相加
  6296. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6297. if errs != nil {
  6298. goodErrcode := models.XtGoodErrcode{
  6299. UserOrgId: item.UserOrgId,
  6300. Errcode: "创建剩余库存字段报错",
  6301. GoodId: item.GoodId,
  6302. Status: 1,
  6303. Ctime: time.Now().Unix(),
  6304. Mtime: 0,
  6305. Count: 0,
  6306. StockCount: 0,
  6307. Creater: creater,
  6308. BatchNumberId: 0,
  6309. WarehouseOutId: 0,
  6310. }
  6311. service.CreateGoodErrcode(goodErrcode)
  6312. }
  6313. }
  6314. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6315. if len(list) == 0 {
  6316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6317. return
  6318. }
  6319. for _, item := range list {
  6320. prepare := models.DialysisBeforePrepare{
  6321. UserOrgId: adminInfo.Org.Id,
  6322. PatientId: patient_id,
  6323. RecordDate: record_time,
  6324. GoodId: item.GoodId,
  6325. GoodTypeId: item.GoodTypeId,
  6326. Count: item.Count,
  6327. Creater: adminInfo.AdminUser.Id,
  6328. Status: 1,
  6329. Ctime: time.Now().Unix(),
  6330. StorehouseId: houseConfig.StorehouseOutInfo,
  6331. }
  6332. //清空准备表数据
  6333. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6334. if err != nil {
  6335. goodErrcode := models.XtGoodErrcode{
  6336. UserOrgId: item.OrgId,
  6337. Errcode: "自动出库清空准备表数据报错",
  6338. GoodId: item.GoodId,
  6339. Status: 1,
  6340. Ctime: time.Now().Unix(),
  6341. Mtime: 0,
  6342. Count: 0,
  6343. StockCount: 0,
  6344. Creater: creater,
  6345. BatchNumberId: 0,
  6346. WarehouseOutId: 0,
  6347. }
  6348. service.CreateGoodErrcode(goodErrcode)
  6349. }
  6350. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6351. if errs != nil {
  6352. goodErrcode := models.XtGoodErrcode{
  6353. UserOrgId: item.OrgId,
  6354. Errcode: "自动出库创建准备表数据报错",
  6355. GoodId: item.GoodId,
  6356. Status: 1,
  6357. Ctime: time.Now().Unix(),
  6358. Mtime: 0,
  6359. Count: 0,
  6360. StockCount: 0,
  6361. Creater: creater,
  6362. BatchNumberId: 0,
  6363. WarehouseOutId: 0,
  6364. }
  6365. service.CreateGoodErrcode(goodErrcode)
  6366. }
  6367. //查询默认仓库
  6368. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6369. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6370. var total_count int64
  6371. for _, it := range stockList {
  6372. total_count += it.StockCount
  6373. }
  6374. //基础库插入数据
  6375. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6376. if errcodes != nil {
  6377. goodErrcode := models.XtGoodErrcode{
  6378. UserOrgId: item.OrgId,
  6379. Errcode: "自动出库基础库插入数据",
  6380. GoodId: item.GoodId,
  6381. Status: 1,
  6382. Ctime: time.Now().Unix(),
  6383. Mtime: 0,
  6384. Count: 0,
  6385. StockCount: 0,
  6386. Creater: creater,
  6387. BatchNumberId: 0,
  6388. WarehouseOutId: 0,
  6389. }
  6390. service.CreateGoodErrcode(goodErrcode)
  6391. }
  6392. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6393. var flush_count int64
  6394. for _, it := range goodList {
  6395. flush_count += it.StockCount
  6396. }
  6397. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6398. if errsss != nil {
  6399. goodErrcode := models.XtGoodErrcode{
  6400. UserOrgId: item.OrgId,
  6401. Errcode: "自动出库剩余库存更新数据",
  6402. GoodId: item.GoodId,
  6403. Status: 1,
  6404. Ctime: time.Now().Unix(),
  6405. Mtime: 0,
  6406. Count: 0,
  6407. StockCount: 0,
  6408. Creater: creater,
  6409. BatchNumberId: 0,
  6410. WarehouseOutId: 0,
  6411. }
  6412. service.CreateGoodErrcode(goodErrcode)
  6413. }
  6414. }
  6415. }
  6416. //
  6417. } else if err == nil {
  6418. for _, item := range consumables {
  6419. //出库
  6420. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6421. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6422. if err != nil {
  6423. goodErrcode := models.XtGoodErrcode{
  6424. UserOrgId: adminInfo.Org.Id,
  6425. Errcode: "自动出库接口报错",
  6426. GoodId: 0,
  6427. Status: 1,
  6428. Ctime: time.Now().Unix(),
  6429. Mtime: 0,
  6430. Count: 0,
  6431. StockCount: 0,
  6432. Creater: creator,
  6433. BatchNumberId: 0,
  6434. WarehouseOutId: 0,
  6435. }
  6436. service.CreateGoodErrcode(goodErrcode)
  6437. }
  6438. //出库数量相加
  6439. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6440. if errss != nil {
  6441. goodErrcode := models.XtGoodErrcode{
  6442. UserOrgId: item.UserOrgId,
  6443. Errcode: "创建剩余库存字段报错",
  6444. GoodId: item.GoodId,
  6445. Status: 1,
  6446. Ctime: time.Now().Unix(),
  6447. Mtime: time.Now().Unix(),
  6448. Count: 0,
  6449. StockCount: 0,
  6450. Creater: item.Creater,
  6451. BatchNumberId: 0,
  6452. WarehouseOutId: 0,
  6453. }
  6454. service.CreateGoodErrcode(goodErrcode)
  6455. }
  6456. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6457. if len(list) == 0 {
  6458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6459. return
  6460. }
  6461. for _, item := range list {
  6462. prepare := models.DialysisBeforePrepare{
  6463. UserOrgId: adminInfo.Org.Id,
  6464. PatientId: patient_id,
  6465. RecordDate: record_time,
  6466. GoodId: item.GoodId,
  6467. GoodTypeId: item.GoodTypeId,
  6468. Count: item.Count,
  6469. Creater: adminInfo.AdminUser.Id,
  6470. Status: 1,
  6471. Ctime: time.Now().Unix(),
  6472. StorehouseId: houseConfig.StorehouseOutInfo,
  6473. }
  6474. //清空准备表数据
  6475. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6476. if errs != nil {
  6477. goodErrcode := models.XtGoodErrcode{
  6478. UserOrgId: adminInfo.Org.Id,
  6479. Errcode: "自动出库清空准备表数据报错",
  6480. GoodId: 0,
  6481. Status: 1,
  6482. Ctime: time.Now().Unix(),
  6483. Mtime: 0,
  6484. Count: 0,
  6485. StockCount: 0,
  6486. Creater: creator,
  6487. BatchNumberId: 0,
  6488. WarehouseOutId: 0,
  6489. }
  6490. service.CreateGoodErrcode(goodErrcode)
  6491. }
  6492. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6493. if errcodes != nil {
  6494. goodErrcode := models.XtGoodErrcode{
  6495. UserOrgId: adminInfo.Org.Id,
  6496. Errcode: "自动出库创建准备表数据报错",
  6497. GoodId: 0,
  6498. Status: 1,
  6499. Ctime: time.Now().Unix(),
  6500. Mtime: 0,
  6501. Count: 0,
  6502. StockCount: 0,
  6503. Creater: creator,
  6504. BatchNumberId: 0,
  6505. WarehouseOutId: 0,
  6506. }
  6507. service.CreateGoodErrcode(goodErrcode)
  6508. }
  6509. //查询默认仓库
  6510. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6511. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6512. var total_count int64
  6513. for _, it := range stockList {
  6514. total_count += it.StockCount
  6515. }
  6516. //基础库插入数据
  6517. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6518. if errcodes != nil {
  6519. goodErrcode := models.XtGoodErrcode{
  6520. UserOrgId: adminInfo.Org.Id,
  6521. Errcode: "自动出库基础库插入数据报错",
  6522. GoodId: 0,
  6523. Status: 1,
  6524. Ctime: time.Now().Unix(),
  6525. Mtime: 0,
  6526. Count: 0,
  6527. StockCount: 0,
  6528. Creater: creator,
  6529. BatchNumberId: 0,
  6530. WarehouseOutId: 0,
  6531. }
  6532. service.CreateGoodErrcode(goodErrcode)
  6533. }
  6534. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6535. var flush_count int64
  6536. for _, it := range goodList {
  6537. flush_count += it.StockCount
  6538. }
  6539. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6540. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6541. if errss != nil {
  6542. goodErrcode := models.XtGoodErrcode{
  6543. UserOrgId: item.OrgId,
  6544. Errcode: "自动出库剩余库存更新数据",
  6545. GoodId: item.GoodId,
  6546. Status: 1,
  6547. Ctime: time.Now().Unix(),
  6548. Mtime: 0,
  6549. Count: 0,
  6550. StockCount: 0,
  6551. Creater: creater,
  6552. BatchNumberId: 0,
  6553. WarehouseOutId: 0,
  6554. }
  6555. service.CreateGoodErrcode(goodErrcode)
  6556. }
  6557. }
  6558. }
  6559. }
  6560. c.ServeSuccessJSON(map[string]interface{}{
  6561. "msg": "提交成功",
  6562. "message": "2",
  6563. "good_name": "",
  6564. "specification_name": "",
  6565. })
  6566. return
  6567. }
  6568. if record.IsOpen == 1 {
  6569. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6570. //查询是否有库存
  6571. for _, item := range consumables {
  6572. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6573. if item.Count > warehouse.Count {
  6574. goodErrcode := models.XtGoodErrcode{
  6575. UserOrgId: item.UserOrgId,
  6576. Errcode: "自动出库库存不足",
  6577. GoodId: item.GoodId,
  6578. Status: 1,
  6579. Ctime: time.Now().Unix(),
  6580. Mtime: 0,
  6581. Count: 0,
  6582. StockCount: 0,
  6583. Creater: creator,
  6584. BatchNumberId: warehouse.ID,
  6585. WarehouseOutId: 0,
  6586. }
  6587. service.CreateGoodErrcode(goodErrcode)
  6588. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6589. c.ServeSuccessJSON(map[string]interface{}{
  6590. "message": "1",
  6591. "good_name": goodObj.GoodName,
  6592. "specification_name": goodObj.SpecificationName,
  6593. })
  6594. return
  6595. }
  6596. }
  6597. //查询是否有出库单
  6598. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6599. if err == gorm.ErrRecordNotFound {
  6600. //没有记录,则创建出库单
  6601. timeStr := time.Now().Format("2006-01-02")
  6602. timeArr := strings.Split(timeStr, "-")
  6603. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6604. total = total + 1
  6605. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6606. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6607. number = number + total
  6608. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6609. creater := adminInfo.AdminUser.Id
  6610. warehouseOut := models.WarehouseOut{
  6611. WarehouseOutOrderNumber: warehousing_out_order,
  6612. OperationTime: time.Now().Unix(),
  6613. OrgId: adminInfo.Org.Id,
  6614. Creater: creater,
  6615. Ctime: time.Now().Unix(),
  6616. Status: 1,
  6617. WarehouseOutTime: record_time,
  6618. Dealer: 0,
  6619. Manufacturer: 0,
  6620. Type: 1,
  6621. IsSys: 1,
  6622. StorehouseId: houseConfig.StorehouseOutInfo,
  6623. IsCheck: 1,
  6624. }
  6625. err := service.AddSigleWarehouseOut(&warehouseOut)
  6626. if err != nil {
  6627. goodErrcode := models.XtGoodErrcode{
  6628. UserOrgId: adminInfo.Org.Id,
  6629. Errcode: "创建出库单失败",
  6630. GoodId: 0,
  6631. Status: 1,
  6632. Ctime: time.Now().Unix(),
  6633. Mtime: 0,
  6634. Count: 0,
  6635. StockCount: 0,
  6636. Creater: creator,
  6637. BatchNumberId: 0,
  6638. WarehouseOutId: 0,
  6639. }
  6640. service.CreateGoodErrcode(goodErrcode)
  6641. utils.TraceLog("创建出库单失败 err = %v", err)
  6642. } else {
  6643. for _, item := range consumables {
  6644. //出库
  6645. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6646. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6647. if err == nil {
  6648. goodErrcode := models.XtGoodErrcode{
  6649. UserOrgId: adminInfo.Org.Id,
  6650. Errcode: "自动出库接口报错",
  6651. GoodId: 0,
  6652. Status: 1,
  6653. Ctime: time.Now().Unix(),
  6654. Mtime: 0,
  6655. Count: 0,
  6656. StockCount: 0,
  6657. Creater: creator,
  6658. BatchNumberId: 0,
  6659. WarehouseOutId: 0,
  6660. }
  6661. service.CreateGoodErrcode(goodErrcode)
  6662. utils.TraceLog("创建出库单失败 err = %v", err)
  6663. }
  6664. //查询
  6665. //出库数量相加
  6666. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6667. if errs != nil {
  6668. goodErrcode := models.XtGoodErrcode{
  6669. UserOrgId: item.UserOrgId,
  6670. Errcode: "创建剩余库存字段报错",
  6671. GoodId: item.GoodId,
  6672. Status: 1,
  6673. Ctime: time.Now().Unix(),
  6674. Mtime: 0,
  6675. Count: 0,
  6676. StockCount: 0,
  6677. Creater: creater,
  6678. BatchNumberId: 0,
  6679. WarehouseOutId: 0,
  6680. }
  6681. service.CreateGoodErrcode(goodErrcode)
  6682. }
  6683. }
  6684. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6685. if len(list) == 0 {
  6686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6687. return
  6688. }
  6689. for _, item := range list {
  6690. prepare := models.DialysisBeforePrepare{
  6691. UserOrgId: adminInfo.Org.Id,
  6692. PatientId: patient_id,
  6693. RecordDate: record_time,
  6694. GoodId: item.GoodId,
  6695. GoodTypeId: item.GoodTypeId,
  6696. Count: item.Count,
  6697. Creater: adminInfo.AdminUser.Id,
  6698. Status: 1,
  6699. Ctime: time.Now().Unix(),
  6700. StorehouseId: houseConfig.StorehouseOutInfo,
  6701. }
  6702. //清空准备表数据
  6703. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6704. if err != nil {
  6705. goodErrcode := models.XtGoodErrcode{
  6706. UserOrgId: item.OrgId,
  6707. Errcode: "自动出库清空准备表数据报错",
  6708. GoodId: item.GoodId,
  6709. Status: 1,
  6710. Ctime: time.Now().Unix(),
  6711. Mtime: 0,
  6712. Count: 0,
  6713. StockCount: 0,
  6714. Creater: creater,
  6715. BatchNumberId: 0,
  6716. WarehouseOutId: 0,
  6717. }
  6718. service.CreateGoodErrcode(goodErrcode)
  6719. }
  6720. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6721. if errs != nil {
  6722. goodErrcode := models.XtGoodErrcode{
  6723. UserOrgId: item.OrgId,
  6724. Errcode: "自动出库创建准备表数据报错",
  6725. GoodId: item.GoodId,
  6726. Status: 1,
  6727. Ctime: time.Now().Unix(),
  6728. Mtime: 0,
  6729. Count: 0,
  6730. StockCount: 0,
  6731. Creater: creater,
  6732. BatchNumberId: 0,
  6733. WarehouseOutId: 0,
  6734. }
  6735. service.CreateGoodErrcode(goodErrcode)
  6736. }
  6737. //查询默认仓库
  6738. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6739. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6740. var total_count int64
  6741. for _, it := range stockList {
  6742. total_count += it.StockCount
  6743. }
  6744. //基础库插入数据
  6745. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6746. if errcodes != nil {
  6747. goodErrcode := models.XtGoodErrcode{
  6748. UserOrgId: item.OrgId,
  6749. Errcode: "自动出库基础库插入数据",
  6750. GoodId: item.GoodId,
  6751. Status: 1,
  6752. Ctime: time.Now().Unix(),
  6753. Mtime: 0,
  6754. Count: 0,
  6755. StockCount: 0,
  6756. Creater: creater,
  6757. BatchNumberId: 0,
  6758. WarehouseOutId: 0,
  6759. }
  6760. service.CreateGoodErrcode(goodErrcode)
  6761. }
  6762. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6763. var flush_count int64
  6764. for _, it := range goodList {
  6765. flush_count += it.StockCount
  6766. }
  6767. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6768. if errsss != nil {
  6769. goodErrcode := models.XtGoodErrcode{
  6770. UserOrgId: item.OrgId,
  6771. Errcode: "自动出库剩余库存更新数据",
  6772. GoodId: item.GoodId,
  6773. Status: 1,
  6774. Ctime: time.Now().Unix(),
  6775. Mtime: 0,
  6776. Count: 0,
  6777. StockCount: 0,
  6778. Creater: creater,
  6779. BatchNumberId: 0,
  6780. WarehouseOutId: 0,
  6781. }
  6782. service.CreateGoodErrcode(goodErrcode)
  6783. }
  6784. }
  6785. }
  6786. //
  6787. } else if err == nil {
  6788. for _, item := range consumables {
  6789. //出库
  6790. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6791. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6792. if err != nil {
  6793. goodErrcode := models.XtGoodErrcode{
  6794. UserOrgId: adminInfo.Org.Id,
  6795. Errcode: "自动出库接口报错",
  6796. GoodId: 0,
  6797. Status: 1,
  6798. Ctime: time.Now().Unix(),
  6799. Mtime: 0,
  6800. Count: 0,
  6801. StockCount: 0,
  6802. Creater: creator,
  6803. BatchNumberId: 0,
  6804. WarehouseOutId: 0,
  6805. }
  6806. service.CreateGoodErrcode(goodErrcode)
  6807. }
  6808. //出库数量相加
  6809. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6810. if errss != nil {
  6811. goodErrcode := models.XtGoodErrcode{
  6812. UserOrgId: item.UserOrgId,
  6813. Errcode: "创建剩余库存字段报错",
  6814. GoodId: item.GoodId,
  6815. Status: 1,
  6816. Ctime: time.Now().Unix(),
  6817. Mtime: time.Now().Unix(),
  6818. Count: 0,
  6819. StockCount: 0,
  6820. Creater: item.Creater,
  6821. BatchNumberId: 0,
  6822. WarehouseOutId: 0,
  6823. }
  6824. service.CreateGoodErrcode(goodErrcode)
  6825. }
  6826. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6827. if len(list) == 0 {
  6828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6829. return
  6830. }
  6831. for _, item := range list {
  6832. prepare := models.DialysisBeforePrepare{
  6833. UserOrgId: adminInfo.Org.Id,
  6834. PatientId: patient_id,
  6835. RecordDate: record_time,
  6836. GoodId: item.GoodId,
  6837. GoodTypeId: item.GoodTypeId,
  6838. Count: item.Count,
  6839. Creater: adminInfo.AdminUser.Id,
  6840. Status: 1,
  6841. Ctime: time.Now().Unix(),
  6842. StorehouseId: houseConfig.StorehouseOutInfo,
  6843. }
  6844. //清空准备表数据
  6845. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6846. if errs != nil {
  6847. goodErrcode := models.XtGoodErrcode{
  6848. UserOrgId: adminInfo.Org.Id,
  6849. Errcode: "自动出库清空准备表数据报错",
  6850. GoodId: 0,
  6851. Status: 1,
  6852. Ctime: time.Now().Unix(),
  6853. Mtime: 0,
  6854. Count: 0,
  6855. StockCount: 0,
  6856. Creater: creator,
  6857. BatchNumberId: 0,
  6858. WarehouseOutId: 0,
  6859. }
  6860. service.CreateGoodErrcode(goodErrcode)
  6861. }
  6862. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6863. if errcodes != nil {
  6864. goodErrcode := models.XtGoodErrcode{
  6865. UserOrgId: adminInfo.Org.Id,
  6866. Errcode: "自动出库创建准备表数据报错",
  6867. GoodId: 0,
  6868. Status: 1,
  6869. Ctime: time.Now().Unix(),
  6870. Mtime: 0,
  6871. Count: 0,
  6872. StockCount: 0,
  6873. Creater: creator,
  6874. BatchNumberId: 0,
  6875. WarehouseOutId: 0,
  6876. }
  6877. service.CreateGoodErrcode(goodErrcode)
  6878. }
  6879. //查询默认仓库
  6880. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6881. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6882. var total_count int64
  6883. for _, it := range stockList {
  6884. total_count += it.StockCount
  6885. }
  6886. //基础库插入数据
  6887. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6888. if errcodes != nil {
  6889. goodErrcode := models.XtGoodErrcode{
  6890. UserOrgId: adminInfo.Org.Id,
  6891. Errcode: "自动出库基础库插入数据报错",
  6892. GoodId: 0,
  6893. Status: 1,
  6894. Ctime: time.Now().Unix(),
  6895. Mtime: 0,
  6896. Count: 0,
  6897. StockCount: 0,
  6898. Creater: creator,
  6899. BatchNumberId: 0,
  6900. WarehouseOutId: 0,
  6901. }
  6902. service.CreateGoodErrcode(goodErrcode)
  6903. }
  6904. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6905. var flush_count int64
  6906. for _, it := range goodList {
  6907. flush_count += it.StockCount
  6908. }
  6909. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6910. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6911. if errss != nil {
  6912. goodErrcode := models.XtGoodErrcode{
  6913. UserOrgId: item.OrgId,
  6914. Errcode: "自动出库剩余库存更新数据",
  6915. GoodId: item.GoodId,
  6916. Status: 1,
  6917. Ctime: time.Now().Unix(),
  6918. Mtime: 0,
  6919. Count: 0,
  6920. StockCount: 0,
  6921. Creater: creater,
  6922. BatchNumberId: 0,
  6923. WarehouseOutId: 0,
  6924. }
  6925. service.CreateGoodErrcode(goodErrcode)
  6926. }
  6927. }
  6928. }
  6929. }
  6930. c.ServeSuccessJSON(map[string]interface{}{
  6931. "msg": "提交成功",
  6932. "message": "2",
  6933. "good_name": "",
  6934. "specification_name": "",
  6935. })
  6936. return
  6937. } else {
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6939. return
  6940. }
  6941. }
  6942. func (c *DialysisAPIController) EditConsumables() {
  6943. patient_id, _ := c.GetInt64("patient_id", 0)
  6944. record_date := c.GetString("record_time")
  6945. if patient_id <= 0 {
  6946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6947. return
  6948. }
  6949. adminInfo := c.GetMobileAdminUserInfo()
  6950. timeLayout := "2006-01-02"
  6951. loc, _ := time.LoadLocation("Local")
  6952. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6953. record_time := theRecordTime.Unix()
  6954. // 查询信息规挡的设置天数
  6955. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6956. if infor.ID > 0 && infor.WeekDay > 0 {
  6957. var cha_time int64
  6958. timeNowStr := time.Now().Format("2006-01-02")
  6959. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6960. //今日的日期减去设置的日期
  6961. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6962. if cha_time >= record_time {
  6963. //查询审核是否允许
  6964. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6965. //申请状态不允许的情况 拒绝修改
  6966. if infor.ApplicationStatus != 1 {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6968. return
  6969. }
  6970. }
  6971. }
  6972. dataBody := make(map[string]interface{}, 0)
  6973. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6974. if err != nil {
  6975. utils.ErrorLog(err.Error())
  6976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6977. return
  6978. }
  6979. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6980. var beforePrepares []*models.DialysisBeforePrepareGoods
  6981. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6982. var cancelbefor []*models.DialysisBeforePrepareGoods
  6983. var outbefor []*models.DialysisBeforePrepareGoods
  6984. //判断是否开启自动出库
  6985. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6986. if record.IsOpen == 1 {
  6987. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6988. goods, _ := dataBody["goods"].([]interface{})
  6989. if len(goods) > 0 {
  6990. for _, item := range goods {
  6991. items := item.(map[string]interface{})
  6992. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6993. utils.ErrorLog("good_id")
  6994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6995. return
  6996. }
  6997. good_id := int64(items["good_id"].(float64))
  6998. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6999. utils.ErrorLog("good_type_id")
  7000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7001. return
  7002. }
  7003. good_type_id := int64(items["good_type_id"].(float64))
  7004. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7005. utils.ErrorLog("count")
  7006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7007. return
  7008. }
  7009. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7010. commdity_code := items["commdity_code"].(string)
  7011. fmt.Println(commdity_code)
  7012. prepareGoods := &models.DialysisBeforePrepareGoods{
  7013. GoodTypeId: good_type_id,
  7014. GoodId: good_id,
  7015. Count: count,
  7016. StorehouseId: houseConfig.StorehouseOutInfo,
  7017. }
  7018. beforePrepares = append(beforePrepares, prepareGoods)
  7019. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7020. GoodTypeId: good_type_id,
  7021. GoodId: good_id,
  7022. Count: count,
  7023. StorehouseId: houseConfig.StorehouseOutInfo,
  7024. }
  7025. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7026. }
  7027. for _, item := range beforePrepares {
  7028. //1.查看该患者该耗材型号最后一次出库数量
  7029. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7030. //判断当前出库数量和最后一次出库数量的大小
  7031. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7032. if item.Count < goodInfo.Count {
  7033. cancelbefor = append(cancelbefor, item)
  7034. }
  7035. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7036. if item.Count > goodInfo.Count {
  7037. outbefor = append(outbefor, item)
  7038. }
  7039. //处理编辑耗材新增不了的问题
  7040. if goodInfo.Count == item.Count {
  7041. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7042. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7043. }
  7044. }
  7045. if len(cancelbefor) > 0 {
  7046. //退库
  7047. for _, item := range cancelbefor {
  7048. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7049. creater := adminInfo.AdminUser.Id
  7050. //查询该患者当天已经出库的耗材信息
  7051. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7052. var delete_count int64 = 0
  7053. delete_count = warehouseOutInfos.Count - item.Count
  7054. //增加库存数量
  7055. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7056. //减少实际出库库存数量
  7057. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7058. // 删除出库完成后,要增加对应批次的库存数量
  7059. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7060. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7061. //更新剩余库存
  7062. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7063. var flush_count int64
  7064. for _, it := range goodListOne {
  7065. flush_count += it.StockCount
  7066. }
  7067. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7068. //查询剩余库存
  7069. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7070. var sum_count int64
  7071. for _, item := range goodList {
  7072. sum_count += item.StockCount
  7073. }
  7074. // 在出库记录表里记录退库详情
  7075. warehouseOutInfo := &models.WarehouseOutInfo{
  7076. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7077. WarehouseOutId: warehouseOut.ID,
  7078. Status: 1,
  7079. Ctime: time.Now().Unix(),
  7080. OrgId: adminInfo.Org.Id,
  7081. Type: 1,
  7082. IsSys: 1,
  7083. SysRecordTime: record_time,
  7084. GoodTypeId: item.GoodTypeId,
  7085. GoodId: item.GoodId,
  7086. PatientId: patient_id,
  7087. ConsumableType: 2,
  7088. StorehouseId: houseConfig.StorehouseOutInfo,
  7089. IsCheck: 1,
  7090. OverCount: sum_count,
  7091. }
  7092. warehouseOutInfo.Count = item.Count
  7093. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7094. warehouseOutInfo.Price = stockInInfo.Price
  7095. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7096. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7097. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7098. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7099. warehouseOutInfo.Number = warehouseOutInfos.Number
  7100. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7101. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7102. //查找当天是否存在出库记录
  7103. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7104. if errcod == gorm.ErrRecordNotFound {
  7105. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7106. //插入详情明细表
  7107. stockFlow := models.VmStockFlow{
  7108. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7109. WarehouseOutId: warehouseOut.ID,
  7110. GoodId: item.GoodId,
  7111. Number: warehouseOutInfos.Number,
  7112. ProductDate: stockInInfo.ProductDate,
  7113. ExpireDate: stockInInfo.ExpiryDate,
  7114. Count: item.Count,
  7115. Price: stockInInfo.Price,
  7116. Status: 1,
  7117. Ctime: record_time,
  7118. UserOrgId: adminInfo.Org.Id,
  7119. Manufacturer: stockInInfo.Manufacturer,
  7120. Dealer: stockInInfo.Dealer,
  7121. LicenseNumber: stockInInfo.LicenseNumber,
  7122. IsEdit: 2,
  7123. Creator: creater,
  7124. SystemTime: record_time,
  7125. ConsumableType: 3,
  7126. WarehousingDetailId: 0,
  7127. IsSys: 1,
  7128. UpdateCreator: creater,
  7129. PatientId: patient_id,
  7130. StorehouseId: houseConfig.StorehouseOutInfo,
  7131. }
  7132. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7133. if errflow == gorm.ErrRecordNotFound {
  7134. //创建流水表
  7135. err := service.CreateStockFlowOne(stockFlow)
  7136. fmt.Println("err", err)
  7137. } else if errflow == nil {
  7138. //插入详情明细表
  7139. stockFlow := models.VmStockFlow{
  7140. ID: exsit.ID,
  7141. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7142. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7143. WarehouseOutId: warehouseOut.ID,
  7144. GoodId: item.GoodId,
  7145. Number: warehouseOutInfos.Number,
  7146. ProductDate: stockInInfo.ProductDate,
  7147. ExpireDate: stockInInfo.ExpiryDate,
  7148. Count: exsit.Count - delete_count,
  7149. Price: stockInInfo.Price,
  7150. Status: 1,
  7151. Ctime: record_time,
  7152. UserOrgId: adminInfo.Org.Id,
  7153. Manufacturer: stockInInfo.Manufacturer,
  7154. Dealer: stockInInfo.Dealer,
  7155. LicenseNumber: stockInInfo.LicenseNumber,
  7156. IsEdit: 2,
  7157. Creator: creater,
  7158. SystemTime: record_time,
  7159. ConsumableType: 3,
  7160. WarehousingDetailId: 0,
  7161. IsSys: 1,
  7162. UpdateCreator: creater,
  7163. PatientId: patient_id,
  7164. StorehouseId: houseConfig.StorehouseOutInfo,
  7165. }
  7166. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7167. }
  7168. } else if errcod == nil {
  7169. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7170. //查询剩余库存
  7171. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7172. var sum_count int64
  7173. for _, item := range goodList {
  7174. sum_count += item.StockCount
  7175. }
  7176. //创建退库单,生成退库数据
  7177. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7178. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7179. operation_time := time.Now().Unix()
  7180. creater := adminInfo.AdminUser.Id
  7181. //创建退库单
  7182. timeStr := time.Now().Format("2006-01-02")
  7183. timeArr := strings.Split(timeStr, "-")
  7184. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7185. total = total + 1
  7186. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7187. cancelStock := models.CancelStock{
  7188. OrderNumber: orderNumber,
  7189. OperaTime: operation_time,
  7190. OrgId: adminInfo.Org.Id,
  7191. Creater: creater,
  7192. Ctime: time.Now().Unix(),
  7193. Status: 1,
  7194. ReturnTime: record_time,
  7195. Type: 1,
  7196. StorehouseId: houseConfig.StorehouseOutInfo,
  7197. IsCheck: 1,
  7198. }
  7199. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7200. if msgerrkonde == gorm.ErrRecordNotFound {
  7201. service.AddSigleCancelStock(&cancelStock)
  7202. }
  7203. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7204. //查询是否有出库
  7205. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7206. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7207. deaerler, _ := service.GetDealerById(info.Dealer)
  7208. if info.ID > 0 {
  7209. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7210. cancelStockInfo := models.CancelStockInfo{
  7211. GoodId: item.GoodId,
  7212. CancelStockId: cancel.ID,
  7213. GoodTypeId: good.GoodTypeId,
  7214. Count: delete_count,
  7215. Price: info.Price,
  7216. Total: 0,
  7217. ProductDate: info.ProductDate,
  7218. ExpiryDate: info.ExpiryDate,
  7219. Ctime: time.Now().Unix(),
  7220. Status: 1,
  7221. OrgId: adminInfo.Org.Id,
  7222. OrderNumber: cancel.OrderNumber,
  7223. Type: 0,
  7224. Dealer: deaerler.DealerName,
  7225. Manufacturer: manufacturer.ManufacturerName,
  7226. Number: info.Number,
  7227. RegisterAccount: "",
  7228. Remark: "",
  7229. WarehouseInfoId: info.WarehouseInfotId,
  7230. PatientId: info.PatientId,
  7231. RecordDate: info.SysRecordTime,
  7232. StorehouseId: houseConfig.StorehouseOutInfo,
  7233. IsCheck: 1,
  7234. }
  7235. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7236. //退库数量增加
  7237. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7238. //查询剩余库存
  7239. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7240. var over_count int64
  7241. for _, it := range goodList {
  7242. over_count += it.StockCount
  7243. }
  7244. flow := models.VmStockFlow{
  7245. WarehousingId: info.WarehouseInfotId,
  7246. GoodId: item.GoodId,
  7247. Number: info.Number,
  7248. LicenseNumber: info.LicenseNumber,
  7249. Count: delete_count,
  7250. UserOrgId: adminInfo.Org.Id,
  7251. PatientId: patient_id,
  7252. SystemTime: info.SysRecordTime,
  7253. ConsumableType: 7,
  7254. IsSys: 0,
  7255. WarehousingOrder: "",
  7256. WarehouseOutId: info.WarehouseOutId,
  7257. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7258. IsEdit: 0,
  7259. CancelStockId: cancel.ID,
  7260. CancelOrderNumber: cancel.OrderNumber,
  7261. Manufacturer: manufacturer.ID,
  7262. Dealer: 0,
  7263. Creator: adminInfo.AdminUser.Id,
  7264. UpdateCreator: 0,
  7265. Status: 1,
  7266. Ctime: record_time,
  7267. Mtime: 0,
  7268. Price: info.Price,
  7269. WarehousingDetailId: info.WarehouseInfotId,
  7270. WarehouseOutDetailId: info.ID,
  7271. CancelOutDetailId: cancelInfo.ID,
  7272. ProductDate: info.ProductDate,
  7273. ExpireDate: info.ExpiryDate,
  7274. StorehouseId: houseConfig.StorehouseOutInfo,
  7275. OverCount: over_count,
  7276. }
  7277. service.CreateStockFlowOne(flow)
  7278. }
  7279. }
  7280. //更改自动出库的表格
  7281. details := models.BloodAutomaticReduceDetail{
  7282. WarehouseOutId: warehouseOutInfo.ID,
  7283. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7284. PatientId: patient_id,
  7285. Ctime: time.Now().Unix(),
  7286. Mtime: time.Now().Unix(),
  7287. Status: 1,
  7288. RecordTime: record_time,
  7289. OrgId: adminInfo.Org.Id,
  7290. GoodId: item.GoodId,
  7291. GoodTypeId: item.GoodTypeId,
  7292. Count: item.Count,
  7293. StorehouseId: houseConfig.StorehouseOutInfo,
  7294. }
  7295. //查询当天耗材是否已经存在数据
  7296. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7297. if errcode == gorm.ErrRecordNotFound {
  7298. service.CreateAutoReduceRecord(&details)
  7299. } else if errcode == nil {
  7300. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7301. service.CreateAutoReduceRecord(&details)
  7302. }
  7303. //查询默认仓库
  7304. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7305. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7306. var total_count int64
  7307. for _, it := range stockList {
  7308. total_count += it.StockCount
  7309. }
  7310. //基础库插入数据
  7311. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7312. }
  7313. }
  7314. if len(outbefor) > 0 {
  7315. //出库
  7316. for _, item := range outbefor {
  7317. var last_total int64
  7318. //1.查看该患者该耗材型号最后一次出库数量
  7319. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7320. //计算当前出库和最后一次出库数据相差数据
  7321. last_total = item.Count - goodInfoOne.Count
  7322. //查询该耗材的总库存
  7323. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7324. // 如果库存差大于剩余库存则提示库存不足
  7325. if last_total > wareinfo.StockCount {
  7326. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7327. c.ServeSuccessJSON(map[string]interface{}{
  7328. "message": "1",
  7329. "good_name": goodObj.GoodName,
  7330. "specification_name": goodObj.SpecificationName,
  7331. })
  7332. return
  7333. } else {
  7334. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7335. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7336. if err == gorm.ErrRecordNotFound {
  7337. //没有记录,则创建出库单
  7338. timeStr := time.Now().Format("2006-01-02")
  7339. timeArr := strings.Split(timeStr, "-")
  7340. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7341. total = total + 1
  7342. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7343. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7344. number = number + total
  7345. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7346. warehouseOut := models.WarehouseOut{
  7347. WarehouseOutOrderNumber: warehousing_out_order,
  7348. OperationTime: time.Now().Unix(),
  7349. OrgId: adminInfo.Org.Id,
  7350. Creater: adminInfo.AdminUser.Id,
  7351. Ctime: time.Now().Unix(),
  7352. Status: 1,
  7353. WarehouseOutTime: record_time,
  7354. Dealer: 0,
  7355. Manufacturer: 0,
  7356. Type: 1,
  7357. IsSys: 1,
  7358. StorehouseId: houseConfig.StorehouseOutInfo,
  7359. IsCheck: 1,
  7360. }
  7361. service.AddSigleWarehouseOut(&warehouseOut)
  7362. }
  7363. //出库
  7364. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7365. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7366. //1.查看该患者该耗材型号最后一次出库数量
  7367. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7368. prepare := models.DialysisBeforePrepare{
  7369. UserOrgId: adminInfo.Org.Id,
  7370. PatientId: patient_id,
  7371. RecordDate: record_time,
  7372. GoodId: item.GoodId,
  7373. GoodTypeId: item.GoodTypeId,
  7374. Count: item.Count - goodInfoTwo.Count,
  7375. Ctime: time.Now().Unix(),
  7376. Mtime: 0,
  7377. Creater: adminInfo.AdminUser.Id,
  7378. Modifier: adminInfo.AdminUser.Id,
  7379. Status: 1,
  7380. CommdityCode: "",
  7381. NewCount: 0,
  7382. ProjectId: 0,
  7383. StorehouseId: houseConfig.StorehouseOutInfo,
  7384. }
  7385. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7386. //增加出库数量
  7387. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7388. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7389. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7390. var total_count int64
  7391. for _, it := range stockList {
  7392. total_count += it.StockCount
  7393. }
  7394. //基础库插入数据
  7395. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7396. //剩余库存
  7397. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7398. var flush_count int64
  7399. for _, it := range goodList {
  7400. flush_count += it.StockCount
  7401. }
  7402. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7403. }
  7404. }
  7405. }
  7406. //查询今日出库数据
  7407. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7408. for _, it := range list {
  7409. prepare := models.DialysisBeforePrepare{
  7410. UserOrgId: it.OrgId,
  7411. PatientId: patient_id,
  7412. RecordDate: it.RecordTime,
  7413. GoodId: it.GoodId,
  7414. GoodTypeId: it.GoodTypeId,
  7415. Count: it.Count,
  7416. Ctime: time.Now().Unix(),
  7417. Creater: adminInfo.AdminUser.Id,
  7418. Status: 1,
  7419. StorehouseId: houseConfig.StorehouseOutInfo,
  7420. ProjectId: it.ProjectId,
  7421. }
  7422. //删除准备表数据
  7423. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7424. service.CreateDialysisBeforePrepareOne(&prepare)
  7425. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7426. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7427. var total_count int64
  7428. for _, it := range stockList {
  7429. total_count += it.StockCount
  7430. }
  7431. //基础库插入数据
  7432. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7433. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7434. var flush_count int64
  7435. for _, it := range goodList {
  7436. flush_count += it.StockCount
  7437. }
  7438. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7439. }
  7440. }
  7441. }
  7442. //更新自动出库的地方
  7443. var errs error
  7444. if errs == nil {
  7445. c.ServeSuccessJSON(map[string]interface{}{
  7446. "msg": "修改成功",
  7447. "message": "2",
  7448. "good_name": "",
  7449. "specification_name": "",
  7450. })
  7451. return
  7452. } else {
  7453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7454. return
  7455. }
  7456. }
  7457. }
  7458. func (c *DialysisAPIController) GetDialysisGoods() {
  7459. schedualDate := c.GetString("schedule_date")
  7460. schedule_type, _ := c.GetInt64("schedule_type")
  7461. partition_id, _ := c.GetInt64("partition_id")
  7462. page, _ := c.GetInt("page")
  7463. patient_id, _ := c.GetInt64("patient_id")
  7464. schedualEndDate := int64(0)
  7465. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7466. if parseDateErr != nil && len(schedualDate) != 0 {
  7467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7468. return
  7469. }
  7470. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7471. if parseDateErr != nil && len(schedualDate) != 0 {
  7472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7473. return
  7474. }
  7475. schedualEndDate = endDate.Unix()
  7476. adminUser := c.GetMobileAdminUserInfo()
  7477. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7478. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7479. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7480. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7481. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7482. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7483. //获取当天该病人的透析处方
  7484. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7485. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7486. if err == gorm.ErrRecordNotFound {
  7487. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7488. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7489. if patient_id != 0 {
  7490. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7491. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7492. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7493. //获取患者总的出库数据
  7494. item.LastAutomaticReduceDetail = goodUser
  7495. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7496. item.Project = project
  7497. for _, it := range item.AutomaticReduceDetail {
  7498. var total int64
  7499. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7500. for _, its := range auto {
  7501. total += its.Count
  7502. }
  7503. it.Count = total
  7504. }
  7505. }
  7506. }
  7507. c.ServeSuccessJSON(map[string]interface{}{
  7508. "dialysis_goods": dialysisGoods,
  7509. "good_type": goodTypes,
  7510. "total": total,
  7511. "prescribe": prescribe,
  7512. "good_info": good_info,
  7513. "warehouseOutList": warehouseOutList,
  7514. "config": config,
  7515. "outConfig": outConfig,
  7516. "settleConfig": settleConfig,
  7517. })
  7518. return
  7519. } else if err == nil {
  7520. //获取当天排班的每个患者的库存使用情况
  7521. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7522. //获取患者总的出库数据
  7523. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7524. if patient_id != 0 {
  7525. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7526. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7527. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7528. item.Project = project
  7529. item.LastAutomaticReduceDetail = goodUser
  7530. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7531. for _, it := range item.AutomaticReduceDetail {
  7532. var total int64
  7533. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7534. for _, its := range auto {
  7535. total += its.Count
  7536. }
  7537. it.Count = total
  7538. }
  7539. }
  7540. }
  7541. if err == nil {
  7542. c.ServeSuccessJSON(map[string]interface{}{
  7543. "dialysis_goods": dialysisGoods,
  7544. "good_type": goodTypes,
  7545. "total": total,
  7546. "prescribe": prescribe,
  7547. "good_info": good_info,
  7548. "project": project,
  7549. "warehouseOutList": warehouseOutList,
  7550. "config": config,
  7551. "outConfig": outConfig,
  7552. "settleConfig": settleConfig,
  7553. })
  7554. return
  7555. } else {
  7556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7557. return
  7558. }
  7559. } else if err != nil {
  7560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7561. return
  7562. }
  7563. }
  7564. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7565. start_time := c.GetString("start_time")
  7566. end_time := c.GetString("end_time")
  7567. timeLayout := "2006-01-02"
  7568. loc, _ := time.LoadLocation("Local")
  7569. var theStartTime int64
  7570. if len(start_time) > 0 {
  7571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7572. if err != nil {
  7573. utils.ErrorLog(err.Error())
  7574. }
  7575. theStartTime = theTime.Unix()
  7576. }
  7577. var theEndtTime int64
  7578. if len(end_time) > 0 {
  7579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7580. if err != nil {
  7581. utils.ErrorLog(err.Error())
  7582. }
  7583. theEndtTime = theTime.Unix()
  7584. }
  7585. adminUser := c.GetMobileAdminUserInfo()
  7586. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7587. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7588. if err == nil {
  7589. c.ServeSuccessJSON(map[string]interface{}{
  7590. "stock_out": outInfo,
  7591. "stockCount": stockCount,
  7592. })
  7593. return
  7594. } else {
  7595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7596. return
  7597. }
  7598. }
  7599. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7600. patient_id, _ := c.GetInt64("patient_id", 0)
  7601. record_time := c.GetString("record_time")
  7602. adminUser := c.GetMobileAdminUserInfo()
  7603. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7604. if parseDateErr != nil && len(record_time) != 0 {
  7605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7606. return
  7607. }
  7608. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7609. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7610. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7611. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7612. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7613. //获取今日患者的透析处方参数
  7614. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7615. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7616. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7617. c.ServeSuccessJSON(map[string]interface{}{
  7618. "good_type": goodTypes,
  7619. "good_user": goodUser,
  7620. "good_info": good_info,
  7621. "last_good_user": lastGoodUserDetial,
  7622. "project": project,
  7623. "prescription": prescribe,
  7624. "outInfo": outInfo,
  7625. "configs": configs,
  7626. })
  7627. return
  7628. }
  7629. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7630. patient_id, _ := c.GetInt64("patient_id", 0)
  7631. record_date := c.GetString("record_time")
  7632. timeLayout := "2006-01-02"
  7633. loc, _ := time.LoadLocation("Local")
  7634. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7635. record_time := theRecordTime.Unix()
  7636. adminInfo := c.GetMobileAdminUserInfo()
  7637. dataBody := make(map[string]interface{}, 0)
  7638. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7639. if err != nil {
  7640. utils.ErrorLog(err.Error())
  7641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7642. return
  7643. }
  7644. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7645. var beforePrepares []*models.DialysisBeforePrepareGoods
  7646. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7647. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7648. goods, _ := dataBody["goods"].([]interface{})
  7649. if len(goods) > 0 {
  7650. for _, item := range goods {
  7651. items := item.(map[string]interface{})
  7652. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7653. utils.ErrorLog("good_id")
  7654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7655. return
  7656. }
  7657. good_id := int64(items["good_id"].(float64))
  7658. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7659. utils.ErrorLog("good_type_id")
  7660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7661. return
  7662. }
  7663. good_type_id := int64(items["good_type_id"].(float64))
  7664. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7665. utils.ErrorLog("count")
  7666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7667. return
  7668. }
  7669. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7670. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7671. utils.ErrorLog("project_id")
  7672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7673. return
  7674. }
  7675. project_id := int64(items["project_id"].(float64))
  7676. new_count := int64(items["new_count"].(float64))
  7677. old_count := int64(items["old_count"].(float64))
  7678. prepare := &models.DialysisBeforePrepareGoods{
  7679. GoodId: good_id,
  7680. GoodTypeId: good_type_id,
  7681. Count: count,
  7682. ProjectId: project_id,
  7683. StorehouseId: houseConfig.StorehouseOutInfo,
  7684. NewCount: new_count,
  7685. OldCount: old_count,
  7686. }
  7687. beforePrepares = append(beforePrepares, prepare)
  7688. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7689. GoodId: good_id,
  7690. GoodTypeId: good_type_id,
  7691. Count: count,
  7692. ProjectId: project_id,
  7693. StorehouseId: houseConfig.StorehouseOutInfo,
  7694. NewCount: new_count,
  7695. OldCount: old_count,
  7696. }
  7697. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7698. }
  7699. }
  7700. }
  7701. //查询是否有库存
  7702. for _, item := range beforePrepares {
  7703. if item.NewCount > 0 {
  7704. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7705. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7706. if item.Count > warehouse.Count {
  7707. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7708. c.ServeSuccessJSON(map[string]interface{}{
  7709. "message": "1",
  7710. "good_name": goodObj.GoodName,
  7711. "specification_name": goodObj.SpecificationName,
  7712. })
  7713. return
  7714. }
  7715. }
  7716. }
  7717. // 查询信息规挡的设置天数
  7718. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7719. if infor.ID > 0 && infor.WeekDay > 0 {
  7720. var cha_time int64
  7721. timeNowStr := time.Now().Format("2006-01-02")
  7722. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7723. //今日的日期减去设置的日期
  7724. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7725. if cha_time >= record_time {
  7726. //查询审核是否允许
  7727. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7728. //申请状态不允许的情况 拒绝修改
  7729. if infor.ApplicationStatus != 1 {
  7730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7731. return
  7732. }
  7733. }
  7734. }
  7735. //出库逻辑
  7736. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7737. if err != nil {
  7738. utils.ErrorLog(err.Error())
  7739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7740. return
  7741. }
  7742. finish := models.XtDialysisFinish{
  7743. IsFinish: 1,
  7744. UserOrgId: adminInfo.Org.Id,
  7745. Status: 1,
  7746. Ctime: time.Now().Unix(),
  7747. Mtime: 0,
  7748. Module: 11,
  7749. RecordDate: record_time,
  7750. Sourse: 1,
  7751. PatientId: patient_id,
  7752. }
  7753. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7754. if dialysisFinish.ID == 0 {
  7755. service.CreateDialysisFinish(finish)
  7756. }
  7757. //查询当天出库的数据
  7758. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7759. for _, item := range list {
  7760. prepare := models.DialysisBeforePrepare{
  7761. UserOrgId: item.OrgId,
  7762. PatientId: item.PatientId,
  7763. RecordDate: item.RecordTime,
  7764. GoodId: item.GoodId,
  7765. GoodTypeId: item.GoodTypeId,
  7766. Count: item.Count,
  7767. Creater: adminInfo.AdminUser.Id,
  7768. Status: 1,
  7769. Ctime: time.Now().Unix(),
  7770. ProjectId: item.ProjectId,
  7771. StorehouseId: houseConfig.StorehouseOutInfo,
  7772. }
  7773. //清空准备表的数据
  7774. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7775. //插入准备表数据
  7776. service.CreateDialysisBeforePrepareOne(&prepare)
  7777. //查询默认仓库
  7778. //查询默认仓库
  7779. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7780. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7781. var total_count int64
  7782. for _, it := range stockList {
  7783. total_count += it.StockCount
  7784. }
  7785. //基础库插入数据
  7786. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7787. ////更新剩余库存
  7788. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7789. var flush_count int64
  7790. for _, it := range goodList {
  7791. flush_count += it.StockCount
  7792. }
  7793. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7794. if errs != nil {
  7795. goodErrcode := models.XtGoodErrcode{
  7796. UserOrgId: item.OrgId,
  7797. Errcode: "手动出库更新剩余出库失败",
  7798. GoodId: item.GoodId,
  7799. Status: 1,
  7800. Ctime: time.Now().Unix(),
  7801. Mtime: 0,
  7802. Count: 0,
  7803. StockCount: 0,
  7804. Creater: adminInfo.AdminUser.Id,
  7805. BatchNumberId: 0,
  7806. WarehouseOutId: 0,
  7807. }
  7808. service.CreateGoodErrcode(goodErrcode)
  7809. }
  7810. }
  7811. //更新自动出库的地方
  7812. var errs error
  7813. if errs == nil {
  7814. c.ServeSuccessJSON(map[string]interface{}{
  7815. "msg": "修改成功",
  7816. "message": "2",
  7817. "good_name": "",
  7818. "specification_name": "",
  7819. })
  7820. return
  7821. } else {
  7822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7823. return
  7824. }
  7825. }
  7826. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7827. newArr = make([]*models.DialysisBeforePrepare, 0)
  7828. for i := 0; i < len(arr); i++ {
  7829. repeat := false
  7830. for j := i + 1; j < len(arr); j++ {
  7831. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7832. repeat = true
  7833. break
  7834. }
  7835. }
  7836. if !repeat {
  7837. newArr = append(newArr, arr[i])
  7838. }
  7839. }
  7840. return
  7841. }
  7842. func (c *DialysisAPIController) GetAllDrug() {
  7843. patient_id, _ := c.GetInt64("patient_id", 0)
  7844. adminInfo := c.GetMobileAdminUserInfo()
  7845. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7846. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7847. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7848. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7849. c.ServeSuccessJSON(map[string]interface{}{
  7850. "base_drug_config": drugStockConfig,
  7851. "private_drug_config": privateDrugConfig,
  7852. "base_drug_list": drugList,
  7853. "private_drug_list": privateDrugList,
  7854. })
  7855. }
  7856. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7857. newArr = make([]*models.DialysisBeforePrepare, 0)
  7858. for i := 0; i < len(arr); i++ {
  7859. repeat := false
  7860. for j := i + 1; j < len(arr); j++ {
  7861. if arr[i].GoodId == arr[j].GoodId {
  7862. repeat = true
  7863. break
  7864. }
  7865. }
  7866. if !repeat {
  7867. newArr = append(newArr, arr[i])
  7868. }
  7869. }
  7870. return
  7871. }
  7872. func (c *DialysisAPIController) GetDepartment() {
  7873. adminInfo := c.GetMobileAdminUserInfo()
  7874. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7875. if err == nil {
  7876. c.ServeSuccessJSON(map[string]interface{}{
  7877. "departments": departments,
  7878. })
  7879. } else {
  7880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7881. return
  7882. }
  7883. }
  7884. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7885. types, _ := c.GetInt("type", 0)
  7886. start_time := c.GetString("start_time")
  7887. end_time := c.GetString("end_time")
  7888. orgId := c.GetMobileAdminUserInfo().Org.Id
  7889. timeLayout := "2006-01-02"
  7890. loc, _ := time.LoadLocation("Local")
  7891. var startTime int64
  7892. if len(start_time) > 0 {
  7893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7894. if err != nil {
  7895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7896. return
  7897. }
  7898. startTime = theTime.Unix()
  7899. }
  7900. var endTime int64
  7901. if len(end_time) > 0 {
  7902. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7903. if err != nil {
  7904. utils.ErrorLog(err.Error())
  7905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7906. return
  7907. }
  7908. endTime = theTime.Unix()
  7909. }
  7910. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7911. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7912. if err != nil {
  7913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7914. } else {
  7915. c.ServeSuccessJSON(map[string]interface{}{
  7916. "list": list,
  7917. "type": types,
  7918. "stockTotal": stockTotal,
  7919. })
  7920. }
  7921. }
  7922. func (c *DialysisAPIController) GetPrescriptionList() {
  7923. start_time := c.GetString("start_time")
  7924. end_time := c.GetString("end_time")
  7925. schedule_type, _ := c.GetInt64("schedule_type")
  7926. partion_id, _ := c.GetInt64("partion_id")
  7927. orgId := c.GetMobileAdminUserInfo().Org.Id
  7928. timeLayout := "2006-01-02"
  7929. loc, _ := time.LoadLocation("Local")
  7930. var startTime int64
  7931. if len(start_time) > 0 {
  7932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7933. if err != nil {
  7934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7935. return
  7936. }
  7937. startTime = theTime.Unix()
  7938. }
  7939. var endTime int64
  7940. if len(end_time) > 0 {
  7941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7942. if err != nil {
  7943. utils.ErrorLog(err.Error())
  7944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7945. return
  7946. }
  7947. endTime = theTime.Unix()
  7948. }
  7949. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7950. fmt.Println("schedulelist22222222", schedulelist)
  7951. c.ServeSuccessJSON(map[string]interface{}{
  7952. "list": schedulelist,
  7953. })
  7954. return
  7955. }
  7956. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7957. ids := c.GetString("ids")
  7958. //patient_id, _ := c.GetInt64("patient_id")
  7959. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7960. idArray := strings.Split(ids, ",")
  7961. err := service.BatchDeleteMonitor(idArray)
  7962. fmt.Print("err", err)
  7963. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7964. //redis := service.RedisClient()
  7965. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7966. //redis.Set(key, "", time.Second)
  7967. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7968. //redis.Set(keyOne, "", time.Second)
  7969. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7970. //redis.Close()
  7971. c.ServeSuccessJSON(map[string]interface{}{
  7972. "msg": "批量删除成功",
  7973. })
  7974. return
  7975. }
  7976. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7977. id, _ := c.GetInt64("id")
  7978. timeLayout := "2006-01-02"
  7979. loc, _ := time.LoadLocation("Local")
  7980. //start_time := time.Now().Format("2006-01-02")
  7981. start_time := c.GetString("start_time")
  7982. end_time := c.GetString("end_time")
  7983. var startdateunix int64
  7984. if len(start_time) > 0 {
  7985. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7986. if err != nil {
  7987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7988. return
  7989. }
  7990. startdateunix = theTime.Unix()
  7991. }
  7992. var enddateunix int64
  7993. if len(end_time) > 0 {
  7994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7995. if err != nil {
  7996. utils.ErrorLog(err.Error())
  7997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7998. return
  7999. }
  8000. enddateunix = theTime.Unix()
  8001. }
  8002. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8003. //nowTime := time.Now()
  8004. //endTime := nowTime.AddDate(-30, 0, 0)
  8005. //endTimes := endTime.Format("2006-01-02")
  8006. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8007. org_id := c.GetMobileAdminUserInfo().Org.Id
  8008. //if org_id == 10579 {
  8009. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8010. // c.ServeSuccessJSON(map[string]interface{}{
  8011. // "list": list,
  8012. // })
  8013. // return
  8014. //} else {
  8015. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8016. // c.ServeSuccessJSON(map[string]interface{}{
  8017. // "list": list,
  8018. // })
  8019. // return
  8020. //}
  8021. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8022. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8023. c.ServeSuccessJSON(map[string]interface{}{
  8024. "list": list,
  8025. })
  8026. return
  8027. } else {
  8028. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8029. c.ServeSuccessJSON(map[string]interface{}{
  8030. "list": list,
  8031. })
  8032. }
  8033. return
  8034. }
  8035. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8036. dataBody := make(map[string]interface{}, 0)
  8037. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8038. ids := c.GetString("ids")
  8039. idArray := strings.Split(ids, ",")
  8040. origin, _ := c.GetInt64("origin")
  8041. if origin == 1 {
  8042. err = service.BatchDeleteAdvice(idArray)
  8043. fmt.Print("err", err)
  8044. c.ServeSuccessJSON(map[string]interface{}{
  8045. "msg": "批量删除成功",
  8046. })
  8047. return
  8048. }
  8049. if origin == 2 {
  8050. service.BatchDeleteHisAdvice(idArray)
  8051. }
  8052. }
  8053. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8054. good_id, _ := c.GetInt64("good_id")
  8055. count, _ := c.GetInt64("count")
  8056. record_time, _ := c.GetInt64("record_time")
  8057. patient_id, _ := c.GetInt64("patient_id")
  8058. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8059. c.ServeSuccessJSON(map[string]interface{}{
  8060. "detail": detail,
  8061. })
  8062. return
  8063. }
  8064. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8065. good_id, _ := c.GetInt64("good_id")
  8066. record_time, _ := c.GetInt64("record_time")
  8067. patient_id, _ := c.GetInt64("patient_id")
  8068. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8069. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8070. fmt.Print("err", err)
  8071. c.ServeSuccessJSON(map[string]interface{}{
  8072. "msg": "批量删除成功",
  8073. })
  8074. return
  8075. }
  8076. func (c *DialysisAPIController) BatchAdviceCheck() {
  8077. ids := c.GetString("ids")
  8078. idArray := strings.Split(ids, ",")
  8079. creator, _ := c.GetInt64("creator")
  8080. origin, _ := c.GetInt64("origin")
  8081. if origin == 1 {
  8082. err := service.BatchAdviceCheck(idArray, creator)
  8083. fmt.Println(err)
  8084. list, _ := service.GetAdviceExecutionById(idArray)
  8085. c.ServeSuccessJSON(map[string]interface{}{
  8086. "list": list,
  8087. })
  8088. return
  8089. }
  8090. if origin == 2 {
  8091. service.BatchHisAdviceCheck(idArray, creator)
  8092. list, _ := service.GetHisAdviceExecutionById(idArray)
  8093. c.ServeSuccessJSON(map[string]interface{}{
  8094. "list": list,
  8095. })
  8096. return
  8097. }
  8098. }
  8099. func (c *DialysisAPIController) BatchAdviceExecution() {
  8100. ids := c.GetString("ids")
  8101. idArray := strings.Split(ids, ",")
  8102. executionTime := c.GetString("execution_time")
  8103. creator, _ := c.GetInt64("creator")
  8104. timeLayout := "2006-01-02 15:04:05"
  8105. loc, _ := time.LoadLocation("Local")
  8106. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8107. orgin, _ := c.GetInt64("origin")
  8108. if orgin == 1 {
  8109. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8110. list, _ := service.GetAdviceExecutionById(idArray)
  8111. fmt.Println(err)
  8112. c.ServeSuccessJSON(map[string]interface{}{
  8113. "list": list,
  8114. })
  8115. return
  8116. }
  8117. if orgin == 2 {
  8118. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8119. list, _ := service.GetHisAdviceExecutionById(idArray)
  8120. fmt.Println(err)
  8121. c.ServeSuccessJSON(map[string]interface{}{
  8122. "list": list,
  8123. })
  8124. return
  8125. }
  8126. }
  8127. func (c *DialysisAPIController) UpdateStockGoods() {
  8128. good_id, _ := c.GetInt64("good_id")
  8129. record_time, _ := c.GetInt64("record_time")
  8130. patient_id, _ := c.GetInt64("patient_id")
  8131. count, _ := c.GetInt64("count")
  8132. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8133. fmt.Print("err", err)
  8134. c.ServeSuccessJSON(map[string]interface{}{
  8135. "msg": "更新成功",
  8136. })
  8137. return
  8138. }
  8139. // 当前数据比上一次出库数据少
  8140. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8141. //查询该患者当天已经出库的耗材信息
  8142. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8143. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8144. for i := len(goods_yc) - 1; i >= 0; i-- {
  8145. goods_yc_temp := goods_yc[i]
  8146. for j := len(goods) - 1; j >= 0; j-- {
  8147. goods_temp := goods[j]
  8148. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8149. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8150. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8151. if goods_yc_temp.Count == goods_temp.Count {
  8152. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8153. goods = append(goods[:j], goods[j+1:]...)
  8154. break
  8155. }
  8156. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8157. if goods_yc_temp.Count > goods_temp.Count {
  8158. temp_count := goods_yc_temp.Count - goods_temp.Count
  8159. goods_yc[i].Count = temp_count
  8160. goods = append(goods[:j], goods[j+1:]...)
  8161. break
  8162. }
  8163. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8164. if goods_yc_temp.Count < goods_temp.Count {
  8165. temp_count := goods_temp.Count - goods_yc_temp.Count
  8166. goods[j].Count = temp_count
  8167. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8168. break
  8169. }
  8170. }
  8171. }
  8172. }
  8173. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8174. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8175. //退库
  8176. if len(goods_yc) > 0 {
  8177. for _, good_yc := range goods_yc {
  8178. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8179. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8180. }
  8181. }
  8182. return nil
  8183. }
  8184. // 耗材出库删除
  8185. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8186. // 先根据相关信息查询当天该耗材的出库信息
  8187. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8188. if err != nil {
  8189. return err
  8190. }
  8191. var delete_count int64 = 0
  8192. delete_count = warehouseOutInfos.Count - count
  8193. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8194. // 在出库记录表里记录退库详情
  8195. warehouseOutInfo := &models.WarehouseOutInfo{
  8196. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8197. WarehouseOutId: warehouseOut.ID,
  8198. Status: 1,
  8199. Ctime: time.Now().Unix(),
  8200. OrgId: orgID,
  8201. Type: 1,
  8202. IsSys: 1,
  8203. SysRecordTime: record_time,
  8204. GoodTypeId: good_yc.GoodTypeId,
  8205. GoodId: good_yc.GoodId,
  8206. PatientId: good_yc.PatientId,
  8207. ConsumableType: 2,
  8208. StorehouseId: houseConfig.StorehouseOutInfo,
  8209. IsCheck: 1,
  8210. }
  8211. warehouseOutInfo.Count = count
  8212. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8213. warehouseOutInfo.Price = stockInInfo.Price
  8214. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8215. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8216. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8217. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8218. warehouseOutInfo.Number = warehouseOutInfos.Number
  8219. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8220. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8221. //查找当天是否存在出库记录
  8222. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8223. if errcod == gorm.ErrRecordNotFound {
  8224. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8225. //插入详情明细表
  8226. stockFlow := models.VmStockFlow{
  8227. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8228. WarehouseOutId: warehouseOut.ID,
  8229. GoodId: good_yc.GoodId,
  8230. Number: warehouseOutInfos.Number,
  8231. ProductDate: stockInInfo.ProductDate,
  8232. ExpireDate: stockInInfo.ExpiryDate,
  8233. Count: count,
  8234. Price: stockInInfo.Price,
  8235. Status: 1,
  8236. Ctime: time.Now().Unix(),
  8237. UserOrgId: good_yc.OrgId,
  8238. Manufacturer: stockInInfo.Manufacturer,
  8239. Dealer: stockInInfo.Dealer,
  8240. LicenseNumber: stockInInfo.LicenseNumber,
  8241. IsEdit: 2,
  8242. Creator: creater,
  8243. SystemTime: record_time,
  8244. ConsumableType: 3,
  8245. WarehousingDetailId: 0,
  8246. IsSys: 1,
  8247. UpdateCreator: creater,
  8248. PatientId: patient_id,
  8249. StorehouseId: houseConfig.StorehouseOutInfo,
  8250. }
  8251. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8252. if errflow == gorm.ErrRecordNotFound {
  8253. //创建流水表
  8254. err := service.CreateStockFlowOne(stockFlow)
  8255. fmt.Println("err", err)
  8256. } else if errflow == nil {
  8257. //插入详情明细表
  8258. stockFlow := models.VmStockFlow{
  8259. ID: exsit.ID,
  8260. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8261. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8262. WarehouseOutId: warehouseOut.ID,
  8263. GoodId: good_yc.GoodId,
  8264. Number: warehouseOutInfos.Number,
  8265. ProductDate: stockInInfo.ProductDate,
  8266. ExpireDate: stockInInfo.ExpiryDate,
  8267. Count: exsit.Count - delete_count,
  8268. Price: stockInInfo.Price,
  8269. Status: 1,
  8270. Ctime: time.Now().Unix(),
  8271. UserOrgId: good_yc.OrgId,
  8272. Manufacturer: stockInInfo.Manufacturer,
  8273. Dealer: stockInInfo.Dealer,
  8274. LicenseNumber: stockInInfo.LicenseNumber,
  8275. IsEdit: 2,
  8276. Creator: creater,
  8277. SystemTime: record_time,
  8278. ConsumableType: 3,
  8279. WarehousingDetailId: 0,
  8280. IsSys: 1,
  8281. UpdateCreator: creater,
  8282. PatientId: patient_id,
  8283. StorehouseId: houseConfig.StorehouseOutInfo,
  8284. }
  8285. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8286. }
  8287. if errOne != nil {
  8288. return errOne
  8289. }
  8290. } else if errcod == nil {
  8291. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8292. //插入详情明细表
  8293. stockFlow := models.VmStockFlow{
  8294. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8295. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8296. WarehouseOutId: warehouseOut.ID,
  8297. GoodId: good_yc.GoodId,
  8298. Number: warehouseOutInfos.Number,
  8299. ProductDate: stockInInfo.ProductDate,
  8300. ExpireDate: stockInInfo.ExpiryDate,
  8301. Count: count,
  8302. Price: stockInInfo.Price,
  8303. Status: 1,
  8304. Ctime: time.Now().Unix(),
  8305. UserOrgId: good_yc.OrgId,
  8306. Manufacturer: stockInInfo.Manufacturer,
  8307. Dealer: stockInInfo.Dealer,
  8308. LicenseNumber: stockInInfo.LicenseNumber,
  8309. IsEdit: 2,
  8310. Creator: creater,
  8311. SystemTime: record_time,
  8312. ConsumableType: 3,
  8313. WarehousingDetailId: 0,
  8314. IsSys: 1,
  8315. UpdateCreator: creater,
  8316. PatientId: patient_id,
  8317. ReturnCount: delete_count,
  8318. StorehouseId: houseConfig.StorehouseOutInfo,
  8319. }
  8320. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8321. if errflows == gorm.ErrRecordNotFound {
  8322. //创建流水表
  8323. service.CreateStockFlowOne(stockFlow)
  8324. } else if errflows == nil {
  8325. stockFlow := models.VmStockFlow{
  8326. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8327. ID: exsit.ID,
  8328. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8329. WarehouseOutId: warehouseOut.ID,
  8330. GoodId: good_yc.GoodId,
  8331. Number: warehouseOutInfos.Number,
  8332. ProductDate: stockInInfo.ProductDate,
  8333. ExpireDate: stockInInfo.ExpiryDate,
  8334. Count: exsit.Count - delete_count,
  8335. Price: stockInInfo.Price,
  8336. Status: 1,
  8337. Ctime: time.Now().Unix(),
  8338. UserOrgId: good_yc.OrgId,
  8339. Manufacturer: stockInInfo.Manufacturer,
  8340. Dealer: stockInInfo.Dealer,
  8341. LicenseNumber: stockInInfo.LicenseNumber,
  8342. IsEdit: 2,
  8343. Creator: creater,
  8344. SystemTime: record_time,
  8345. ConsumableType: 3,
  8346. WarehousingDetailId: 0,
  8347. IsSys: 1,
  8348. UpdateCreator: creater,
  8349. PatientId: patient_id,
  8350. ReturnCount: delete_count,
  8351. StorehouseId: houseConfig.StorehouseOutInfo,
  8352. }
  8353. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8354. }
  8355. }
  8356. //更改自动出库的表格
  8357. details := models.BloodAutomaticReduceDetail{
  8358. WarehouseOutId: warehouseOutInfo.ID,
  8359. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8360. PatientId: patient_id,
  8361. Ctime: time.Now().Unix(),
  8362. Mtime: time.Now().Unix(),
  8363. Status: 1,
  8364. RecordTime: record_time,
  8365. OrgId: orgID,
  8366. GoodId: good_yc.GoodId,
  8367. GoodTypeId: good_yc.GoodTypeId,
  8368. Count: count,
  8369. StorehouseId: houseConfig.StorehouseOutInfo,
  8370. }
  8371. //查询当天耗材是否已经存在数据
  8372. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8373. if errcode == gorm.ErrRecordNotFound {
  8374. errTwo := service.CreateAutoReduceRecord(&details)
  8375. if errTwo != nil {
  8376. return errTwo
  8377. }
  8378. } else if errcode == nil {
  8379. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8380. service.CreateAutoReduceRecord(&details)
  8381. }
  8382. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8383. //增加出库库存数量
  8384. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8385. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8386. fmt.Println("errOne", errOne)
  8387. // 删除出库完成后,要增加对应批次的库存数量
  8388. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8389. if errThree != nil {
  8390. return errThree
  8391. }
  8392. if good_yc.Count == 0 {
  8393. return nil
  8394. } else {
  8395. return errors.New("退库和出库数据不匹配")
  8396. }
  8397. }
  8398. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8399. //查询该患者当天已经出库的耗材信息
  8400. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8401. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8402. for i := len(goods_yc) - 1; i >= 0; i-- {
  8403. goods_yc_temp := goods_yc[i]
  8404. for j := len(goods) - 1; j >= 0; j-- {
  8405. goods_temp := goods[j]
  8406. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8407. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8408. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8409. if goods_yc_temp.Count == goods_temp.Count {
  8410. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8411. goods = append(goods[:j], goods[j+1:]...)
  8412. break
  8413. }
  8414. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8415. if goods_yc_temp.Count > goods_temp.Count {
  8416. temp_count := goods_yc_temp.Count - goods_temp.Count
  8417. goods_yc[i].Count = temp_count
  8418. goods = append(goods[:j], goods[j+1:]...)
  8419. break
  8420. }
  8421. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8422. if goods_yc_temp.Count < goods_temp.Count {
  8423. temp_count := goods_temp.Count - goods_yc_temp.Count
  8424. goods[j].Count = temp_count
  8425. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8426. break
  8427. }
  8428. }
  8429. }
  8430. }
  8431. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8432. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8433. fmt.Println("剩余需要出库的", len(goods))
  8434. if len(goods) > 0 {
  8435. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8436. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8437. if err == gorm.ErrRecordNotFound {
  8438. //没有记录,则创建出库单
  8439. timeStr := time.Now().Format("2006-01-02")
  8440. timeArr := strings.Split(timeStr, "-")
  8441. total, _ := service.FindAllWarehouseOut(orgID)
  8442. total = total + 1
  8443. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8444. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8445. number = number + total
  8446. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8447. warehouseOut := models.WarehouseOut{
  8448. WarehouseOutOrderNumber: warehousing_out_order,
  8449. OperationTime: time.Now().Unix(),
  8450. OrgId: orgID,
  8451. Creater: creater,
  8452. Ctime: time.Now().Unix(),
  8453. Status: 1,
  8454. WarehouseOutTime: record_time,
  8455. Dealer: 0,
  8456. Manufacturer: 0,
  8457. Type: 1,
  8458. IsSys: 1,
  8459. StorehouseId: houseConfig.StorehouseOutInfo,
  8460. IsCheck: 1,
  8461. }
  8462. err := service.AddSigleWarehouseOut(&warehouseOut)
  8463. if err != nil {
  8464. utils.TraceLog("创建出库单失败 err = %v", err)
  8465. return err
  8466. } else {
  8467. out = warehouseOut
  8468. }
  8469. }
  8470. for _, item := range goods {
  8471. var newCount int64 = 0
  8472. for _, it := range goodOne {
  8473. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8474. newCount = it.Count
  8475. }
  8476. }
  8477. prepare := models.DialysisBeforePrepare{
  8478. GoodTypeId: item.GoodTypeId,
  8479. GoodId: item.GoodId,
  8480. Count: item.Count,
  8481. StorehouseId: houseConfig.StorehouseOutInfo,
  8482. }
  8483. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8484. //增加出库数量
  8485. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8486. }
  8487. }
  8488. if len(goods_yc) > 0 {
  8489. for _, good_yc := range goods_yc {
  8490. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8491. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8492. }
  8493. }
  8494. return nil
  8495. }
  8496. // 耗材出库删除
  8497. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8498. // 先根据相关信息查询当天该耗材的出库信息
  8499. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8500. if err != nil {
  8501. return err
  8502. }
  8503. var delete_count int64 = 0
  8504. for _, ware := range warehouseOutInfos {
  8505. // 判断当前出库的数据和删除出库数量
  8506. if good_yc.Count <= ware.Count {
  8507. delete_count = good_yc.Count
  8508. } else {
  8509. delete_count = ware.Count
  8510. }
  8511. warehouseOutInfo := &models.WarehouseOutInfo{
  8512. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8513. WarehouseOutId: warehouseOut.ID,
  8514. Status: 1,
  8515. Ctime: time.Now().Unix(),
  8516. Remark: "",
  8517. OrgId: orgID,
  8518. Type: 1,
  8519. Manufacturer: 0,
  8520. Dealer: 0,
  8521. IsSys: 0,
  8522. SysRecordTime: record_time,
  8523. GoodTypeId: good_yc.GoodTypeId,
  8524. GoodId: good_yc.GoodId,
  8525. StorehouseId: warehouseOut.StorehouseId,
  8526. IsCheck: 1,
  8527. }
  8528. warehouseOutInfo.Count = delete_count
  8529. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8530. warehouseOutInfo.Price = stockInInfo.Price
  8531. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8532. if errOne != nil {
  8533. return errOne
  8534. }
  8535. // 删除出库完成后,要改变流水库存(有疑问)
  8536. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8537. fmt.Println("errOne", errOne)
  8538. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8539. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8540. //扣减出库数量
  8541. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8542. if errThree != nil {
  8543. return errThree
  8544. }
  8545. }
  8546. if good_yc.Count == 0 {
  8547. return nil
  8548. } else {
  8549. return errors.New("退库和出库数据不匹配")
  8550. }
  8551. }
  8552. func (this *DialysisAPIController) GetMobileScheduleList() {
  8553. limit, _ := this.GetInt64("limit")
  8554. page, _ := this.GetInt64("page")
  8555. type_options_visible, _ := this.GetInt64("type_options_visible")
  8556. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8557. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8558. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8559. }
  8560. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8561. newArr = make([]*models.HisPrescriptionProject, 0)
  8562. for i := 0; i < len(arr); i++ {
  8563. repeat := false
  8564. for j := i + 1; j < len(arr); j++ {
  8565. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8566. repeat = true
  8567. break
  8568. }
  8569. }
  8570. if !repeat {
  8571. newArr = append(newArr, arr[i])
  8572. }
  8573. }
  8574. return
  8575. }
  8576. func (this *DialysisAPIController) GetRoleList() {
  8577. admin_user_id, _ := this.GetInt64("admin_user_id")
  8578. orgid := this.GetMobileAdminUserInfo().Org.Id
  8579. list, err := service.GetRoleList(orgid, admin_user_id)
  8580. fmt.Println(err)
  8581. this.ServeSuccessJSON(map[string]interface{}{
  8582. "list": list,
  8583. })
  8584. return
  8585. }
  8586. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8587. // 先根据相关信息查询当天该耗材的出库信息
  8588. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8589. if err != nil {
  8590. return err
  8591. }
  8592. var delete_count int64 = 0
  8593. delete_count = warehouseOutInfos.Count - count
  8594. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8595. // 删除出库完成后,要增加对应批次的库存数量
  8596. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8597. if errThree != nil {
  8598. return errThree
  8599. }
  8600. //增加退库数量
  8601. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8602. //扣减出库数量
  8603. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8604. //查询剩余库存
  8605. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8606. var sum_count int64
  8607. for _, item := range goodList {
  8608. sum_count += item.StockCount
  8609. }
  8610. // 在出库记录表里记录退库详情
  8611. warehouseOutInfo := &models.WarehouseOutInfo{
  8612. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8613. WarehouseOutId: warehouseOut.ID,
  8614. Status: 1,
  8615. Ctime: time.Now().Unix(),
  8616. OrgId: orgID,
  8617. Type: 1,
  8618. IsSys: 1,
  8619. SysRecordTime: record_time,
  8620. GoodTypeId: good_yc.GoodTypeId,
  8621. GoodId: good_yc.GoodId,
  8622. PatientId: good_yc.PatientId,
  8623. ConsumableType: 2,
  8624. StorehouseId: houseConfig.StorehouseOutInfo,
  8625. IsCheck: 1,
  8626. OverCount: sum_count,
  8627. }
  8628. warehouseOutInfo.Count = count
  8629. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8630. warehouseOutInfo.Price = stockInInfo.Price
  8631. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8632. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8633. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8634. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8635. warehouseOutInfo.Number = warehouseOutInfos.Number
  8636. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8637. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8638. //查找当天是否存在出库记录
  8639. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8640. if errcod == gorm.ErrRecordNotFound {
  8641. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8642. //插入详情明细表
  8643. if errOne != nil {
  8644. return errOne
  8645. }
  8646. //插入详情明细表
  8647. stockFlow := models.VmStockFlow{
  8648. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8649. WarehouseOutId: warehouseOut.ID,
  8650. GoodId: good_yc.GoodId,
  8651. Number: warehouseOutInfos.Number,
  8652. ProductDate: stockInInfo.ProductDate,
  8653. ExpireDate: stockInInfo.ExpiryDate,
  8654. Count: count,
  8655. Price: stockInInfo.Price,
  8656. Status: 1,
  8657. Ctime: record_time,
  8658. UserOrgId: good_yc.OrgId,
  8659. Manufacturer: stockInInfo.Manufacturer,
  8660. Dealer: stockInInfo.Dealer,
  8661. LicenseNumber: stockInInfo.LicenseNumber,
  8662. IsEdit: 2,
  8663. Creator: creater,
  8664. SystemTime: record_time,
  8665. ConsumableType: 3,
  8666. WarehousingDetailId: 0,
  8667. IsSys: 1,
  8668. UpdateCreator: creater,
  8669. PatientId: patient_id,
  8670. StorehouseId: houseConfig.StorehouseOutInfo,
  8671. OverCount: sum_count,
  8672. ProjectId: good_yc.ProjectId,
  8673. }
  8674. err := service.CreateStockFlowOne(stockFlow)
  8675. fmt.Println("err", err)
  8676. } else if errcod == nil {
  8677. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8678. }
  8679. //创建退库单
  8680. operation_time := time.Now().Unix()
  8681. //创建退库单
  8682. timeStr := time.Now().Format("2006-01-02")
  8683. timeArr := strings.Split(timeStr, "-")
  8684. total, _ := service.FindAllCancelStockTotal(orgID)
  8685. total = total + 1
  8686. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8687. cancelStock := models.CancelStock{
  8688. OrderNumber: orderNumber,
  8689. OperaTime: operation_time,
  8690. OrgId: orgID,
  8691. Creater: warehouseOut.Creater,
  8692. Ctime: time.Now().Unix(),
  8693. Status: 1,
  8694. ReturnTime: record_time,
  8695. Type: 1,
  8696. StorehouseId: stockInInfo.StorehouseId,
  8697. IsCheck: 1,
  8698. }
  8699. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8700. if msgerrkonde == gorm.ErrRecordNotFound {
  8701. service.AddSigleCancelStock(&cancelStock)
  8702. }
  8703. cancel, _ := service.GetLastCancelStockById(orgID)
  8704. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8705. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8706. cancelStockInfo := models.CancelStockInfo{
  8707. GoodId: stockInInfo.GoodId,
  8708. CancelStockId: cancel.ID,
  8709. GoodTypeId: stockInInfo.GoodTypeId,
  8710. Count: delete_count,
  8711. Price: stockInInfo.PackingPrice,
  8712. Total: 0,
  8713. ProductDate: stockInInfo.ProductDate,
  8714. ExpiryDate: stockInInfo.ExpiryDate,
  8715. Ctime: record_time,
  8716. Status: 1,
  8717. OrgId: orgID,
  8718. OrderNumber: cancel.OrderNumber,
  8719. Type: 0,
  8720. Dealer: deaerler.DealerName,
  8721. Manufacturer: manufacturer.ManufacturerName,
  8722. Number: stockInInfo.Number,
  8723. RegisterAccount: "",
  8724. Remark: "",
  8725. WarehouseInfoId: stockInInfo.ID,
  8726. PatientId: patient_id,
  8727. RecordDate: record_time,
  8728. StorehouseId: stockInInfo.StorehouseId,
  8729. IsCheck: 1,
  8730. }
  8731. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8732. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8733. flow := models.VmStockFlow{
  8734. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8735. GoodId: good_yc.GoodId,
  8736. Number: warehouseOutInfos.Number,
  8737. LicenseNumber: stockInInfo.LicenseNumber,
  8738. Count: delete_count,
  8739. UserOrgId: orgID,
  8740. PatientId: patient_id,
  8741. SystemTime: record_time,
  8742. ConsumableType: 7,
  8743. IsSys: 0,
  8744. WarehousingOrder: "",
  8745. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8746. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8747. IsEdit: 0,
  8748. CancelStockId: cancel.ID,
  8749. CancelOrderNumber: cancel.OrderNumber,
  8750. Manufacturer: manufacturer.ID,
  8751. Dealer: 0,
  8752. Creator: warehouseOut.Creater,
  8753. UpdateCreator: 0,
  8754. Status: 1,
  8755. Ctime: record_time,
  8756. Mtime: 0,
  8757. Price: stockInInfo.Price,
  8758. WarehousingDetailId: stockInInfo.ID,
  8759. WarehouseOutDetailId: warehouseOutInfos.ID,
  8760. CancelOutDetailId: cancelInfo.ID,
  8761. ProductDate: stockInInfo.ProductDate,
  8762. ExpireDate: stockInInfo.ExpiryDate,
  8763. StorehouseId: houseConfig.StorehouseOutInfo,
  8764. OverCount: sum_count,
  8765. }
  8766. service.CreateStockFlowOne(flow)
  8767. //更改自动出库的表格
  8768. details := models.BloodAutomaticReduceDetail{
  8769. WarehouseOutId: warehouseOutInfo.ID,
  8770. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8771. PatientId: patient_id,
  8772. Ctime: time.Now().Unix(),
  8773. Mtime: time.Now().Unix(),
  8774. Status: 1,
  8775. RecordTime: record_time,
  8776. OrgId: orgID,
  8777. GoodId: good_yc.GoodId,
  8778. GoodTypeId: good_yc.GoodTypeId,
  8779. Count: count,
  8780. StorehouseId: houseConfig.StorehouseOutInfo,
  8781. }
  8782. //查询当天耗材是否已经存在数据
  8783. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8784. if errcode == gorm.ErrRecordNotFound {
  8785. errTwo := service.CreateAutoReduceRecord(&details)
  8786. if errTwo != nil {
  8787. return errTwo
  8788. }
  8789. } else if errcode == nil {
  8790. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8791. service.CreateAutoReduceRecord(&details)
  8792. }
  8793. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8794. //增加出库库存数量
  8795. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8796. if good_yc.Count == 0 {
  8797. return nil
  8798. } else {
  8799. return errors.New("退库和出库数据不匹配")
  8800. }
  8801. }
  8802. func (this *DialysisAPIController) SavePatientSign() {
  8803. adminUserInfo := this.GetMobileAdminUserInfo()
  8804. patient_id, _ := this.GetInt64("patient_id")
  8805. dialysis_date, _ := this.GetInt64("dialysis_date")
  8806. orgid := adminUserInfo.Org.Id
  8807. var esdata models.DialysisOrder
  8808. var err error
  8809. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8811. return
  8812. }
  8813. esdata.Hash = esdata.Hash
  8814. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8815. order := models.DialysisOrder{
  8816. Hash: esdata.Hash,
  8817. Url: esdata.Url,
  8818. }
  8819. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8820. redis := service.RedisClient()
  8821. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8822. redis.Set(key, "", time.Second)
  8823. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8824. //清空key 值
  8825. redis.Set(keyOne, "", time.Second)
  8826. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8827. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8828. //redis.Set(keyTwo, "", time.Second)
  8829. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8830. redis.Set(keyThree, "", time.Second)
  8831. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8832. redis.Set(keyFour, "", time.Second)
  8833. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8834. redis.Set(keyFive, "", time.Second)
  8835. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8836. redis.Set(keySix, "", time.Second)
  8837. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8838. redis.Set(keySeven, "", time.Second)
  8839. if err != nil {
  8840. fmt.Println(err)
  8841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8842. return
  8843. }
  8844. this.ServeSuccessJSON(map[string]interface{}{
  8845. "electronic_signature": esdata,
  8846. })
  8847. }
  8848. func (this *DialysisAPIController) GetPatientSign() {
  8849. patient_id, _ := this.GetInt64("patient_id")
  8850. dialysis_date, _ := this.GetInt64("dialysis_date")
  8851. adminUserInfo := this.GetMobileAdminUserInfo()
  8852. orgId := adminUserInfo.Org.Id
  8853. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8854. if err != nil {
  8855. fmt.Println(err)
  8856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8857. return
  8858. }
  8859. this.ServeSuccessJSON(map[string]interface{}{
  8860. "dialysisOrder": dialysisOrder,
  8861. })
  8862. }
  8863. func (this *DialysisAPIController) GetScheduleByPatient() {
  8864. patient_id, _ := this.GetInt64("patient_id")
  8865. schedule_date, _ := this.GetInt64("schedule_date")
  8866. orgid := this.GetMobileAdminUserInfo().Org.Id
  8867. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8868. this.ServeSuccessJSON(map[string]interface{}{
  8869. "schedule": schedule,
  8870. })
  8871. }
  8872. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8873. org_id := this.GetMobileAdminUserInfo().Org.Id
  8874. patient_id, _ := this.GetInt64("patient_id")
  8875. schedule_date, _ := this.GetInt64("schedule_date")
  8876. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8877. this.ServeSuccessJSON(map[string]interface{}{
  8878. "order": order,
  8879. })
  8880. }
  8881. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8882. org_id := this.GetMobileAdminUserInfo().Org.Id
  8883. schedule_date := this.GetString("schedule_date")
  8884. schedule_type, _ := this.GetInt64("schedule_type")
  8885. timeLayout := "2006-01-02"
  8886. loc, _ := time.LoadLocation("Local")
  8887. var startdateunix int64
  8888. if len(schedule_date) > 0 {
  8889. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8890. if err != nil {
  8891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8892. return
  8893. }
  8894. startdateunix = theTime.Unix()
  8895. }
  8896. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8897. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8898. devices, _ := service.GetAllDevicetByListSix(org_id)
  8899. for key, item := range scheduals {
  8900. // 床位信息
  8901. for _, device := range devices {
  8902. if item.BedId == device.ID {
  8903. scheduals[key].DeviceNumber = device
  8904. break
  8905. }
  8906. }
  8907. }
  8908. this.ServeSuccessJSON(map[string]interface{}{
  8909. "list": list,
  8910. "scheduals": scheduals,
  8911. })
  8912. }
  8913. func (this *DialysisAPIController) SavePatientPicture() {
  8914. patient_id, _ := this.GetInt64("patient_id")
  8915. dialysis_date, _ := this.GetInt64("schedule_date")
  8916. avatar := this.GetString("avatar")
  8917. fmt.Println("patient_id", patient_id)
  8918. orgId := this.GetMobileAdminUserInfo().Org.Id
  8919. order := models.DialysisOrder{
  8920. Url: avatar,
  8921. }
  8922. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8923. redis := service.RedisClient()
  8924. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8925. redis.Set(key, "", time.Second)
  8926. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8927. //清空key 值
  8928. redis.Set(keyOne, "", time.Second)
  8929. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8930. redis.Set(keyThree, "", time.Second)
  8931. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8932. redis.Set(keyFour, "", time.Second)
  8933. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8934. redis.Set(keyFive, "", time.Second)
  8935. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8936. redis.Set(keySix, "", time.Second)
  8937. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8938. redis.Set(keySeven, "", time.Second)
  8939. if err != nil {
  8940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8941. return
  8942. }
  8943. this.ServeSuccessJSON(map[string]interface{}{
  8944. "order": order,
  8945. })
  8946. }
  8947. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8948. ids := this.GetString("ids")
  8949. idSplit := strings.Split(ids, ",")
  8950. orgId := this.GetMobileAdminUserInfo().Org.Id
  8951. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8952. execution_time := this.GetString("exce_time")
  8953. timeLayout2 := "2006-01-02 15:04:05"
  8954. loc, _ := time.LoadLocation("Local")
  8955. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8956. if errs != nil {
  8957. utils.ErrorLog(errs.Error())
  8958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8959. return
  8960. }
  8961. //his客户
  8962. if config.IsOpen == 1 {
  8963. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8964. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8965. for _, item := range list {
  8966. for _, it := range adviceList {
  8967. if item.DrugId == it.DrugId {
  8968. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8969. }
  8970. }
  8971. }
  8972. for _, item := range list {
  8973. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8974. var sum_out_count int64
  8975. for _, itemThree := range item.ChildDoctorAdvice {
  8976. var prescribing_number int64
  8977. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8978. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8979. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8980. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8981. }
  8982. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8983. prescribing_number = parseIntPrescribingNumber
  8984. }
  8985. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8986. prescribing_number = parseIntPrescribingNumber
  8987. }
  8988. sum_out_count += prescribing_number
  8989. }
  8990. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8991. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8992. //库存不足
  8993. if sum_out_count > drugStockOut.FlushCount {
  8994. this.ServeSuccessJSON(map[string]interface{}{
  8995. "msg": "2",
  8996. "drug": medical,
  8997. "ids": ids,
  8998. })
  8999. return
  9000. }
  9001. }
  9002. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9003. //执行医嘱
  9004. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9005. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9006. for _, item := range advices {
  9007. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9008. redis := service.RedisClient()
  9009. //清空key 值
  9010. redis.Set(key, "", time.Second)
  9011. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9012. redis.Set(keyTwo, "", time.Second)
  9013. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9014. redis.Set(keyThree, "", time.Second)
  9015. recordDate := theTime.Format("2006-01-02")
  9016. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9017. redis.Set(keyFour, "", time.Second)
  9018. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9019. redis.Set(keyFive, "", time.Second)
  9020. defer redis.Close()
  9021. }
  9022. if errs == nil {
  9023. //药品管理信息
  9024. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9025. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9026. if drugStockConfig.IsOpen == 1 {
  9027. for _, item := range advices {
  9028. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9029. config, _ := service.GetDrugOpenConfigOne(orgId)
  9030. if config.IsOpen != 1 {
  9031. //查询该药品是否有库存
  9032. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9033. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9034. if medical.IsUse == 2 {
  9035. if config.IsOpen != 1 {
  9036. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9037. service.HisDrugsDelivery(orgId, creater, &advice)
  9038. if orgId == 3877 || orgId == 10265 {
  9039. //查询该药品是否有出库记录
  9040. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9041. if len(flowMap) == 0 {
  9042. errs := service.UpdateHisAdviceById(advice.ID)
  9043. if errs != nil {
  9044. drugError := models.XtDrugError{
  9045. UserOrgId: orgId,
  9046. DrugId: item.DrugId,
  9047. RecordDate: item.AdviceDate,
  9048. PatientId: item.PatientId,
  9049. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9050. Status: 1,
  9051. Ctime: time.Now().Unix(),
  9052. Mtime: 0,
  9053. SumCount: 0,
  9054. Prescribingnumber: advice.PrescribingNumber,
  9055. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9056. }
  9057. service.CreateDrugError(drugError)
  9058. }
  9059. this.ServeSuccessJSON(map[string]interface{}{
  9060. "msg": "2",
  9061. "drug": medical,
  9062. "ids": ids,
  9063. })
  9064. return
  9065. }
  9066. }
  9067. }
  9068. if pharmacyConfig.IsOpen != 1 {
  9069. service.HisDrugsDelivery(orgId, creater, &advice)
  9070. if orgId == 3877 || orgId == 10265 {
  9071. //查询该药品是否有出库记录
  9072. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9073. if len(flowMap) == 0 {
  9074. errs := service.UpdateHisAdviceById(advice.ID)
  9075. if errs != nil {
  9076. drugError := models.XtDrugError{
  9077. UserOrgId: orgId,
  9078. DrugId: item.DrugId,
  9079. RecordDate: item.AdviceDate,
  9080. PatientId: item.PatientId,
  9081. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9082. Status: 1,
  9083. Ctime: time.Now().Unix(),
  9084. Mtime: 0,
  9085. SumCount: 0,
  9086. Prescribingnumber: advice.PrescribingNumber,
  9087. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9088. }
  9089. service.CreateDrugError(drugError)
  9090. }
  9091. this.ServeSuccessJSON(map[string]interface{}{
  9092. "msg": "2",
  9093. "drug": medical,
  9094. "ids": ids,
  9095. })
  9096. return
  9097. }
  9098. }
  9099. }
  9100. //更新字典里面的库存
  9101. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9102. var sum_count int64
  9103. for _, its := range stockInfo {
  9104. if its.MaxUnit == medical.MaxUnit {
  9105. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9106. }
  9107. sum_count += its.StockMaxNumber + its.StockMinNumber
  9108. }
  9109. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9110. //剩余库存
  9111. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9112. }
  9113. }
  9114. }
  9115. }
  9116. }
  9117. this.ServeSuccessJSON(map[string]interface{}{
  9118. "msg": "1",
  9119. "ids": ids,
  9120. })
  9121. return
  9122. } else {
  9123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9124. }
  9125. }
  9126. //血透客户
  9127. if config.IsOpen == 2 || config.IsOpen == 0 {
  9128. //药品管理信息
  9129. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9130. if drugStockConfig.IsOpen == 1 {
  9131. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9132. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9133. for _, item := range list {
  9134. for _, it := range adviceList {
  9135. if item.DrugId == it.DrugId {
  9136. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9137. }
  9138. }
  9139. }
  9140. for _, item := range list {
  9141. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9142. var sum_out_count int64
  9143. for _, itemThree := range item.ChildDoctorAdvice {
  9144. var prescribing_number int64
  9145. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9146. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9147. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9148. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9149. }
  9150. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9151. prescribing_number = parseIntPrescribingNumber
  9152. }
  9153. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9154. prescribing_number = parseIntPrescribingNumber
  9155. }
  9156. sum_out_count += prescribing_number
  9157. }
  9158. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9159. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9160. //库存不足
  9161. if sum_out_count > drugStockOut.FlushCount {
  9162. this.ServeSuccessJSON(map[string]interface{}{
  9163. "msg": "2",
  9164. "drug": medical,
  9165. "ids": ids,
  9166. })
  9167. return
  9168. }
  9169. }
  9170. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9171. //执行医嘱
  9172. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9173. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9174. for _, item := range advices {
  9175. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9176. redis := service.RedisClient()
  9177. //清空key 值
  9178. redis.Set(key, "", time.Second)
  9179. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9180. redis.Set(keyTwo, "", time.Second)
  9181. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9182. redis.Set(keyThree, "", time.Second)
  9183. recordDate := theTime.Format("2006-01-02")
  9184. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9185. redis.Set(keyFour, "", time.Second)
  9186. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9187. redis.Set(keyFive, "", time.Second)
  9188. defer redis.Close()
  9189. }
  9190. if errs == nil {
  9191. for _, item := range advices {
  9192. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9193. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9194. //查询是否出库按钮开启
  9195. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9196. if adviceSetting.IsAdviceOpen == 1 {
  9197. //查询是否出库按钮开启
  9198. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9199. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9200. if prescriptionConfig.IsOpen == 1 {
  9201. if medical.IsUse == 2 {
  9202. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9203. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9204. }
  9205. if pharmacyConfig.IsOpen != 1 {
  9206. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9207. }
  9208. //更新字典里面的库存
  9209. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9210. var sum_count int64
  9211. for _, its := range stockInfo {
  9212. if its.MaxUnit == medical.MaxUnit {
  9213. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9214. }
  9215. sum_count += its.StockMaxNumber + its.StockMinNumber
  9216. }
  9217. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9218. //剩余库存
  9219. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9220. }
  9221. }
  9222. } else {
  9223. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9224. if medical.IsUse == 2 {
  9225. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9226. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9227. }
  9228. if pharmacyConfig.IsOpen != 1 {
  9229. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9230. }
  9231. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9232. var sum_count int64
  9233. for _, its := range stockInfo {
  9234. if its.MaxUnit == medical.MaxUnit {
  9235. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9236. }
  9237. sum_count += its.StockMaxNumber + its.StockMinNumber
  9238. }
  9239. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9240. //剩余库存
  9241. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9242. }
  9243. }
  9244. }
  9245. }
  9246. this.ServeSuccessJSON(map[string]interface{}{
  9247. "msg": "1",
  9248. "ids": ids,
  9249. })
  9250. return
  9251. } else {
  9252. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9253. //执行医嘱
  9254. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9255. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9256. for _, item := range advices {
  9257. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9258. redis := service.RedisClient()
  9259. //清空key 值
  9260. redis.Set(key, "", time.Second)
  9261. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9262. redis.Set(keyTwo, "", time.Second)
  9263. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9264. redis.Set(keyThree, "", time.Second)
  9265. recordDate := theTime.Format("2006-01-02")
  9266. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9267. redis.Set(keyFour, "", time.Second)
  9268. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9269. redis.Set(keyFive, "", time.Second)
  9270. defer redis.Close()
  9271. }
  9272. this.ServeSuccessJSON(map[string]interface{}{
  9273. "msg": "1",
  9274. "ids": ids,
  9275. })
  9276. return
  9277. }
  9278. }
  9279. }
  9280. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9281. ids := this.GetString("ids")
  9282. idSplit := strings.Split(ids, ",")
  9283. orgId := this.GetMobileAdminUserInfo().Org.Id
  9284. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9285. if config.IsOpen == 1 {
  9286. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9287. this.ServeSuccessJSON(map[string]interface{}{
  9288. "msg": "1",
  9289. "ids": ids,
  9290. })
  9291. return
  9292. }
  9293. if config.IsOpen == 0 || config.IsOpen == 2 {
  9294. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9295. this.ServeSuccessJSON(map[string]interface{}{
  9296. "msg": "1",
  9297. "ids": ids,
  9298. })
  9299. return
  9300. }
  9301. }
  9302. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9303. ids := this.GetString("ids")
  9304. idSplit := strings.Split(ids, ",")
  9305. orgId := this.GetMobileAdminUserInfo().Org.Id
  9306. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9307. //his
  9308. if config.IsOpen == 1 {
  9309. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9310. theTime := time.Now()
  9311. advices := models.HisDoctorAdviceThirty{
  9312. CheckTime: theTime.Unix(),
  9313. Checker: checker,
  9314. UpdatedTime: time.Now().Unix(),
  9315. }
  9316. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9317. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9318. for _, item := range list {
  9319. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9320. redis := service.RedisClient()
  9321. //清空key 值
  9322. redis.Set(key, "", time.Second)
  9323. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9324. redis.Set(keyTwo, "", time.Second)
  9325. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9326. redis.Set(keyThree, "", time.Second)
  9327. recordDate := theTime.Format("2006-01-02")
  9328. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9329. redis.Set(keyFour, "", time.Second)
  9330. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9331. redis.Set(keyFive, "", time.Second)
  9332. defer redis.Close()
  9333. }
  9334. this.ServeSuccessJSON(map[string]interface{}{
  9335. "msg": "1",
  9336. "ids": ids,
  9337. })
  9338. return
  9339. }
  9340. //血透
  9341. if config.IsOpen == 0 || config.IsOpen == 2 {
  9342. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9343. theTime := time.Now()
  9344. advices := models.DoctorAdvice{
  9345. CheckTime: theTime.Unix(),
  9346. Checker: checker,
  9347. UpdatedTime: time.Now().Unix(),
  9348. }
  9349. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9350. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9351. for _, item := range list {
  9352. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9353. redis := service.RedisClient()
  9354. //清空key 值
  9355. redis.Set(key, "", time.Second)
  9356. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9357. redis.Set(keyTwo, "", time.Second)
  9358. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9359. redis.Set(keyThree, "", time.Second)
  9360. recordDate := theTime.Format("2006-01-02")
  9361. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9362. redis.Set(keyFour, "", time.Second)
  9363. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9364. redis.Set(keyFive, "", time.Second)
  9365. defer redis.Close()
  9366. }
  9367. this.ServeSuccessJSON(map[string]interface{}{
  9368. "msg": "1",
  9369. "ids": ids,
  9370. })
  9371. return
  9372. }
  9373. }
  9374. func (this *DialysisAPIController) CheckSchedule() {
  9375. patientID, _ := this.GetInt64("patient_id")
  9376. recordDateStr := this.GetString("record_date")
  9377. nurseID, _ := this.GetInt64("start_nurse")
  9378. schedual_type, _ := this.GetInt64("schedual_type")
  9379. bedID, _ := this.GetInt64("bed")
  9380. start_time := this.GetString("start_time")
  9381. fmt.Println("patientID", patientID)
  9382. fmt.Println("recordDateStr", recordDateStr)
  9383. fmt.Println("nurseID", nurseID)
  9384. fmt.Println("schedual_type------", schedual_type)
  9385. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9386. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9387. return
  9388. }
  9389. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9390. if parseStartDateErr != nil {
  9391. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9393. return
  9394. }
  9395. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9396. if parseErr != nil {
  9397. this.ErrorLog("时间解析失败:%v", parseErr)
  9398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9399. return
  9400. }
  9401. adminUserInfo := this.GetMobileAdminUserInfo()
  9402. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9403. if getPatientErr != nil {
  9404. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9406. return
  9407. } else if patient == nil {
  9408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9409. return
  9410. }
  9411. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9412. if getNurseErr != nil {
  9413. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9415. return
  9416. } else if nurse == nil {
  9417. this.ErrorLog("护士不存在")
  9418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9419. return
  9420. }
  9421. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9422. if getDeviceNumberErr != nil {
  9423. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9425. return
  9426. } else if deviceNumber == nil {
  9427. this.ErrorLog("床位号不存在")
  9428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9429. return
  9430. }
  9431. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9432. if getRecordErr != nil {
  9433. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9435. return
  9436. } else if dialysisRecord != nil {
  9437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9438. return
  9439. }
  9440. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9441. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9442. timeLayout := "2006-01-02 15:04:05"
  9443. loc, _ := time.LoadLocation("Local")
  9444. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9445. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9446. schedulestartTime := theStartTime.Unix()
  9447. scheduleendTime := theEndTime.Unix()
  9448. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9449. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9450. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9451. //查询该床位是否有人用了
  9452. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9453. if err == nil {
  9454. if schedule.ID == 0 {
  9455. this.ServeSuccessJSON(map[string]interface{}{
  9456. "status": 0,
  9457. "msg": "请求失败",
  9458. })
  9459. } else {
  9460. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9461. if order.ID > 0 { //该机位被其他人占用了
  9462. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9463. return
  9464. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9465. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9466. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9467. this.ServeSuccessJSON(map[string]interface{}{
  9468. "status": 1,
  9469. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9470. })
  9471. return
  9472. } else {
  9473. this.ServeSuccessJSON(map[string]interface{}{
  9474. "status": 0,
  9475. "msg": "",
  9476. })
  9477. }
  9478. }
  9479. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9480. this.ServeSuccessJSON(map[string]interface{}{
  9481. "status": 2,
  9482. "msg": "当前机位已有患者在使用,请重新选择!",
  9483. })
  9484. }
  9485. }
  9486. } else {
  9487. this.ServeSuccessJSON(map[string]interface{}{
  9488. "status": 0,
  9489. "msg": "",
  9490. })
  9491. }
  9492. }
  9493. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9494. orgId := this.GetMobileAdminUserInfo().Org.Id
  9495. schedule_type, _ := this.GetInt64("schedule_type")
  9496. partion_type, _ := this.GetInt64("partion_type")
  9497. start_time := this.GetString("start_time")
  9498. timeLayout := "2006-01-02"
  9499. loc, _ := time.LoadLocation("Local")
  9500. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9501. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9502. _, config := service.FindXTHisRecordByOrgId(orgId)
  9503. appId := this.GetMobileAdminUserInfo().App.Id
  9504. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9505. if err == nil {
  9506. this.ServeSuccessJSON(map[string]interface{}{
  9507. "list": list,
  9508. "config": config,
  9509. "doctorList": doctorList,
  9510. })
  9511. return
  9512. } else {
  9513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9514. return
  9515. }
  9516. }
  9517. func (this *DialysisAPIController) SaveMobileInformation() {
  9518. patient_id, _ := this.GetInt64("patient_id")
  9519. record_date, _ := this.GetInt64("record_date")
  9520. startTime := this.GetString("start_time")
  9521. module, _ := this.GetInt64("module")
  9522. remark := this.GetString("remark")
  9523. timeLayout := "2006-01-02 15:04"
  9524. loc, _ := time.LoadLocation("Local")
  9525. if len(startTime) == 0 {
  9526. utils.ErrorLog("len(start_time) == 0")
  9527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9528. return
  9529. }
  9530. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9531. if err != nil {
  9532. utils.ErrorLog(err.Error())
  9533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9534. return
  9535. }
  9536. StartTime := theTime.Unix()
  9537. fmt.Println("startime-------------", StartTime)
  9538. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9539. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9540. information := models.XtDialysisInformation{
  9541. Module: module,
  9542. PatientId: patient_id,
  9543. RecordDate: record_date,
  9544. ApplicationDate: StartTime,
  9545. Creater: creater,
  9546. ApplicationStatus: 2,
  9547. Checker: 0,
  9548. CheckTime: 0,
  9549. Remark: remark,
  9550. UserOrgId: user_org_id,
  9551. Ctime: time.Now().Unix(),
  9552. Status: 1,
  9553. Mtime: 0,
  9554. }
  9555. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9556. if infor.ID == 0 {
  9557. service.SaveDialysisInformation(information)
  9558. }
  9559. if infor.ID > 0 {
  9560. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9561. }
  9562. this.ServeSuccessJSON(map[string]interface{}{
  9563. "information": information,
  9564. })
  9565. return
  9566. }
  9567. func (this *DialysisAPIController) GetMobileInformation() {
  9568. limit, _ := this.GetInt64("limit")
  9569. page, _ := this.GetInt64("page")
  9570. orgid := this.GetMobileAdminUserInfo().Org.Id
  9571. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9572. appid := this.GetMobileAdminUserInfo().App.Id
  9573. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9574. patients, _ := service.GetAllpatientThirty(orgid)
  9575. this.ServeSuccessJSON(map[string]interface{}{
  9576. "information": information,
  9577. "total": total,
  9578. "doclist": doclist,
  9579. "patients": patients,
  9580. })
  9581. return
  9582. }
  9583. func (this *DialysisAPIController) GetMobileInformationOne() {
  9584. limit, _ := this.GetInt64("limit")
  9585. page, _ := this.GetInt64("page")
  9586. orgid := this.GetMobileAdminUserInfo().Org.Id
  9587. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9588. appid := this.GetMobileAdminUserInfo().App.Id
  9589. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9590. patients, _ := service.GetAllpatientThirty(orgid)
  9591. this.ServeSuccessJSON(map[string]interface{}{
  9592. "information": information,
  9593. "total": total,
  9594. "doclist": doclist,
  9595. "patients": patients,
  9596. })
  9597. return
  9598. }
  9599. func (this *DialysisAPIController) CheckMobileInformation() {
  9600. id, _ := this.GetInt64("id")
  9601. application_status, _ := this.GetInt64("application_status")
  9602. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9603. checktime := time.Now().Unix()
  9604. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9605. if err == nil {
  9606. this.ServeSuccessJSON(map[string]interface{}{
  9607. "msg": "ok",
  9608. })
  9609. return
  9610. }
  9611. }
  9612. func (c *DialysisAPIController) GetControlMonitorList() {
  9613. partition, _ := c.GetInt64("partition")
  9614. monitorDate := c.GetString("date")
  9615. patient_id, _ := c.GetInt64("patient_id")
  9616. pat_type, _ := c.GetInt64("pat_type")
  9617. timeLayout := "2006-01-02"
  9618. loc, _ := time.LoadLocation("Local")
  9619. var theStartTime int64
  9620. if len(monitorDate) > 0 {
  9621. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9622. if err != nil {
  9623. theStartTime = 0
  9624. }
  9625. theStartTime = theTime.Unix()
  9626. }
  9627. adminInfo := c.GetMobileAdminUserInfo()
  9628. orgID := adminInfo.Org.Id
  9629. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9630. if err != nil {
  9631. c.ErrorLog("获取排班信息失败:%v", err)
  9632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9633. } else {
  9634. if len(monitor) > 0 {
  9635. //获取所有床位
  9636. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9637. //获取所有分区
  9638. zoneList, _ := service.GetAllZoneByList(orgID)
  9639. //获取透析处方
  9640. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9641. //获取透前评估
  9642. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9643. //获取上机
  9644. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9645. //获取透后
  9646. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9647. //获取透后监测
  9648. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9649. //获取所有的患者
  9650. patients, _ := service.GetAllPatientListByListOne(orgID)
  9651. //获取所有透析模式
  9652. treatments, _ := service.GetAllTreatModeByList(orgID)
  9653. //获取所有医嘱
  9654. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9655. //获取双人核对
  9656. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9657. //治疗小结
  9658. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9659. //待消毒
  9660. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9661. for key, item := range monitor {
  9662. // 获取床位信息
  9663. for _, it := range numberList {
  9664. if item.BedId == it.ID {
  9665. monitor[key].DeviceNumber = it
  9666. break
  9667. }
  9668. }
  9669. //获取分区信息
  9670. for _, it := range zoneList {
  9671. if item.PartitionId == it.ID {
  9672. monitor[key].DeviceZone = it
  9673. }
  9674. }
  9675. for _, prescription := range prescriptions {
  9676. if item.PatientId == prescription.PatientId {
  9677. monitor[key].Prescription = prescription
  9678. break
  9679. }
  9680. }
  9681. for _, it := range checkList {
  9682. if item.PatientId == it.PatientId {
  9683. monitor[key].DoubleCheck = it
  9684. break
  9685. }
  9686. }
  9687. for _, it := range summaryList {
  9688. if item.PatientId == it.PatientId {
  9689. monitor[key].TreatmentSummaryForList = it
  9690. break
  9691. }
  9692. }
  9693. // 透前评估
  9694. for _, assessmentBefore := range assessmentBefores {
  9695. if item.PatientId == assessmentBefore.PatientId {
  9696. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9697. break
  9698. }
  9699. }
  9700. // 透析上下机
  9701. for _, dialysisOrder := range dialysisOrders {
  9702. if item.PatientId == dialysisOrder.PatientId {
  9703. monitor[key].DialysisOrder = dialysisOrder
  9704. break
  9705. }
  9706. }
  9707. // 治疗小节
  9708. for _, afterDislysis := range AssessmentAfterDislysis {
  9709. if item.PatientId == afterDislysis.PatientId {
  9710. monitor[key].AssessmentAfterDislysis = afterDislysis
  9711. break
  9712. }
  9713. }
  9714. for _, it := range monitorlist {
  9715. if item.PatientId == it.PatientId {
  9716. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9717. }
  9718. }
  9719. for _, it := range adviceList {
  9720. if item.PatientId == it.PatientId {
  9721. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9722. }
  9723. }
  9724. for _, patient := range patients {
  9725. if item.PatientId == patient.ID {
  9726. monitor[key].MonitorPatients = patient
  9727. break
  9728. }
  9729. }
  9730. for _, treatment := range treatments {
  9731. if item.ModeId == treatment.ID {
  9732. monitor[key].TreatmentMode = treatment
  9733. break
  9734. }
  9735. }
  9736. for _, infor := range informationList {
  9737. if item.PatientId == infor.PatientId {
  9738. monitor[key].NewDeviceInformation = infor
  9739. break
  9740. }
  9741. }
  9742. }
  9743. }
  9744. }
  9745. patients, err := service.GetAllpatientFourty(orgID)
  9746. var mds []*models.NewMonitorDialysisScheduleList
  9747. if pat_type == 0 {
  9748. for _, item := range monitor {
  9749. mds = append(mds, item)
  9750. }
  9751. }
  9752. //待医嘱核对
  9753. if pat_type == 1 {
  9754. for _, item := range monitor {
  9755. if len(item.AdviceList) > 0 {
  9756. mds = append(mds, item)
  9757. }
  9758. }
  9759. }
  9760. //待开小结
  9761. if pat_type == 2 {
  9762. for _, item := range monitor {
  9763. if item.TreatmentSummaryForList == nil {
  9764. mds = append(mds, item)
  9765. }
  9766. }
  9767. }
  9768. //待下机
  9769. if pat_type == 3 {
  9770. for _, item := range monitor {
  9771. if item.DialysisOrder != nil {
  9772. if item.DialysisOrder.ID > 0 {
  9773. mds = append(mds, item)
  9774. }
  9775. }
  9776. }
  9777. }
  9778. //待消毒
  9779. if pat_type == 4 {
  9780. for _, item := range monitor {
  9781. if item.NewDeviceInformation == nil {
  9782. mds = append(mds, item)
  9783. }
  9784. }
  9785. }
  9786. //待双人核对
  9787. if pat_type == 5 {
  9788. for _, item := range monitor {
  9789. if item.DoubleCheck == nil {
  9790. mds = append(mds, item)
  9791. }
  9792. }
  9793. }
  9794. //医嘱未执行
  9795. if pat_type == 6 {
  9796. for _, item := range monitor {
  9797. if len(item.AdviceList) > 0 {
  9798. mds = append(mds, item)
  9799. }
  9800. }
  9801. }
  9802. //患者未签名
  9803. if pat_type == 7 {
  9804. for _, item := range monitor {
  9805. if item.DialysisOrder != nil {
  9806. if item.DialysisOrder.ID > 0 {
  9807. mds = append(mds, item)
  9808. }
  9809. }
  9810. }
  9811. }
  9812. //目标超滤于实际超滤不同
  9813. if pat_type == 8 {
  9814. for _, item := range monitor {
  9815. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9816. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9817. mds = append(mds, item)
  9818. }
  9819. }
  9820. }
  9821. }
  9822. //血压少于5次
  9823. if pat_type == 9 {
  9824. for _, item := range monitor {
  9825. if len(item.MonitoringRecord) < 5 {
  9826. mds = append(mds, item)
  9827. }
  9828. }
  9829. }
  9830. if pat_type == 10 {
  9831. for _, item := range monitor {
  9832. if len(item.MonitoringRecord) == 0 {
  9833. mds = append(mds, item)
  9834. }
  9835. }
  9836. }
  9837. if pat_type == 11 {
  9838. for _, item := range monitor {
  9839. if len(item.MonitoringRecord) > 0 {
  9840. mds = append(mds, item)
  9841. }
  9842. }
  9843. }
  9844. if pat_type == 12 {
  9845. for _, item := range monitor {
  9846. if len(item.MonitoringRecord) > 0 {
  9847. mds = append(mds, item)
  9848. }
  9849. }
  9850. }
  9851. if err == nil {
  9852. c.ServeSuccessJSON(map[string]interface{}{
  9853. "monitor": mds,
  9854. "patients": patients,
  9855. })
  9856. } else {
  9857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9858. }
  9859. }
  9860. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9861. admin_user_id, _ := c.GetInt64("admin_user_id")
  9862. timeStr := time.Now().Format("2006-01-02")
  9863. timeLayout := "2006-01-02 15:04:05"
  9864. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9865. timenow := timeStringToTime.Unix()
  9866. orgId := c.GetMobileAdminUserInfo().Org.Id
  9867. //查询当前护士的患者
  9868. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9869. var patientIds []int64
  9870. for _, item := range orderList {
  9871. patientIds = append(patientIds, item.PatientId)
  9872. }
  9873. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9874. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9875. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9876. //药品管理信息
  9877. _, drugStockConfig := service.FindHisConfig(orgId)
  9878. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9879. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9880. c.ServeSuccessJSON(map[string]interface{}{
  9881. "adviceList": adviceList,
  9882. "hisAdviceList": hisAdviceList,
  9883. "projectList": projectList,
  9884. "drugStockConfig": drugStockConfig,
  9885. "patientList": patientList,
  9886. "projectConfig": projectConfig,
  9887. })
  9888. }
  9889. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9890. patient_id, _ := c.GetInt64("patient_id")
  9891. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9892. c.ServeSuccessJSON(map[string]interface{}{
  9893. "recrods": recrods,
  9894. })
  9895. }
  9896. func (c *DialysisAPIController) ExMobileChangeSch() {
  9897. id_one, _ := c.GetInt64("id_one")
  9898. id_two, _ := c.GetInt64("id_two")
  9899. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9900. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9901. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9902. //if order2.ID > 0 {
  9903. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9904. // return
  9905. //}
  9906. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9907. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9908. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9909. if count > 0 {
  9910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9911. return
  9912. }
  9913. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9914. if count1 > 0 {
  9915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9916. return
  9917. }
  9918. }
  9919. err := service.UpdateScheduleThree(sch, sch_two)
  9920. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9921. if order.ID > 0 {
  9922. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9923. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9924. redis := service.RedisClient()
  9925. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9926. redis.Set(key, "", time.Second)
  9927. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9928. //清空key 值
  9929. redis.Set(keyOne, "", time.Second)
  9930. }
  9931. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9932. if orderOne.ID > 0 {
  9933. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9934. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9935. redis := service.RedisClient()
  9936. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9937. redis.Set(key, "", time.Second)
  9938. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9939. //清空key 值
  9940. redis.Set(keyOne, "", time.Second)
  9941. }
  9942. if err == nil {
  9943. //去除当天患者排班中重复数据,保留最后一条数据
  9944. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9945. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9946. c.ServeSuccessJSON(map[string]interface{}{
  9947. "msg": "交换成功",
  9948. })
  9949. } else {
  9950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9951. return
  9952. }
  9953. }
  9954. func (c *DialysisAPIController) MobileCoverSch() {
  9955. id_one, _ := c.GetInt64("id_one")
  9956. id_two, _ := c.GetInt64("id_two")
  9957. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9958. //针对凤凰医院
  9959. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9960. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9961. if len(advice) > 0 {
  9962. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9963. }
  9964. }
  9965. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9966. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9967. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9968. if len(hisAdvice) > 0 {
  9969. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9970. }
  9971. if len(project) > 0 {
  9972. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9973. }
  9974. }
  9975. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9976. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9977. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9978. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9979. if count > 0 {
  9980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9981. return
  9982. }
  9983. }
  9984. var new_sch models.Schedule
  9985. new_sch = sch
  9986. new_sch.BedId = sch_two.BedId
  9987. new_sch.ScheduleDate = sch_two.ScheduleDate
  9988. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9989. new_sch.PartitionId = sch_two.PartitionId
  9990. new_sch.ScheduleType = sch_two.ScheduleType
  9991. new_sch.ID = 0
  9992. //删除原来的排班
  9993. err := service.SaveSchTwo(sch, sch_two)
  9994. //生成新的排班
  9995. if err == nil {
  9996. err2 := service.SaveSch(&new_sch)
  9997. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9998. if order.ID > 0 {
  9999. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10000. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10001. redis := service.RedisClient()
  10002. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10003. redis.Set(key, "", time.Second)
  10004. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10005. //清空key 值
  10006. redis.Set(keyOne, "", time.Second)
  10007. }
  10008. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10009. if orderOne.ID > 0 {
  10010. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10011. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10012. redis := service.RedisClient()
  10013. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10014. redis.Set(key, "", time.Second)
  10015. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10016. //清空key 值
  10017. redis.Set(keyOne, "", time.Second)
  10018. }
  10019. if err2 == nil {
  10020. //去除当天患者排班中重复数据,保留最后一条数据
  10021. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10022. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10023. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10024. c.ServeSuccessJSON(map[string]interface{}{
  10025. "msg": "覆盖成功",
  10026. "new_sch": new_sch,
  10027. })
  10028. } else {
  10029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10030. return
  10031. }
  10032. } else {
  10033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10034. return
  10035. }
  10036. }
  10037. func (c *DialysisAPIController) BatchCheckAdvice() {
  10038. patient_id, _ := c.GetInt64("patient_id")
  10039. advice_date, _ := c.GetInt64("advice_date")
  10040. org_id := c.GetMobileAdminUserInfo().Org.Id
  10041. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10042. //查询是his系统还是血透系统
  10043. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10044. //his客户
  10045. if configs.IsOpen == 1 {
  10046. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10047. for _, item := range adviceList {
  10048. service.BatchCheckHisAdvice(item.ID, creater)
  10049. }
  10050. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10051. for _, item := range projectList {
  10052. service.BatchCheckProject(item.ID, creater)
  10053. }
  10054. c.ServeSuccessJSON(map[string]interface{}{
  10055. "adviceList": adviceList,
  10056. "projectList": projectList,
  10057. })
  10058. }
  10059. if configs.IsOpen != 1 {
  10060. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10061. for _, item := range adviceList {
  10062. service.BatchAdviceList(item.ID, creater)
  10063. }
  10064. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10065. for _, item := range projectList {
  10066. service.BatchCheckProject(item.ID, creater)
  10067. }
  10068. c.ServeSuccessJSON(map[string]interface{}{
  10069. "adviceList": adviceList,
  10070. "projectList": projectList,
  10071. })
  10072. }
  10073. return
  10074. }
  10075. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10076. org_id := c.GetMobileAdminUserInfo().Org.Id
  10077. drugList, _ := service.GetAllDrugList(org_id)
  10078. c.ServeSuccessJSON(map[string]interface{}{
  10079. "drugList": drugList,
  10080. })
  10081. }
  10082. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10083. org_id := c.GetMobileAdminUserInfo().Org.Id
  10084. dataBody := make(map[string]interface{}, 0)
  10085. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10086. if err != nil {
  10087. utils.ErrorLog(err.Error())
  10088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10089. return
  10090. }
  10091. timeLayout := "2006-01-02"
  10092. loc, _ := time.LoadLocation("Local")
  10093. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10094. utils.ErrorLog("advice_type")
  10095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10096. return
  10097. }
  10098. adviceType := int64(dataBody["advice_type"].(float64))
  10099. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10100. utils.ErrorLog("start_time")
  10101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10102. return
  10103. }
  10104. startTime2, _ := dataBody["start_time"].(string)
  10105. time_arr := strings.Split(startTime2, " ")
  10106. if len(time_arr) > 0 {
  10107. startTime2 = time_arr[0]
  10108. }
  10109. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10110. utils.ErrorLog("advice_date")
  10111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10112. return
  10113. }
  10114. advice_date, _ := dataBody["advice_date"].(string)
  10115. var advicedateunix int64
  10116. if len(advice_date) > 0 {
  10117. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10118. if err != nil {
  10119. fmt.Println(err)
  10120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10121. return
  10122. }
  10123. advicedateunix = theTime.Unix()
  10124. }
  10125. adviceDate := startTime2
  10126. if len(adviceDate) == 0 {
  10127. utils.ErrorLog("len(adviceDate) == 0")
  10128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10129. return
  10130. }
  10131. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10132. if err != nil {
  10133. utils.ErrorLog(err.Error())
  10134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10135. return
  10136. }
  10137. AdviceDate := advicedateunix
  10138. RecordDate := advicedateunix
  10139. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10140. utils.ErrorLog("start_time")
  10141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10142. return
  10143. }
  10144. startTime, _ := dataBody["start_time"].(string)
  10145. if len(startTime) == 0 {
  10146. utils.ErrorLog("len(start_time) == 0")
  10147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10148. return
  10149. }
  10150. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10151. if err != nil {
  10152. utils.ErrorLog(err.Error())
  10153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10154. return
  10155. }
  10156. StartTime := theTime.Unix()
  10157. advice_name, _ := dataBody["advice_name"].(string)
  10158. advice_desc, _ := dataBody["advice_desc"].(string)
  10159. delivery_way, _ := dataBody["delivery_way"].(string)
  10160. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10161. frequency_type := int64(dataBody["frequency_type"].(float64))
  10162. frequency_week, _ := dataBody["frequency_week"].(string)
  10163. prescribing_number := dataBody["prescribing_number"].(float64)
  10164. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10165. remark := dataBody["remark"].(string)
  10166. single_dose := dataBody["single_dose"].(float64)
  10167. single_dose_unit := dataBody["single_dose_unit"].(string)
  10168. patient_id := int64(dataBody["patient_id"].(float64))
  10169. day_count := int64(dataBody["day_count"].(float64))
  10170. groupNo := int64(dataBody["group_no"].(float64))
  10171. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10172. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10173. if groupNo <= 0 {
  10174. group := service.GetMaxAdviceGroupID(org_id)
  10175. groupNo = group + 1
  10176. }
  10177. var template_id = ""
  10178. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10179. template_id = "M" + adviceLastId
  10180. advice := models.DoctorAdvice{
  10181. UserOrgId: org_id,
  10182. PatientId: patient_id,
  10183. AdviceType: adviceType,
  10184. AdviceDate: AdviceDate,
  10185. StartTime: StartTime,
  10186. AdviceName: advice_name,
  10187. AdviceDesc: advice_desc,
  10188. ReminderDate: 0,
  10189. SingleDose: single_dose,
  10190. SingleDoseUnit: single_dose_unit,
  10191. DrugSpec: 0,
  10192. DrugSpecUnit: "",
  10193. PrescribingNumber: prescribing_number,
  10194. PrescribingNumberUnit: prescribing_number_unit,
  10195. DeliveryWay: delivery_way,
  10196. ExecutionFrequency: execution_frequency,
  10197. AdviceDoctor: advice_doctor,
  10198. Status: 1,
  10199. CreatedTime: time.Now().Unix(),
  10200. UpdatedTime: 0,
  10201. AdviceAffirm: "",
  10202. Remark: remark,
  10203. StopTime: 0,
  10204. StopReason: "",
  10205. StopDoctor: 0,
  10206. StopState: 0,
  10207. ParentId: 0,
  10208. ExecutionTime: 0,
  10209. ExecutionStaff: 0,
  10210. ExecutionState: 0,
  10211. Checker: 0,
  10212. RecordDate: RecordDate,
  10213. DialysisOrderId: 0,
  10214. CheckTime: 0,
  10215. CheckState: 0,
  10216. AdviceId: 0,
  10217. RemindType: 0,
  10218. FrequencyType: frequency_type,
  10219. DayCount: day_count,
  10220. WeekDay: frequency_week,
  10221. ChildDoctorAdvice: nil,
  10222. TemplateId: template_id,
  10223. Modifier: 0,
  10224. IsCheck: 0,
  10225. Way: 0,
  10226. DrugId: 0,
  10227. DrugNameId: 0,
  10228. IsMedicine: 0,
  10229. PushStartTime: 0,
  10230. IsSettle: 0,
  10231. IsPrescription: 0,
  10232. GroupNo: groupNo,
  10233. }
  10234. service.CreateMobileAdivce(advice)
  10235. c.ServeSuccessJSON(map[string]interface{}{
  10236. "msg": "保存成功!",
  10237. })
  10238. }
  10239. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10240. patient_id, _ := c.GetInt64("patient_id")
  10241. org_id := c.GetMobileAdminUserInfo().Org.Id
  10242. app_id := c.GetMobileAdminUserInfo().App.Id
  10243. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10244. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10245. c.ServeSuccessJSON(map[string]interface{}{
  10246. "adviceList": adviceList,
  10247. "adminRoles": adminRoles,
  10248. })
  10249. }
  10250. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10251. org_id := c.GetMobileAdminUserInfo().Org.Id
  10252. dataBody := make(map[string]interface{}, 0)
  10253. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10254. if err != nil {
  10255. utils.ErrorLog(err.Error())
  10256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10257. return
  10258. }
  10259. timeLayout := "2006-01-02"
  10260. loc, _ := time.LoadLocation("Local")
  10261. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10262. utils.ErrorLog("start_time")
  10263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10264. return
  10265. }
  10266. startTime2, _ := dataBody["start_time"].(string)
  10267. time_arr := strings.Split(startTime2, " ")
  10268. if len(time_arr) > 0 {
  10269. startTime2 = time_arr[0]
  10270. }
  10271. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10272. utils.ErrorLog("advice_date")
  10273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10274. return
  10275. }
  10276. advice_date, _ := dataBody["advice_date"].(string)
  10277. var advicedateunix int64
  10278. if len(advice_date) > 0 {
  10279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10280. if err != nil {
  10281. fmt.Println(err)
  10282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10283. return
  10284. }
  10285. advicedateunix = theTime.Unix()
  10286. }
  10287. adviceDate := startTime2
  10288. if len(adviceDate) == 0 {
  10289. utils.ErrorLog("len(adviceDate) == 0")
  10290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10291. return
  10292. }
  10293. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10294. if err != nil {
  10295. utils.ErrorLog(err.Error())
  10296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10297. return
  10298. }
  10299. AdviceDate := advicedateunix
  10300. RecordDate := advicedateunix
  10301. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10302. utils.ErrorLog("start_time")
  10303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10304. return
  10305. }
  10306. startTime, _ := dataBody["start_time"].(string)
  10307. if len(startTime) == 0 {
  10308. utils.ErrorLog("len(start_time) == 0")
  10309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10310. return
  10311. }
  10312. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10313. if err != nil {
  10314. utils.ErrorLog(err.Error())
  10315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10316. return
  10317. }
  10318. StartTime := theTime.Unix()
  10319. advice_name, _ := dataBody["advice_name"].(string)
  10320. advice_desc, _ := dataBody["advice_desc"].(string)
  10321. delivery_way, _ := dataBody["delivery_way"].(string)
  10322. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10323. prescribing_number := dataBody["prescribing_number"].(float64)
  10324. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10325. remark := dataBody["remark"].(string)
  10326. single_dose := dataBody["single_dose"].(float64)
  10327. single_dose_unit := dataBody["single_dose_unit"].(string)
  10328. patient_id := int64(dataBody["patient_id"].(float64))
  10329. groupNo := int64(dataBody["group_no"].(float64))
  10330. parent_id := int64(dataBody["parent_id"].(float64))
  10331. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10332. advice := models.XtDoctorAdviceOne{
  10333. UserOrgId: org_id,
  10334. PatientId: patient_id,
  10335. AdviceType: 1,
  10336. AdviceDate: AdviceDate,
  10337. StartTime: StartTime,
  10338. AdviceName: advice_name,
  10339. AdviceDesc: advice_desc,
  10340. ReminderDate: 0,
  10341. SingleDose: single_dose,
  10342. SingleDoseUnit: single_dose_unit,
  10343. PrescribingNumber: prescribing_number,
  10344. PrescribingNumberUnit: prescribing_number_unit,
  10345. DeliveryWay: delivery_way,
  10346. ExecutionFrequency: execution_frequency,
  10347. AdviceDoctor: advice_doctor,
  10348. Status: 1,
  10349. CreatedTime: time.Now().Unix(),
  10350. UpdatedTime: time.Now().Unix(),
  10351. AdviceAffirm: "",
  10352. Remark: remark,
  10353. StopTime: 0,
  10354. StopReason: "",
  10355. StopDoctor: 0,
  10356. StopState: 0,
  10357. ParentId: parent_id,
  10358. ExecutionTime: 0,
  10359. ExecutionStaff: 0,
  10360. ExecutionState: 0,
  10361. Checker: 0,
  10362. RecordDate: RecordDate,
  10363. DialysisOrderId: 0,
  10364. CheckTime: 0,
  10365. CheckState: 0,
  10366. DrugSpec: 0,
  10367. DrugSpecUnit: "",
  10368. Groupno: groupNo,
  10369. RemindType: 0,
  10370. FrequencyType: 0,
  10371. DayCount: 0,
  10372. WeekDay: "",
  10373. TemplateId: "",
  10374. Modifier: 0,
  10375. }
  10376. service.CreateMobileAdivceOne(advice)
  10377. c.ServeSuccessJSON(map[string]interface{}{
  10378. "msg": "保存成功!",
  10379. })
  10380. }
  10381. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10382. id, _ := c.GetInt64("id")
  10383. service.DeleteSelfAdviceSubAdvice(id)
  10384. c.ServeSuccessJSON(map[string]interface{}{
  10385. "msg": "保存成功!",
  10386. })
  10387. }
  10388. func (c *DialysisAPIController) GetEditAdviceAction() {
  10389. id, _ := c.GetInt64("id")
  10390. org_id := c.GetMobileAdminUserInfo().Org.Id
  10391. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10392. drugList, _ := service.GetAllDrugList(org_id)
  10393. c.ServeSuccessJSON(map[string]interface{}{
  10394. "advice": advice,
  10395. "drugList": drugList,
  10396. })
  10397. }
  10398. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10399. dataBody := make(map[string]interface{}, 0)
  10400. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10401. if err != nil {
  10402. utils.ErrorLog(err.Error())
  10403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10404. return
  10405. }
  10406. timeLayout := "2006-01-02"
  10407. loc, _ := time.LoadLocation("Local")
  10408. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10409. utils.ErrorLog("start_time")
  10410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10411. return
  10412. }
  10413. startTime2, _ := dataBody["start_time"].(string)
  10414. time_arr := strings.Split(startTime2, " ")
  10415. if len(time_arr) > 0 {
  10416. startTime2 = time_arr[0]
  10417. }
  10418. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10419. utils.ErrorLog("advice_date")
  10420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10421. return
  10422. }
  10423. advice_date, _ := dataBody["advice_date"].(string)
  10424. var advicedateunix int64
  10425. if len(advice_date) > 0 {
  10426. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10427. if err != nil {
  10428. fmt.Println(err)
  10429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10430. return
  10431. }
  10432. advicedateunix = theTime.Unix()
  10433. }
  10434. adviceDate := startTime2
  10435. if len(adviceDate) == 0 {
  10436. utils.ErrorLog("len(adviceDate) == 0")
  10437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10438. return
  10439. }
  10440. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10441. if err != nil {
  10442. utils.ErrorLog(err.Error())
  10443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10444. return
  10445. }
  10446. AdviceDate := advicedateunix
  10447. RecordDate := advicedateunix
  10448. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10449. utils.ErrorLog("start_time")
  10450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10451. return
  10452. }
  10453. startTime, _ := dataBody["start_time"].(string)
  10454. if len(startTime) == 0 {
  10455. utils.ErrorLog("len(start_time) == 0")
  10456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10457. return
  10458. }
  10459. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10460. if err != nil {
  10461. utils.ErrorLog(err.Error())
  10462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10463. return
  10464. }
  10465. StartTime := theTime.Unix()
  10466. advice_name, _ := dataBody["advice_name"].(string)
  10467. advice_desc, _ := dataBody["advice_desc"].(string)
  10468. delivery_way, _ := dataBody["delivery_way"].(string)
  10469. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10470. prescribing_number := dataBody["prescribing_number"].(float64)
  10471. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10472. remark := dataBody["remark"].(string)
  10473. single_dose := dataBody["single_dose"].(float64)
  10474. single_dose_unit := dataBody["single_dose_unit"].(string)
  10475. id := int64(dataBody["id"].(float64))
  10476. frequency_type := int64(dataBody["frequency_type"].(float64))
  10477. frequency_week, _ := dataBody["frequency_week"].(string)
  10478. day_count := int64(dataBody["day_count"].(float64))
  10479. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10480. advice := models.XtDoctorAdviceOne{
  10481. AdviceDate: AdviceDate,
  10482. StartTime: StartTime,
  10483. AdviceName: advice_name,
  10484. AdviceDesc: advice_desc,
  10485. SingleDose: single_dose,
  10486. SingleDoseUnit: single_dose_unit,
  10487. PrescribingNumber: prescribing_number,
  10488. PrescribingNumberUnit: prescribing_number_unit,
  10489. DeliveryWay: delivery_way,
  10490. ExecutionFrequency: execution_frequency,
  10491. AdviceDoctor: advice_doctor,
  10492. Remark: remark,
  10493. RecordDate: RecordDate,
  10494. FrequencyType: frequency_type,
  10495. DayCount: day_count,
  10496. WeekDay: frequency_week,
  10497. }
  10498. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10499. c.ServeSuccessJSON(map[string]interface{}{
  10500. "advice": advice,
  10501. })
  10502. }
  10503. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10504. dataBody := make(map[string]interface{}, 0)
  10505. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10506. if err != nil {
  10507. utils.ErrorLog(err.Error())
  10508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10509. return
  10510. }
  10511. timeLayout := "2006-01-02"
  10512. loc, _ := time.LoadLocation("Local")
  10513. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10514. utils.ErrorLog("start_time")
  10515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10516. return
  10517. }
  10518. startTime2, _ := dataBody["start_time"].(string)
  10519. time_arr := strings.Split(startTime2, " ")
  10520. if len(time_arr) > 0 {
  10521. startTime2 = time_arr[0]
  10522. }
  10523. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10524. utils.ErrorLog("advice_date")
  10525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10526. return
  10527. }
  10528. advice_date, _ := dataBody["advice_date"].(string)
  10529. var advicedateunix int64
  10530. if len(advice_date) > 0 {
  10531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10532. if err != nil {
  10533. fmt.Println(err)
  10534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10535. return
  10536. }
  10537. advicedateunix = theTime.Unix()
  10538. }
  10539. adviceDate := startTime2
  10540. if len(adviceDate) == 0 {
  10541. utils.ErrorLog("len(adviceDate) == 0")
  10542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10543. return
  10544. }
  10545. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10546. if err != nil {
  10547. utils.ErrorLog(err.Error())
  10548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10549. return
  10550. }
  10551. AdviceDate := advicedateunix
  10552. RecordDate := advicedateunix
  10553. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10554. utils.ErrorLog("start_time")
  10555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10556. return
  10557. }
  10558. startTime, _ := dataBody["start_time"].(string)
  10559. if len(startTime) == 0 {
  10560. utils.ErrorLog("len(start_time) == 0")
  10561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10562. return
  10563. }
  10564. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10565. if err != nil {
  10566. utils.ErrorLog(err.Error())
  10567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10568. return
  10569. }
  10570. StartTime := theTime.Unix()
  10571. advice_name, _ := dataBody["advice_name"].(string)
  10572. advice_desc, _ := dataBody["advice_desc"].(string)
  10573. delivery_way, _ := dataBody["delivery_way"].(string)
  10574. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10575. prescribing_number := dataBody["prescribing_number"].(float64)
  10576. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10577. remark := dataBody["remark"].(string)
  10578. single_dose := dataBody["single_dose"].(float64)
  10579. single_dose_unit := dataBody["single_dose_unit"].(string)
  10580. id := int64(dataBody["id"].(float64))
  10581. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10582. advice := models.XtDoctorAdviceOne{
  10583. AdviceDate: AdviceDate,
  10584. StartTime: StartTime,
  10585. AdviceName: advice_name,
  10586. AdviceDesc: advice_desc,
  10587. SingleDose: single_dose,
  10588. SingleDoseUnit: single_dose_unit,
  10589. PrescribingNumber: prescribing_number,
  10590. PrescribingNumberUnit: prescribing_number_unit,
  10591. DeliveryWay: delivery_way,
  10592. ExecutionFrequency: execution_frequency,
  10593. AdviceDoctor: advice_doctor,
  10594. Remark: remark,
  10595. RecordDate: RecordDate,
  10596. }
  10597. service.UpdateMobileDoctorAdviceById(id, advice)
  10598. c.ServeSuccessJSON(map[string]interface{}{
  10599. "advice": advice,
  10600. })
  10601. }
  10602. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10603. dataBody := make(map[string]interface{}, 0)
  10604. timeLayout := "2006-01-02"
  10605. loc, _ := time.LoadLocation("Local")
  10606. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10607. if err != nil {
  10608. utils.ErrorLog(err.Error())
  10609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10610. return
  10611. }
  10612. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10613. utils.ErrorLog("start_time")
  10614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10615. return
  10616. }
  10617. startTime2, _ := dataBody["start_time"].(string)
  10618. time_arr := strings.Split(startTime2, " ")
  10619. if len(time_arr) > 0 {
  10620. startTime2 = time_arr[0]
  10621. }
  10622. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10623. utils.ErrorLog("advice_date")
  10624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10625. return
  10626. }
  10627. advice_date, _ := dataBody["advice_date"].(string)
  10628. var advicedateunix int64
  10629. if len(advice_date) > 0 {
  10630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10631. if err != nil {
  10632. fmt.Println(err)
  10633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10634. return
  10635. }
  10636. advicedateunix = theTime.Unix()
  10637. }
  10638. adviceDate := startTime2
  10639. if len(adviceDate) == 0 {
  10640. utils.ErrorLog("len(adviceDate) == 0")
  10641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10642. return
  10643. }
  10644. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10645. if err != nil {
  10646. utils.ErrorLog(err.Error())
  10647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10648. return
  10649. }
  10650. RecordDate := advicedateunix
  10651. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10652. utils.ErrorLog("start_time")
  10653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10654. return
  10655. }
  10656. startTime, _ := dataBody["start_time"].(string)
  10657. if len(startTime) == 0 {
  10658. utils.ErrorLog("len(start_time) == 0")
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10663. if err != nil {
  10664. utils.ErrorLog(err.Error())
  10665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10666. return
  10667. }
  10668. StartTime := theTime.Unix()
  10669. patient_id := int64(dataBody["patient_id"].(float64))
  10670. group_no := int64(dataBody["group_no"].(float64))
  10671. org_id := c.GetMobileAdminUserInfo().Org.Id
  10672. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10673. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10674. utils.ErrorLog("advices")
  10675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10676. return
  10677. }
  10678. adviceNames := dataBody["advices"].([]interface{})
  10679. var advices []*models.GroupAdvice
  10680. for _, adviceNameMap := range adviceNames {
  10681. var advice models.GroupAdvice
  10682. adviceNameM := adviceNameMap.(map[string]interface{})
  10683. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10684. utils.ErrorLog("advice_name")
  10685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10686. return
  10687. }
  10688. adviceName, _ := adviceNameM["advice_name"].(string)
  10689. if len(adviceName) == 0 {
  10690. utils.ErrorLog("len(advice_name) == 0")
  10691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10692. return
  10693. }
  10694. advice.AdviceName = adviceName
  10695. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10696. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10697. advice.DrugSpec = drugSpec
  10698. }
  10699. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10700. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10701. advice.AdviceDesc = adviceDesc
  10702. }
  10703. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10704. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10705. advice.DrugSpecUnit = drugSpecUnit
  10706. }
  10707. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10708. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10709. advice.SingleDose = singleDose
  10710. }
  10711. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10712. singleDose := adviceNameM["single_dose"].(float64)
  10713. advice.SingleDose = singleDose
  10714. }
  10715. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10716. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10717. advice.SingleDoseUnit = singleDoseUnit
  10718. }
  10719. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10720. tmp := adviceNameM["single_dose_unit"].(float64)
  10721. singleDoseUnit := service.TypeConversion(tmp)
  10722. advice.SingleDoseUnit = singleDoseUnit
  10723. }
  10724. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10725. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10726. advice.PrescribingNumber = prescribingNumber
  10727. }
  10728. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10729. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10730. advice.PrescribingNumber = prescribingNumber
  10731. }
  10732. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10733. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10734. advice.PrescribingNumberUnit = prescribingNumberUnit
  10735. }
  10736. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10737. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10738. advice.DeliveryWay = deliveryWay
  10739. }
  10740. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10741. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10742. advice.ExecutionFrequency = executionFrequency
  10743. }
  10744. remark, _ := adviceNameM["remark"].(string)
  10745. advice.Remark = remark
  10746. advice.AdviceType = 1
  10747. advice.StartTime = StartTime
  10748. advice.RecordDate = RecordDate
  10749. advice.PatientId = patient_id
  10750. advice.UserOrgId = org_id
  10751. advice.AdviceDoctor = advice_doctor
  10752. advices = append(advices, &advice)
  10753. }
  10754. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10755. c.ServeSuccessJSON(map[string]interface{}{
  10756. "advice": newAdvices,
  10757. })
  10758. }
  10759. func (c *DialysisAPIController) StopLongAdvice() {
  10760. stop_time := c.GetString("execution_time")
  10761. id, _ := c.GetInt64("id")
  10762. if len(stop_time) <= 0 {
  10763. utils.ErrorLog("stop_time")
  10764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10765. return
  10766. }
  10767. timeLayout2 := "2006-01-02 15:04:05"
  10768. loc, _ := time.LoadLocation("Local")
  10769. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10770. if errs != nil {
  10771. utils.ErrorLog(errs.Error())
  10772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10773. return
  10774. }
  10775. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10776. c.ServeSuccessJSON(map[string]interface{}{
  10777. "advice": advice,
  10778. })
  10779. }