dialysis_api_controller.go 429KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  891. redis := service.RedisClient()
  892. //清空key 值
  893. redis.Set(key, "", time.Second)
  894. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  895. redis.Set(keyOne, "", time.Second)
  896. defer redis.Close()
  897. if err == nil {
  898. c.ServeSuccessJSON(map[string]interface{}{
  899. "doubleCheck": &doubleCheck,
  900. })
  901. }
  902. } else { //修改
  903. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  904. if infor.ID > 0 {
  905. var cha_time int64
  906. timeNowStr := time.Now().Format("2006-01-02")
  907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  908. //今日的日期减去设置的日期
  909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  910. if cha_time >= recordDate.Unix() {
  911. //查询审核是否允许
  912. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  913. //申请状态不允许的情况 拒绝修改
  914. if infor.ApplicationStatus != 1 {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  916. return
  917. }
  918. }
  919. }
  920. doubleCheck.FirstCheckTime = firstCheckDate
  921. doubleCheck.CheckTime = checkDate
  922. doubleCheck.Creater = creater
  923. doubleCheck.Modifier = modifier
  924. doubleCheck.CreatedTime = check.CreatedTime
  925. doubleCheck.ID = check.ID
  926. doubleCheck.EmployeeNumber = employee_number
  927. doubleCheck.NeedleBatchNumber = needle_batch_number
  928. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  929. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  930. //查询未核对的医嘱
  931. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  932. for _, advice := range doctorList {
  933. if advice.ExecutionStaff == modifier {
  934. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  935. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  936. return
  937. }
  938. }
  939. }
  940. err := service.UpdateDoubleCheck(&doubleCheck)
  941. //针对长沙南雅
  942. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  943. //查询未核对的医嘱
  944. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  945. if len(doctorList) > 0 && modifier > 0 {
  946. for _, advice := range doctorList {
  947. service.UpdateDoctorAdviceList(advice.ID, modifier)
  948. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  949. redis := service.RedisClient()
  950. //清空key 值
  951. redis.Set(key, "", time.Second)
  952. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  953. redis.Set(keyTwo, "", time.Second)
  954. theTime := time.Now()
  955. recordDate := theTime.Format("2006-01-02")
  956. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  957. redis.Set(keyFour, "", time.Second)
  958. defer redis.Close()
  959. }
  960. }
  961. }
  962. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  963. redis := service.RedisClient()
  964. //清空key 值
  965. redis.Set(key, "", time.Second)
  966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  967. redis.Set(keyOne, "", time.Second)
  968. defer redis.Close()
  969. if err == nil {
  970. c.ServeSuccessJSON(map[string]interface{}{
  971. "doubleCheck": &doubleCheck,
  972. "msg": "1",
  973. })
  974. }
  975. }
  976. }
  977. func (c *DialysisAPIController) PostAcceptsAssessment() {
  978. id, _ := c.GetInt64("patient", 0)
  979. recordDateStr := c.GetString("record_date")
  980. way, _ := c.GetInt64("way", 0)
  981. consciousness, _ := c.GetInt64("consciousness", 0)
  982. appetite, _ := c.GetInt64("appetite", 0)
  983. condition, _ := c.GetInt64("condition", 0)
  984. posture, _ := c.GetInt64("posture")
  985. sick_condition, _ := c.GetInt64("sick_condition", 0)
  986. danger_level, _ := c.GetInt64("danger_level", 0)
  987. intake, _ := c.GetInt64("intake", 0)
  988. nutrition, _ := c.GetInt64("nutrition", 0)
  989. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  990. psychological_assessment_other := c.GetString("psychological_assessment_other")
  991. score := c.GetString("score")
  992. sick_condition_other := c.GetString("sick_condition_other")
  993. //precaution, _ := c.GetInt64("precaution", 0)
  994. precaution := c.GetString("precaution")
  995. precaution_other := c.GetString("precaution_other")
  996. psychological_other := c.GetString("psychological_other")
  997. admission_number := c.GetString("admission_number")
  998. tumble, _ := c.GetInt64("tumble")
  999. diacrisis := c.GetString("diacrisis")
  1000. his_department := c.GetString("his_department")
  1001. his_bed := c.GetString("his_bed")
  1002. if id <= 0 {
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. adminUserInfo := c.GetMobileAdminUserInfo()
  1007. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1008. if patient.ID == 0 {
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1010. return
  1011. }
  1012. //now := time.Now()
  1013. //year, month, day := now.Date()
  1014. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1015. //todayTimeStamp := today_time.Unix()
  1016. if len(recordDateStr) == 0 {
  1017. recordDateStr = time.Now().Format("2006-01-02")
  1018. }
  1019. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1020. if parseDateErr != nil {
  1021. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. // 查询信息规挡的设置天数
  1026. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1027. if infor.ID > 0 && infor.WeekDay > 0 {
  1028. var cha_time int64
  1029. timeNowStr := time.Now().Format("2006-01-02")
  1030. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1031. //今日的日期减去设置的日期
  1032. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1033. if cha_time >= recordDate.Unix() {
  1034. //查询审核是否允许
  1035. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1036. //申请状态不允许的情况 拒绝修改
  1037. if infor.ApplicationStatus != 1 {
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1039. return
  1040. }
  1041. }
  1042. }
  1043. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1044. if adminUserInfo.Org.Id == 10340 {
  1045. if condition == 1 {
  1046. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1047. if admission_number == "" {
  1048. admission_number = lastAcceptTreatment.AdmissionNumber
  1049. }
  1050. }
  1051. }
  1052. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1053. UserOrgId: adminUserInfo.Org.Id,
  1054. PatientId: id,
  1055. RecordDate: recordDate.Unix(),
  1056. Way: way,
  1057. Consciousness: consciousness,
  1058. Appetite: appetite,
  1059. Condition: condition,
  1060. SickCondition: sick_condition,
  1061. DangerLevel: danger_level,
  1062. Intake: intake,
  1063. Nutrition: nutrition,
  1064. PsychologicalAssessment: psychological_assessment,
  1065. PsychologicalAssessmentOther: psychological_assessment_other,
  1066. SickConditionOther: sick_condition_other,
  1067. Posture: posture,
  1068. CreatedTime: time.Now().Unix(),
  1069. UpdateTime: time.Now().Unix(),
  1070. Status: 1,
  1071. Score: score,
  1072. Precaution: precaution,
  1073. PrecautionOther: precaution_other,
  1074. PsychologicalOther: psychological_other,
  1075. AdmissionNumber: admission_number,
  1076. Tumble: tumble,
  1077. Diacrisis: diacrisis,
  1078. HisBed: his_bed,
  1079. HisDepartment: his_department,
  1080. }
  1081. if receiveTreatment.ID == 0 { //新增
  1082. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1083. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1084. finish := models.XtDialysisFinish{
  1085. IsFinish: 1,
  1086. UserOrgId: adminUserInfo.Org.Id,
  1087. Status: 1,
  1088. Ctime: time.Now().Unix(),
  1089. Mtime: 0,
  1090. Module: 2,
  1091. RecordDate: recordDate.Unix(),
  1092. Sourse: 1,
  1093. PatientId: id,
  1094. }
  1095. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1096. if dialysisFinish.ID == 0 {
  1097. service.CreateDialysisFinish(finish)
  1098. }
  1099. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1100. redis := service.RedisClient()
  1101. defer redis.Close()
  1102. //清空key 值
  1103. redis.Set(key, "", time.Second)
  1104. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1105. redis.Set(keyOne, "", time.Second)
  1106. if err == nil {
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "receiveTreatmentAsses": receiveTreatmentAsses,
  1109. })
  1110. }
  1111. } else { //修改
  1112. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1113. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1114. // if getPermissionErr != nil {
  1115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1116. // return
  1117. // } else if headNursePermission == nil {
  1118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1119. // return
  1120. // }
  1121. //}
  1122. // 查询信息规挡的设置天数
  1123. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1124. if infor.ID > 0 && infor.WeekDay > 0 {
  1125. var cha_time int64
  1126. timeNowStr := time.Now().Format("2006-01-02")
  1127. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1128. //今日的日期减去设置的日期
  1129. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1130. if cha_time >= recordDate.Unix() {
  1131. //查询审核是否允许
  1132. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1133. //申请状态不允许的情况 拒绝修改
  1134. if infor.ApplicationStatus != 1 {
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1136. return
  1137. }
  1138. }
  1139. }
  1140. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1141. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1142. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1143. receiveTreatmentAsses.ID = receiveTreatment.ID
  1144. if adminUserInfo.Org.Id == 10340 {
  1145. if condition == 1 {
  1146. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1147. if receiveTreatmentAsses.AdmissionNumber == "" {
  1148. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1149. }
  1150. }
  1151. }
  1152. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1153. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1154. redis := service.RedisClient()
  1155. defer redis.Close()
  1156. //清空key 值
  1157. redis.Set(key, "", time.Second)
  1158. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1159. redis.Set(keyOne, "", time.Second)
  1160. if err == nil {
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "receiveTreatmentAsses": receiveTreatmentAsses,
  1163. })
  1164. }
  1165. }
  1166. }
  1167. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1168. id, _ := c.GetInt64("patient", 0)
  1169. recordDateStr := c.GetString("record_date")
  1170. weightAfter, _ := c.GetFloat("weight_after", 0)
  1171. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1172. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1173. fmt.Println("weight_loss", weightReduce)
  1174. temperature, _ := c.GetFloat("temperature", 0)
  1175. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1176. breathing_rate := c.GetString("breathing_rate")
  1177. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1178. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1179. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1180. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1181. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1182. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1183. cruor := c.GetString("cruor")
  1184. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1185. internalFistula := c.GetString("internal_fistula")
  1186. catheter := c.GetString("catheter")
  1187. complications := c.GetString("complication")
  1188. remark := c.GetString("remark")
  1189. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1190. dialysis_intakes := c.GetString("dialysis_intakes")
  1191. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1192. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1193. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1194. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1195. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1196. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1197. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1198. patientGose, _ := c.GetInt64("patient_gose", 0)
  1199. inpatientDepartment := c.GetString("inpatient_department")
  1200. observationContent := c.GetString("observation_content")
  1201. observationContentOther := c.GetString("observation_content_other")
  1202. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1203. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1204. in_advance_reason := c.GetString("in_advance_reason")
  1205. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1206. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1207. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1208. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1209. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1210. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1211. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1212. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1213. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1214. is_eat, _ := c.GetInt64("is_eat", 0)
  1215. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1216. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1217. channels, _ := c.GetInt64("channel", 0)
  1218. return_blood, _ := c.GetInt64("return_blood", 0)
  1219. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1220. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1221. dialysis_during, _ := c.GetFloat("dialysis_during")
  1222. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1223. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1224. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1225. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1226. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1227. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1228. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1229. setting_pressure := c.GetString("setting_pressure")
  1230. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1231. diastolic_pressure := c.GetString("diastolic_pressure")
  1232. other_complication := c.GetString("other_complication")
  1233. ktv := c.GetString("ktv")
  1234. urr := c.GetString("urr")
  1235. hypertenison, _ := c.GetInt64("hypertenison")
  1236. hypopiesia, _ := c.GetInt64("hypopiesia")
  1237. leave_office_method, _ := c.GetInt64("leave_office_method")
  1238. lapse, _ := c.GetInt64("lapse")
  1239. consciousness, _ := c.GetInt64("consciousness")
  1240. fallrisk, _ := c.GetInt64("fallrisk")
  1241. machine_run := c.GetString("machine_run")
  1242. after_urea := c.GetString("after_urea")
  1243. pip_coagulation := c.GetString("pip_coagulation")
  1244. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1245. transfusion_volume := c.GetString("transfusion_volume")
  1246. last_after_weight := c.GetString("last_after_weight")
  1247. displace_liqui_value := c.GetString("displace_liqui_value")
  1248. if id <= 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. adminUserInfo := c.GetMobileAdminUserInfo()
  1253. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1254. if patient.ID == 0 {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1256. return
  1257. }
  1258. if len(recordDateStr) == 0 {
  1259. recordDateStr = time.Now().Format("2006-01-02")
  1260. }
  1261. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1262. fmt.Println("parseDateErr", parseDateErr)
  1263. if parseDateErr != nil {
  1264. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. //now := time.Now()
  1269. //year, month, day := now.Date()
  1270. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1271. //todayTimeStamp := today_time.Unix()
  1272. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1273. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1274. UserOrgId: adminUserInfo.Org.Id,
  1275. PatientId: id,
  1276. AssessmentDate: recordDate.Unix(),
  1277. Temperature: temperature,
  1278. PulseFrequency: pulse_frequency,
  1279. BreathingRate: breathing_rate,
  1280. SystolicBloodPressure: systolic_blood_pressure,
  1281. DiastolicBloodPressure: diastolic_blood_pressure,
  1282. ActualUltrafiltration: actual_ultrafiltration,
  1283. ActualDisplacement: actual_displacement,
  1284. ActualTreatmentHour: actualtreatHour,
  1285. ActualTreatmentMinute: actualtreatmin,
  1286. WeightAfter: weightAfter,
  1287. AdditionalWeight: additionalWeight,
  1288. WeightLoss: weightReduce,
  1289. Cruor: cruor,
  1290. SymptomAfterDialysis: symptomsAfterDialysi,
  1291. InternalFistula: internalFistula,
  1292. Catheter: catheter,
  1293. Complication: complications,
  1294. DialysisIntakes: dialysateVolume,
  1295. CreatedTime: time.Now().Unix(),
  1296. UpdatedTime: time.Now().Unix(),
  1297. Status: 1,
  1298. Remark: remark,
  1299. BloodAccessPartId: blood_access_part_id,
  1300. BloodAccessPartOperaId: blood_access_part_opera_id,
  1301. DialysisIntakesUnit: dialysis_intakes_unit,
  1302. PuncturePointOozingBlood: puncturePointOozingBlood,
  1303. PuncturePointHaematoma: puncturePointHaematoma,
  1304. InternalFistulaTremorAc: internalFistulaTremorAc,
  1305. PatientGose: patientGose,
  1306. InpatientDepartment: inpatientDepartment,
  1307. ObservationContent: observationContent,
  1308. ObservationContentOther: observationContentOther,
  1309. DialysisProcess: dialysis_process,
  1310. InAdvanceMinute: in_advance_minute,
  1311. InAdvanceReason: in_advance_reason,
  1312. HemostasisMinute: hemostasis_minute,
  1313. HemostasisOpera: hemostasis_opera,
  1314. TremorNoise: tremor_noise,
  1315. DisequilibriumSyndrome: disequilibrium_syndrome,
  1316. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1317. ArterialTube: arterial_tube,
  1318. IntravenousTube: intravenous_tube,
  1319. Dialyzer: dialyzer,
  1320. InAdvanceReasonOther: in_advance_reason_other,
  1321. IsEat: is_eat,
  1322. CvcA: cvc_a,
  1323. CvcV: cvc_v,
  1324. Channel: channels,
  1325. ReturnBlood: return_blood,
  1326. RehydrationVolume: rehydration_volume,
  1327. DialysisDuring: dialysis_during,
  1328. StrokeVolume: stroke_volume,
  1329. BloodFlow: blood_flow,
  1330. SealingFluidDispose: sealing_fluid_dispose,
  1331. SealingFluidSpecial: sealing_fluid_special,
  1332. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1333. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1334. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1335. SettingPressure: setting_pressure,
  1336. DiastolicPressure: diastolic_pressure,
  1337. OtherComplication: other_complication,
  1338. Ktv: ktv,
  1339. Urr: urr,
  1340. Hypopiesia: hypopiesia,
  1341. Hypertenison: hypertenison,
  1342. Lapse: lapse,
  1343. LeaveOfficeMethod: leave_office_method,
  1344. Consciousness: consciousness,
  1345. Fallrisk: fallrisk,
  1346. MachineRun: machine_run,
  1347. AfterUrea: after_urea,
  1348. PipCoagulation: pip_coagulation,
  1349. AccumulatedBloodVolume: accumulated_blood_volume,
  1350. TransfusionVolume: transfusion_volume,
  1351. LastAfterWeight: last_after_weight,
  1352. DisplaceLiquiValue: displace_liqui_value,
  1353. }
  1354. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1355. // 查询信息规挡的设置天数
  1356. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1357. if infor.ID > 0 && infor.WeekDay > 0 {
  1358. var cha_time int64
  1359. timeNowStr := time.Now().Format("2006-01-02")
  1360. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1361. //今日的日期减去设置的日期
  1362. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1363. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1364. if cha_time >= recordDate.Unix() {
  1365. //查询审核是否允许
  1366. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1367. //申请状态不允许的情况 拒绝修改
  1368. if infor.ApplicationStatus != 1 {
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1370. return
  1371. }
  1372. }
  1373. }
  1374. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1375. if assessmentAfter.ID == 0 { //新增
  1376. if appRole.UserType == 2 || appRole.UserType == 1 {
  1377. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1378. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1379. } else {
  1380. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1381. }
  1382. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1383. if assessmentAfterDislysis.UserOrgId != 10340 {
  1384. if assessmentAfterDislysis.WeightAfter == 0 {
  1385. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1386. }
  1387. }
  1388. if adminUserInfo.Org.Id == 10693 {
  1389. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1390. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1391. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1392. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1393. }
  1394. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1395. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1396. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1397. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1398. }
  1399. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1400. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1401. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1402. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1403. }
  1404. if assessmentAfterDislysis.PulseFrequency == 0 {
  1405. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1406. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1407. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1408. }
  1409. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1410. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1411. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1412. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1413. }
  1414. }
  1415. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1416. //记录日志
  1417. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1418. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1419. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1420. PatientId: assessmentAfterDislysis.PatientId,
  1421. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1422. Status: 1,
  1423. ErrLog: string(byterequest),
  1424. AdminUserId: adminUserInfo.AdminUser.Id,
  1425. Ctime: 0,
  1426. Mtime: 0,
  1427. Source: "手机端保存透后评估",
  1428. }
  1429. service.CreateAfterDialysisLog(afterDialysisLog)
  1430. finish := models.XtDialysisFinish{
  1431. IsFinish: 1,
  1432. UserOrgId: adminUserInfo.Org.Id,
  1433. Status: 1,
  1434. Ctime: time.Now().Unix(),
  1435. Mtime: 0,
  1436. Module: 9,
  1437. RecordDate: recordDate.Unix(),
  1438. Sourse: 1,
  1439. PatientId: id,
  1440. }
  1441. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1442. if dialysisFinish.ID == 0 {
  1443. service.CreateDialysisFinish(finish)
  1444. }
  1445. redis := service.RedisClient()
  1446. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1447. redis.Set(keyTwo, "", time.Second)
  1448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1449. //清空key 值
  1450. redis.Set(key, "", time.Second)
  1451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1452. redis.Set(keyOne, "", time.Second)
  1453. defer redis.Close()
  1454. if err == nil {
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "assessmentAfterDislysis": assessmentAfterDislysis,
  1457. })
  1458. }
  1459. return
  1460. } else { //修改
  1461. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1462. if infor.ID > 0 && infor.WeekDay > 0 {
  1463. var cha_time int64
  1464. timeNowStr := time.Now().Format("2006-01-02")
  1465. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1466. //今日的日期减去设置的日期
  1467. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1468. if cha_time >= recordDate.Unix() {
  1469. //查询审核是否允许
  1470. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1471. //申请状态不允许的情况 拒绝修改
  1472. if infor.ApplicationStatus != 1 {
  1473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1474. return
  1475. }
  1476. }
  1477. }
  1478. if appRole.UserType == 2 || appRole.UserType == 1 {
  1479. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1480. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1481. } else {
  1482. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1483. if assessmentAfterDislysis.Creater == 0 {
  1484. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1485. }
  1486. }
  1487. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1488. assessmentAfterDislysis.ID = assessmentAfter.ID
  1489. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1490. if assessmentAfterDislysis.UserOrgId != 10340 {
  1491. if assessmentAfterDislysis.WeightAfter == 0 {
  1492. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1493. }
  1494. }
  1495. if adminUserInfo.Org.Id == 10693 {
  1496. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1497. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1498. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1499. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1500. }
  1501. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1502. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1503. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1504. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1505. }
  1506. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1507. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1508. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1509. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1510. }
  1511. if assessmentAfterDislysis.PulseFrequency == 0 {
  1512. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1513. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1514. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1515. }
  1516. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1517. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1518. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1519. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1520. }
  1521. }
  1522. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1523. //记录日志
  1524. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1525. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1526. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1527. PatientId: assessmentAfterDislysis.PatientId,
  1528. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1529. Status: 1,
  1530. ErrLog: string(byterequest),
  1531. AdminUserId: adminUserInfo.AdminUser.Id,
  1532. Ctime: time.Now().Unix(),
  1533. Mtime: 0,
  1534. Source: "手机端修改保存透后评估",
  1535. }
  1536. service.CreateAfterDialysisLog(afterDialysisLog)
  1537. redis := service.RedisClient()
  1538. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1539. redis.Set(keyTwo, "", time.Second)
  1540. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1541. //清空key 值
  1542. redis.Set(key, "", time.Second)
  1543. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1544. redis.Set(keyOne, "", time.Second)
  1545. if err == nil {
  1546. c.ServeSuccessJSON(map[string]interface{}{
  1547. "assessmentAfterDislysis": assessmentAfterDislysis,
  1548. })
  1549. return
  1550. }
  1551. }
  1552. return
  1553. }
  1554. func (c *DialysisAPIController) PostDialysisPrescription() {
  1555. id, _ := c.GetInt64("patient", 0)
  1556. recordDateStr := c.GetString("record_date")
  1557. if id <= 0 {
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1559. return
  1560. }
  1561. adminUserInfo := c.GetMobileAdminUserInfo()
  1562. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1563. if patient.ID == 0 {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1565. return
  1566. }
  1567. if len(recordDateStr) == 0 {
  1568. recordDateStr = time.Now().Format("2006-01-02")
  1569. }
  1570. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1571. if parseDateErr != nil {
  1572. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. mode_id, _ := c.GetInt64("mode_id", 0)
  1577. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1578. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1579. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1580. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1581. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1582. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1583. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1584. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1585. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1586. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1587. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1588. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1589. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1590. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1591. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1592. kalium, _ := c.GetFloat("kalium", 0)
  1593. sodium, _ := c.GetFloat("sodium", 0)
  1594. calcium, _ := c.GetFloat("calcium", 0)
  1595. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1596. glucose, _ := c.GetFloat("glucose", 0)
  1597. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1598. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1599. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1600. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1601. conductivity, _ := c.GetFloat("conductivity", 0)
  1602. remark := c.GetString("remark")
  1603. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1604. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1605. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1606. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1607. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1608. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1609. special_medicine_other := c.GetString("special_medicine_other")
  1610. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1611. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1612. blood_access, _ := c.GetInt64("blood_access", 0)
  1613. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1614. body_fluid_other := c.GetString("body_fluid_other")
  1615. niprocart, _ := c.GetInt64("niprocart", 0)
  1616. jms, _ := c.GetInt64("jms", 0)
  1617. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1618. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1619. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1620. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1621. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1622. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1623. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1624. injector, _ := c.GetInt64("injector", 0)
  1625. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1626. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1627. safe_package, _ := c.GetInt64("package", 0)
  1628. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1629. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1630. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1631. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1632. blood := c.GetString("blood")
  1633. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1634. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1635. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1636. displace_speed := c.GetString("displace_speed")
  1637. illness, _ := c.GetInt64("illness")
  1638. amylaceum := c.GetString("amylaceum")
  1639. single_time := c.GetString("single_time")
  1640. single_water := c.GetString("single_water")
  1641. replacement_flow := c.GetString("replacement_flow")
  1642. plasma_separator := c.GetString("plasma_separator")
  1643. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1644. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1645. oxygen_flow := c.GetString("oxygen_flow")
  1646. oxygen_time := c.GetString("oxygen_time")
  1647. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1648. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1649. puncture_needle := c.GetString("puncture_needle")
  1650. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1651. epo := c.GetString("epo")
  1652. epo_count, _ := c.GetFloat("epo_count", 0)
  1653. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1654. admin_user_id, _ := c.GetInt64("admin_user_id")
  1655. is_water := c.GetString("is_water")
  1656. var is_war int64
  1657. if is_water == "是" {
  1658. is_war = 1
  1659. }
  1660. if is_water == "否" {
  1661. is_war = 2
  1662. }
  1663. if is_water == "请选择" {
  1664. is_war = 0
  1665. }
  1666. drhy_water := c.GetString("drhy_water")
  1667. dry_water_hour := c.GetString("dry_water_hour")
  1668. water_machine := c.GetString("water_machine")
  1669. add_amount, _ := c.GetFloat("add_amount")
  1670. reduce_amount, _ := c.GetFloat("reduce_amount")
  1671. dialysis_remark := c.GetString("dialysis_remark")
  1672. prescribing_number, _ := c.GetFloat("prescribing_number")
  1673. prescription_sodium := c.GetString("prescription_sodium")
  1674. start_sodium := c.GetString("start_sodium")
  1675. sodium_curve := c.GetString("sodium_curve")
  1676. treatment_remark := c.GetString("treatment_remark")
  1677. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1678. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1679. prescription_water, _ := c.GetFloat("prescription_water")
  1680. dialysis_strainer := c.GetString("dialysis_strainer")
  1681. chaptalization := c.GetString("chaptalization")
  1682. washing_time := c.GetString("washing_time")
  1683. warsh_count := c.GetString("warsh_count")
  1684. blood_access_part_id := c.GetString("blood_access_part_id")
  1685. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1686. dialyzate := c.GetString("dialyzate")
  1687. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1688. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1689. //
  1690. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1691. // if appRole.UserType == 3 {
  1692. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1693. // if getPermissionErr != nil {
  1694. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1695. // return
  1696. // } else if headNursePermission == nil {
  1697. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1698. // return
  1699. // }
  1700. // }
  1701. //}
  1702. // 查询信息规挡的设置天数
  1703. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1704. if infor.ID > 0 && infor.WeekDay > 0 {
  1705. var cha_time int64
  1706. timeNowStr := time.Now().Format("2006-01-02")
  1707. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1708. //今日的日期减去设置的日期
  1709. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1710. if cha_time >= recordDate.Unix() {
  1711. //查询审核是否允许
  1712. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1713. //申请状态不允许的情况 拒绝修改
  1714. if infor.ApplicationStatus != 1 {
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1716. return
  1717. }
  1718. }
  1719. }
  1720. if mode_id > 0 {
  1721. var str string
  1722. //查找该机构用的是什么透析器
  1723. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1724. if filedConfig.ID > 0 {
  1725. str = dialyzerPerfusionApparatus
  1726. } else {
  1727. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1728. }
  1729. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1730. }
  1731. //TODO 需要根据角色去判断
  1732. prescription := models.DialysisPrescription{
  1733. UserOrgId: adminUserInfo.Org.Id,
  1734. PatientId: id,
  1735. RecordDate: recordDate.Unix(),
  1736. ModeId: mode_id,
  1737. DialysisDuration: dialysis_duration,
  1738. Dialyzer: dialyzer,
  1739. PerfusionApparatus: perfusion_apparatus,
  1740. BloodFlowVolume: blood_flow_volume,
  1741. DewaterAmount: dewater_amount,
  1742. DisplaceLiqui: displace_liqui,
  1743. ReplacementWay: replacement_way,
  1744. Anticoagulant: anticoagulant,
  1745. AnticoagulantShouji: anticoagulant_shouji,
  1746. AnticoagulantWeichi: anticoagulant_weichi,
  1747. AnticoagulantZongliang: anticoagulant_zongliang,
  1748. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1749. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1750. Kalium: kalium,
  1751. Sodium: sodium,
  1752. Calcium: calcium,
  1753. Bicarbonate: bicarbonate,
  1754. Glucose: glucose,
  1755. // DryWeight: dry_weight,
  1756. DialysateFlow: dialysate_flow,
  1757. DialysateTemperature: dialysate_temperature,
  1758. // PrescriptionDoctor: prescription_doctor,
  1759. ReplacementTotal: replacement_total,
  1760. Conductivity: conductivity,
  1761. Remark: remark,
  1762. Status: 1,
  1763. CreatedTime: time.Now().Unix(),
  1764. UpdatedTime: time.Now().Unix(),
  1765. DialysisDurationMinute: dialysisDurationMinute,
  1766. DialysisDurationHour: dialysisDurationHour,
  1767. TargetUltrafiltration: targetUltrafiltration,
  1768. DialysateFormulation: dialysateFormulation,
  1769. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1770. BodyFluid: body_fluid,
  1771. SpecialMedicine: special_medicine,
  1772. SpecialMedicineOther: special_medicine_other,
  1773. DisplaceLiquiPart: displace_liqui_part,
  1774. DisplaceLiquiValue: displace_liqui_value,
  1775. BloodAccess: blood_access,
  1776. Ultrafiltration: ultrafiltration,
  1777. BodyFluidOther: body_fluid_other,
  1778. Niprocart: niprocart,
  1779. Jms: jms,
  1780. FistulaNeedleSet: fistula_needle_set,
  1781. FistulaNeedleSet16: fistula_needle_set_16,
  1782. Hemoperfusion: hemoperfusion,
  1783. DialyserSterilised: dialyser_sterilised,
  1784. Filtryzer: filtryzer,
  1785. Dialyzers: dialyzers,
  1786. Injector: injector,
  1787. Bloodlines: bloodlines,
  1788. TubingHemodialysis: tubing_hemodialysis,
  1789. Package: safe_package,
  1790. ALiquid: a_liquid,
  1791. TargetKtv: target_ktv,
  1792. PreImpulse: pre_impulse,
  1793. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1794. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1795. Blood: blood,
  1796. DialysisDialyszers: dialysis_dialyszers,
  1797. DialysisIrrigation: dialysis_irrigation,
  1798. AntioxidantCommodityName: antioxidant_commodity_name,
  1799. DisplaceSpeed: displace_speed,
  1800. Illness: illness,
  1801. Amylaceum: amylaceum,
  1802. SingleTime: single_time,
  1803. SingleWater: single_water,
  1804. ReplacementFlow: replacement_flow,
  1805. PlasmaSeparator: plasma_separator,
  1806. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1807. OxygenUptake: oxygen_uptake,
  1808. OxygenFlow: oxygen_flow,
  1809. OxygenTime: oxygen_time,
  1810. HemodialysisPipelines: hemodialysis_pipelines,
  1811. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1812. PunctureNeedle: puncture_needle,
  1813. PunctureNeedleCount: puncture_needle_count,
  1814. Epo: epo,
  1815. EpoCount: epo_count,
  1816. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1817. AdminUserId: admin_user_id,
  1818. IsWater: is_war,
  1819. DrhyWater: drhy_water,
  1820. DryWaterHour: dry_water_hour,
  1821. WaterMachine: water_machine,
  1822. AddAmount: add_amount,
  1823. ReduceAmount: reduce_amount,
  1824. DialysisRemark: dialysis_remark,
  1825. PrescribingNumber: prescribing_number,
  1826. StartSodium: start_sodium,
  1827. SodiumCurve: sodium_curve,
  1828. TreatmentRemark: treatment_remark,
  1829. PrescriptionSodium: prescription_sodium,
  1830. DialysisFluidFlow: dialysis_fluid_flow,
  1831. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1832. PrescriptionWater: prescription_water,
  1833. DialysisStrainer: dialysis_strainer,
  1834. Chaptalization: chaptalization,
  1835. WashingTime: washing_time,
  1836. WarshCount: warsh_count,
  1837. BloodAccessPartId: blood_access_part_id,
  1838. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1839. Dialyzate: dialyzate,
  1840. }
  1841. //查询最近透析准备表里是否存在 透析器 灌流器
  1842. //
  1843. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1844. //
  1845. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1846. //
  1847. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1848. //if len(mation)>0{
  1849. // for _, item := range splitStr {
  1850. // for _,it := range mation{
  1851. // if(item == it.SpecificationName){
  1852. //
  1853. // //查询最近一次的透析器
  1854. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1855. //
  1856. // if errcode == gorm.ErrRecordNotFound{
  1857. // //插入数据
  1858. // prepare := models.DialysisBeforePrepare{
  1859. // UserOrgId: adminUserInfo.Org.Id,
  1860. // PatientId: id,
  1861. // RecordDate: recordDate.Unix(),
  1862. // GoodTypeId: it.GoodTypeId,
  1863. // GoodId: it.ID,
  1864. // Count: 1,
  1865. // Ctime: time.Now().Unix(),
  1866. // Creater: adminUserInfo.AdminUser.Id,
  1867. // Status:1,
  1868. //
  1869. // }
  1870. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1871. // fmt.Println("",errcode)
  1872. // }
  1873. // }
  1874. // }
  1875. //
  1876. // }
  1877. //
  1878. // for _, item := range splitIrrigation {
  1879. // for _,it := range mation{
  1880. // if(item == it.SpecificationName){
  1881. // //查询最近一次的透析器
  1882. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1883. // if errcode == gorm.ErrRecordNotFound{
  1884. // //插入数据
  1885. // prepare := models.DialysisBeforePrepare{
  1886. // UserOrgId: adminUserInfo.Org.Id,
  1887. // PatientId: id,
  1888. // RecordDate: recordDate.Unix(),
  1889. // GoodTypeId: it.GoodTypeId,
  1890. // GoodId: it.ID,
  1891. // Count: 1,
  1892. // Ctime: time.Now().Unix(),
  1893. // Creater: adminUserInfo.AdminUser.Id,
  1894. // Status:1,
  1895. //
  1896. // }
  1897. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1898. // fmt.Println(errcode)
  1899. // }
  1900. // }
  1901. // }
  1902. // }
  1903. //}
  1904. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1905. if dialysisPrescription.ID == 0 { //新增
  1906. if appRole.UserType == 2 || appRole.UserType == 1 {
  1907. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1908. }
  1909. prescription.Creater = adminUserInfo.AdminUser.Id
  1910. //针对河间咸得
  1911. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1912. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1913. prescription.DisplaceLiquiPart = 0
  1914. prescription.DisplaceLiquiValue = 0
  1915. }
  1916. }
  1917. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1918. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1919. }
  1920. err := service.AddSigleRecord(&prescription)
  1921. //记录日志
  1922. byterequest, _ := json.Marshal(prescription)
  1923. prescriptionLog := models.XtDialysisPrescriptionLog{
  1924. UserOrgId: prescription.UserOrgId,
  1925. Ctime: time.Now().Unix(),
  1926. Mtime: 0,
  1927. ErrLog: string(byterequest),
  1928. AdminUserId: adminUserInfo.AdminUser.Id,
  1929. RecordDate: prescription.RecordDate,
  1930. PatientId: prescription.PatientId,
  1931. Source: "手机端新增保存处方",
  1932. Status: 1,
  1933. }
  1934. service.CreatePrescriptionLog(prescriptionLog)
  1935. finish := models.XtDialysisFinish{
  1936. IsFinish: 1,
  1937. UserOrgId: adminUserInfo.Org.Id,
  1938. Status: 1,
  1939. Ctime: time.Now().Unix(),
  1940. Mtime: 0,
  1941. Module: 1,
  1942. RecordDate: recordDate.Unix(),
  1943. Sourse: 1,
  1944. PatientId: id,
  1945. }
  1946. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1947. if dialysisFinish.ID == 0 {
  1948. service.CreateDialysisFinish(finish)
  1949. }
  1950. //长沙南雅医院,自动生成抗凝剂的临时处方
  1951. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1952. if prescribing_number == 0 {
  1953. prescribing_number = 1
  1954. }
  1955. if prescribing_number == 0 && id == 14682 {
  1956. prescribing_number = 2
  1957. }
  1958. if prescribing_number == 0 && id == 18560 {
  1959. prescribing_number = 2
  1960. }
  1961. advice := models.DoctorAdvice{
  1962. UserOrgId: adminUserInfo.Org.Id,
  1963. PatientId: id,
  1964. GroupNo: 0,
  1965. AdviceType: 2,
  1966. RecordDate: recordDate.Unix(),
  1967. AdviceDate: recordDate.Unix(),
  1968. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1969. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1970. AdviceDesc: "",
  1971. ReminderDate: 0,
  1972. SingleDose: anticoagulant_zongliang,
  1973. SingleDoseUnit: "iu",
  1974. DrugSpec: 0,
  1975. DrugSpecUnit: "",
  1976. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1977. PrescribingNumberUnit: "支",
  1978. DeliveryWay: "静脉注射",
  1979. ExecutionFrequency: "上机前",
  1980. AdviceDoctor: 0,
  1981. Status: 1,
  1982. CreatedTime: time.Now().Unix(),
  1983. UpdatedTime: time.Now().Unix(),
  1984. IsPrescription: 1,
  1985. ExecutionState: 2,
  1986. StopState: 2,
  1987. IsSettle: 2,
  1988. }
  1989. // 查询排班信息
  1990. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1991. if schedulePatient.ID > 0 {
  1992. if schedulePatient.ScheduleType == 1 {
  1993. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1994. }
  1995. if schedulePatient.ScheduleType == 2 {
  1996. advice.StartTime = recordDate.Unix() + 9*60*60
  1997. }
  1998. }
  1999. // 抗凝剂名称
  2000. switch anticoagulant {
  2001. case 1:
  2002. advice.AdviceName = "无肝素"
  2003. break
  2004. case 2:
  2005. advice.AdviceName = "普通肝素"
  2006. break
  2007. case 3:
  2008. advice.AdviceName = "低分子肝素"
  2009. break
  2010. case 4:
  2011. advice.AdviceName = "阿加曲班"
  2012. break
  2013. case 5:
  2014. advice.AdviceName = "枸橼酸钠"
  2015. break
  2016. case 6:
  2017. advice.AdviceName = "低分子肝素钙"
  2018. break
  2019. case 7:
  2020. advice.AdviceName = "低分子肝素钠"
  2021. break
  2022. case 8:
  2023. advice.AdviceName = "依诺肝素"
  2024. break
  2025. case 9:
  2026. advice.AdviceName = "达肝素"
  2027. break
  2028. case 10:
  2029. advice.AdviceName = "体外抗凝"
  2030. break
  2031. case 11:
  2032. advice.AdviceName = "那曲肝素"
  2033. break
  2034. case 12:
  2035. advice.AdviceName = "无抗凝剂"
  2036. break
  2037. }
  2038. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2039. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2040. advice.AdviceDoctor = appRole.AdminUserId
  2041. }
  2042. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2043. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2044. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2045. advice.AdviceName = "低分子肝素钠注射液"
  2046. // 修改患者临时医嘱里的抗凝剂医嘱
  2047. advice.ID = advicePrescription.ID
  2048. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2049. } else {
  2050. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2051. advice.AdviceName = "低分子肝素钠注射液"
  2052. // 新增患者临时医嘱里的抗凝剂医嘱
  2053. service.CreateDoctorAdvice(&advice)
  2054. }
  2055. }
  2056. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2057. redis := service.RedisClient()
  2058. defer redis.Close()
  2059. //清空key 值
  2060. redis.Set(key, "", time.Second)
  2061. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2062. redis.Set(keyOne, "", time.Second)
  2063. }
  2064. //获取key,清空redis
  2065. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2066. redis := service.RedisClient()
  2067. //清空key 值
  2068. redis.Set(key, "", time.Second)
  2069. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2070. //清空key 值
  2071. redis.Set(keyOne, "", time.Second)
  2072. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2073. //清空key 值
  2074. redis.Set(keyTwo, "", time.Second)
  2075. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2076. redis.Set(keySix, "", time.Second)
  2077. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2078. redis.Set(keySeven, "", time.Second)
  2079. if err == nil {
  2080. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2081. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2082. //清空key 值
  2083. redis.Set(keyThree, "", time.Second)
  2084. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2085. //清空key 值
  2086. redis.Set(keyFour, "", time.Second)
  2087. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2088. redis.Set(keyFive, "", time.Second)
  2089. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2090. redis.Set(keySix, "", time.Second)
  2091. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2092. redis.Set(keySeven, "", time.Second)
  2093. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2094. //清空key 值
  2095. redis.Set(keyOne, "", time.Second)
  2096. if updateErr != nil {
  2097. utils.ErrorLog("%v", updateErr)
  2098. }
  2099. defer redis.Close()
  2100. c.ServeSuccessJSON(map[string]interface{}{
  2101. "prescription": prescription,
  2102. })
  2103. }
  2104. } else { //修改
  2105. //if mode_id > 0 {
  2106. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2107. //}
  2108. //if template.TemplateId == 1 {
  2109. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2111. // if getPermissionErr != nil {
  2112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2113. // return
  2114. // } else if headNursePermission == nil {
  2115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2116. // return
  2117. // }
  2118. // }
  2119. //}
  2120. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2121. prescription.Modifier = adminUserInfo.AdminUser.Id
  2122. if appRole.UserType == 2 || appRole.UserType == 1 {
  2123. prescription_doctor := adminUserInfo.AdminUser.Id
  2124. prescription.PrescriptionDoctor = prescription_doctor
  2125. } else {
  2126. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2127. }
  2128. if dialysisPrescription.Creater == 0 { //体重称
  2129. prescription.Creater = adminUserInfo.AdminUser.Id
  2130. } else {
  2131. prescription.Creater = dialysisPrescription.Creater
  2132. if adminUserInfo.Org.Id == 9882 {
  2133. if appRole.UserType == 2 || appRole.UserType == 1 {
  2134. prescription_doctor := adminUserInfo.AdminUser.Id
  2135. prescription.PrescriptionDoctor = prescription_doctor
  2136. prescription.Creater = prescription_doctor
  2137. }
  2138. }
  2139. }
  2140. prescription.ID = dialysisPrescription.ID
  2141. service.UpDateDialysisPrescription(&prescription)
  2142. //记录日志
  2143. byterequest, _ := json.Marshal(prescription)
  2144. prescriptionLog := models.XtDialysisPrescriptionLog{
  2145. UserOrgId: prescription.UserOrgId,
  2146. Ctime: time.Now().Unix(),
  2147. Mtime: 0,
  2148. ErrLog: string(byterequest),
  2149. AdminUserId: adminUserInfo.AdminUser.Id,
  2150. RecordDate: prescription.RecordDate,
  2151. PatientId: prescription.PatientId,
  2152. Source: "手机端修改处方",
  2153. Status: 1,
  2154. }
  2155. service.CreatePrescriptionLog(prescriptionLog)
  2156. finish := models.XtDialysisFinish{
  2157. IsFinish: 1,
  2158. UserOrgId: adminUserInfo.Org.Id,
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Module: 1,
  2163. RecordDate: recordDate.Unix(),
  2164. Sourse: 1,
  2165. PatientId: id,
  2166. }
  2167. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2168. if dialysisFinish.ID == 0 {
  2169. service.CreateDialysisFinish(finish)
  2170. }
  2171. //修改处方
  2172. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2173. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2174. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. if advicePrescription.ID > 0 {
  2176. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2177. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2178. redis := service.RedisClient()
  2179. defer redis.Close()
  2180. //清空key 值
  2181. redis.Set(key, "", time.Second)
  2182. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2183. redis.Set(keyOne, "", time.Second)
  2184. }
  2185. }
  2186. //获取key,清空redis
  2187. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2188. redis := service.RedisClient()
  2189. //清空key 值
  2190. redis.Set(key, "", time.Second)
  2191. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2192. //清空key 值
  2193. redis.Set(keyOne, "", time.Second)
  2194. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2195. redis.Set(keySix, "", time.Second)
  2196. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2197. redis.Set(keySeven, "", time.Second)
  2198. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2199. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2200. //清空key 值
  2201. redis.Set(keyTwoOne, "", time.Second)
  2202. defer redis.Close()
  2203. if updateErr != nil {
  2204. utils.ErrorLog("%v", updateErr)
  2205. }
  2206. c.ServeSuccessJSON(map[string]interface{}{
  2207. "prescription": prescription,
  2208. })
  2209. }
  2210. }
  2211. func (c *DialysisAPIController) Finish() {
  2212. id, _ := c.GetInt64("patient", 0)
  2213. recordDateStr := c.GetString("record_date")
  2214. nurseID, _ := c.GetInt64("nurse")
  2215. end_time := c.GetString("end_time")
  2216. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2217. internal_fistula := c.GetString("blood_access_internal_fistula")
  2218. catheter := c.GetString("catheter")
  2219. cruor := c.GetString("cruor")
  2220. mission := c.GetString("mission")
  2221. condenser := c.GetString("condenser")
  2222. if id <= 0 || nurseID <= 0 {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. adminUserInfo := c.GetMobileAdminUserInfo()
  2227. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2228. if patient.ID == 0 {
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2230. return
  2231. }
  2232. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2233. if getNurseErr != nil {
  2234. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2236. return
  2237. } else if nurse == nil {
  2238. c.ErrorLog("护士不存在")
  2239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2240. return
  2241. }
  2242. if len(recordDateStr) == 0 {
  2243. recordDateStr = time.Now().Format("2006-01-02")
  2244. }
  2245. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2246. if parseDateErr != nil {
  2247. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2249. return
  2250. }
  2251. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2252. if parseEndDateErr != nil {
  2253. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2255. return
  2256. }
  2257. // 查询信息规挡的设置天数
  2258. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2259. if infor.ID > 0 && infor.WeekDay > 0 {
  2260. var cha_time int64
  2261. timeNowStr := time.Now().Format("2006-01-02")
  2262. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2263. //今日的日期减去设置的日期
  2264. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2265. if cha_time >= recordDate.Unix() {
  2266. //查询审核是否允许
  2267. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2268. //申请状态不允许的情况 拒绝修改
  2269. if infor.ApplicationStatus != 1 {
  2270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2271. return
  2272. }
  2273. }
  2274. }
  2275. //now := time.Now()
  2276. //year, month, day := now.Date()
  2277. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2278. //todayTimeStamp := today_time.Unix()
  2279. // 获取当天的第一条透析纪录
  2280. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2281. if getMonitorRecordsErr != nil {
  2282. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. return
  2285. }
  2286. // 获取当前的最后一条透析纪录
  2287. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2288. if getMonitorRecordsErr != nil {
  2289. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2291. return
  2292. }
  2293. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2294. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2295. if getAADErr != nil {
  2296. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2298. return
  2299. }
  2300. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2301. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2304. if assessmentAfterDislysis != nil {
  2305. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2306. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2307. } else {
  2308. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2309. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2310. tempassessmentAfterDislysis.Status = 1
  2311. tempassessmentAfterDislysis.PatientId = id
  2312. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2313. }
  2314. //长沙南雅
  2315. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2316. //获取最后一条透析处方数据
  2317. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2318. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2320. }
  2321. if dialysisOrder.Stage == 1 {
  2322. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2323. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2324. fmt.Println(value)
  2325. a, b := math.Modf(value)
  2326. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2327. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2328. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2329. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2330. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2331. }
  2332. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2333. //var num1 int64
  2334. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2335. //fmt.Println(num1)
  2336. //sub := float64(num1 / 3600)
  2337. //fmt.Println(sub)
  2338. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2339. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2340. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2341. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2342. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2343. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2344. if adminUserInfo.Org.Id != 10375 {
  2345. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2346. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2347. }
  2348. if adminUserInfo.Org.Id != 10445 {
  2349. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2350. }
  2351. //北方营口医院
  2352. if adminUserInfo.Org.Id == 10445 {
  2353. //获取最后一条透析处方数据
  2354. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2355. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2356. } else {
  2357. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2358. }
  2359. //新化博翔
  2360. if adminUserInfo.Org.Id == 10447 {
  2361. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2362. }
  2363. //阳春
  2364. if adminUserInfo.Org.Id == 10485 {
  2365. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2366. }
  2367. if adminUserInfo.Org.Id == 10551 {
  2368. //获取最后一条透析处方数据
  2369. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2370. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2371. }
  2372. if adminUserInfo.Org.Id == 10580 {
  2373. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2374. }
  2375. if adminUserInfo.Org.Id == 10612 {
  2376. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2377. }
  2378. //孝康
  2379. if adminUserInfo.Org.Id == 10693 {
  2380. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2381. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2382. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2383. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2384. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2385. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2386. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2387. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2388. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2389. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2390. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2391. }
  2392. if adminUserInfo.Org.Id == 10721 {
  2393. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2394. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2395. }
  2396. if adminUserInfo.Org.Id == 10697 {
  2397. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2398. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2399. lastWeightAfter.LastAfterWeight = floatAfeter
  2400. }
  2401. }
  2402. 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 {
  2403. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2404. if evaluation.SystolicBloodPressure == 0 {
  2405. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2406. if adminUserInfo.Org.Id == 10693 {
  2407. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2408. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2409. }
  2410. pre := models.PredialysisEvaluation{
  2411. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2412. }
  2413. fmt.Println("prew", pre)
  2414. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2415. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2417. redis := service.RedisClient()
  2418. redis.Set(key, "", time.Second)
  2419. redis.Set(keyOne, "", time.Second)
  2420. defer redis.Close()
  2421. fmt.Println(getNurseErr)
  2422. }
  2423. if evaluation.DiastolicBloodPressure == 0 {
  2424. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2425. if adminUserInfo.Org.Id == 10693 {
  2426. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2427. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2428. }
  2429. pres := models.PredialysisEvaluation{
  2430. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2431. }
  2432. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2433. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2434. redis := service.RedisClient()
  2435. redis.Set(key, "", time.Second)
  2436. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2437. redis.Set(keyOne, "", time.Second)
  2438. defer redis.Close()
  2439. fmt.Println(getNurseErr)
  2440. }
  2441. if evaluation.PulseFrequency == 0 {
  2442. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2443. if adminUserInfo.Org.Id == 10693 {
  2444. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2445. evaluation.PulseFrequency = pulseFrequency
  2446. }
  2447. press := models.PredialysisEvaluation{
  2448. PulseFrequency: evaluation.PulseFrequency,
  2449. }
  2450. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2451. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2452. redis := service.RedisClient()
  2453. redis.Set(key, "", time.Second)
  2454. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2455. redis.Set(keyOne, "", time.Second)
  2456. defer redis.Close()
  2457. fmt.Println(getNurseErr)
  2458. }
  2459. if evaluation.Temperature == 0 {
  2460. evaluation.Temperature = fmonitorRecords.Temperature
  2461. press := models.PredialysisEvaluation{
  2462. Temperature: evaluation.Temperature,
  2463. }
  2464. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2465. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2466. redis := service.RedisClient()
  2467. redis.Set(key, "", time.Second)
  2468. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2469. redis.Set(keyOne, "", time.Second)
  2470. defer redis.Close()
  2471. fmt.Println(getNurseErr)
  2472. }
  2473. }
  2474. if adminUserInfo.Org.Id == 9583 {
  2475. //获取透析处方的最后一条数据
  2476. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if diaerr != nil {
  2478. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2483. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2484. }
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2496. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2497. }
  2498. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2499. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2500. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2501. }
  2502. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2505. }
  2506. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2507. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2508. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2509. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2510. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2511. }
  2512. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2513. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2514. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2515. }
  2516. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2517. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2518. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2519. }
  2520. if lastAssessmentAfterDislysis != nil {
  2521. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2522. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2523. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2524. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2525. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2526. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2527. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2528. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2529. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2530. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2531. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2532. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2533. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2534. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2535. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2536. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2537. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2538. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2539. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2540. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2541. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2542. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2543. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2544. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2545. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2546. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2547. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2548. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2549. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2550. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2551. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2552. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2553. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2554. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2555. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2556. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2557. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2558. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2559. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2560. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2561. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2562. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2563. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2564. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2565. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2566. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2567. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2568. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2569. if tempassessmentAfterDislysis.PatientId == 18695 {
  2570. tempassessmentAfterDislysis.ActualDisplacement = 0
  2571. }
  2572. if adminUserInfo.Org.Id != 10375 {
  2573. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2574. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2575. }
  2576. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2577. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2578. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2579. }
  2580. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2581. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. }
  2584. }
  2585. finish := models.XtDialysisFinish{
  2586. IsFinish: 1,
  2587. UserOrgId: adminUserInfo.Org.Id,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. Module: 9,
  2592. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2593. Sourse: 1,
  2594. PatientId: tempassessmentAfterDislysis.PatientId,
  2595. }
  2596. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2597. if dialysisFinish.ID == 0 {
  2598. service.CreateDialysisFinish(finish)
  2599. }
  2600. //孝康
  2601. if adminUserInfo.Org.Id == 10693 {
  2602. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2603. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2604. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2605. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2606. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2607. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2608. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2609. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2610. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2612. }
  2613. if adminUserInfo.Org.Id == 10697 {
  2614. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2615. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2616. lastWeightAfter.LastAfterWeight = floatAfeter
  2617. }
  2618. if adminUserInfo.Org.Id == 10721 {
  2619. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2620. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2621. }
  2622. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2624. redis := service.RedisClient()
  2625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2626. redis.Set(keyOne, "", time.Second)
  2627. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2628. redis.Set(keyTwo, "", time.Second)
  2629. defer redis.Close()
  2630. //清空key 值
  2631. redis.Set(key, "", time.Second)
  2632. if err != nil {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2634. return
  2635. }
  2636. if dialysisOrder == nil {
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2638. return
  2639. }
  2640. if dialysisOrder.Stage == 2 {
  2641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2642. return
  2643. }
  2644. if dialysisOrder.Stage == 1 {
  2645. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2646. finish := models.XtDialysisFinish{
  2647. IsFinish: 1,
  2648. UserOrgId: adminUserInfo.Org.Id,
  2649. Status: 1,
  2650. Ctime: time.Now().Unix(),
  2651. Mtime: 0,
  2652. Module: 8,
  2653. RecordDate: recordDate.Unix(),
  2654. Sourse: 1,
  2655. PatientId: id,
  2656. }
  2657. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2658. if dialysisFinish.ID == 0 {
  2659. service.CreateDialysisFinish(finish)
  2660. }
  2661. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2662. redis := service.RedisClient()
  2663. defer redis.Close()
  2664. //清空key 值
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2667. redis.Set(keyOne, "", time.Second)
  2668. //结束时候透析次数加1
  2669. service.UpdateSolutionByPatientId(id)
  2670. //下机完自动消毒,针对长沙南雅
  2671. if dialysisOrder.Stage == 1 {
  2672. 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 {
  2673. //根据床位号获取设备型号
  2674. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2675. //查询使用消毒最后一条消毒记录
  2676. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2677. fmt.Println("err", err)
  2678. if err == gorm.ErrRecordNotFound {
  2679. //查找排班
  2680. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2681. //查询改设备是否有消毒计划
  2682. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2683. //根据床位号获取设备id
  2684. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2685. //查询病人信息
  2686. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2687. var con = ""
  2688. if patients.IsInfectious == 0 {
  2689. con = ""
  2690. }
  2691. if patients.IsInfectious == 1 {
  2692. con = "无"
  2693. }
  2694. if patients.IsInfectious == 2 {
  2695. con = "有"
  2696. }
  2697. if errcode == nil {
  2698. var end_time int64
  2699. end_time = endDate.Unix() + plan.DisinfecTime*60
  2700. //新增消毒
  2701. information := models.DeviceInformation{
  2702. Date: dialysisOrder.DialysisDate,
  2703. Zone: dialysisOrder.ZoneId,
  2704. Class: dialysisOrder.SchedualType,
  2705. BedNumber: dialysisOrder.BedID,
  2706. PatientId: dialysisOrder.PatientId,
  2707. DialysisMode: scheduleByPatient.ModeId,
  2708. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2709. Disinfection: 1,
  2710. DialysisConcentration: 1,
  2711. DisinfectionStatus: 1,
  2712. Move: 1,
  2713. UserOrgId: dialysisOrder.UserOrgId,
  2714. DisinfectType: plan.Way,
  2715. DisinfectantType: plan.MachineDisinfectant,
  2716. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2717. Disinfectant: plan.Disinfectant,
  2718. Ctime: time.Now().Unix(),
  2719. Status: 1,
  2720. SignName: nurseID,
  2721. EquimentId: addmacher.ID,
  2722. DisinfectionResidue: 2,
  2723. Bed: addmacher.BedNumber,
  2724. StartTime: dialysisOrder.StartTime,
  2725. EndTime: dialysisOrder.EndTime,
  2726. Contagion: con,
  2727. WeightLoss: 0,
  2728. Hyperfiltratio: 0,
  2729. DialysisHour: "",
  2730. MachineRun: 1,
  2731. DisinfecStartime: endDate.Unix(),
  2732. DisinfecEndtime: end_time,
  2733. }
  2734. err := service.CreateInformationTwo(&information)
  2735. fmt.Println("报错", err)
  2736. }
  2737. }
  2738. }
  2739. }
  2740. dialysisOrder.Stage = 2
  2741. dialysisOrder.FinishNurse = nurseID
  2742. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2743. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2744. dialysisOrder.EndTime = endDate.Unix()
  2745. // 长沙南雅需求
  2746. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2747. //获取最后1条监测的数据
  2748. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2749. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2750. var accumulatedBloodVolume float64
  2751. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2752. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2753. fmt.Println(err)
  2754. // 查询未执行的医嘱
  2755. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2756. for _, item := range doctorAdvice {
  2757. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2758. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2759. redis := service.RedisClient()
  2760. //清空key 值
  2761. redis.Set(key, "", time.Second)
  2762. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2763. redis.Set(keyTwo, "", time.Second)
  2764. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2765. redis.Set(keyThree, "", time.Second)
  2766. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2767. theTime := toTime.Format("2006-01-02")
  2768. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2769. redis.Set(keyFour, "", time.Second)
  2770. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2771. redis.Set(keyFive, "", time.Second)
  2772. defer redis.Close()
  2773. }
  2774. }
  2775. go func() {
  2776. ssoDomain := beego.AppConfig.String("call_domain")
  2777. api := ssoDomain + "/index/downpatient"
  2778. values := make(url.Values)
  2779. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2780. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2781. values.Set("patient_id", strconv.FormatInt(id, 10))
  2782. http.PostForm(api, values)
  2783. }()
  2784. if err == nil {
  2785. c.ServeSuccessJSON(map[string]interface{}{
  2786. "dialysisOrder": dialysisOrder,
  2787. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2788. })
  2789. } else {
  2790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2791. }
  2792. }
  2793. }
  2794. func (c *DialysisAPIController) GetAllZone() {
  2795. adminUserInfo := c.GetMobileAdminUserInfo()
  2796. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2797. if err == nil {
  2798. c.ServeSuccessJSON(map[string]interface{}{
  2799. "zone": zone,
  2800. })
  2801. }
  2802. }
  2803. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2804. adminUserInfo := c.GetMobileAdminUserInfo()
  2805. page, _ := c.GetInt64("page", 1)
  2806. limit, _ := c.GetInt64("limit", 10)
  2807. schedulType, _ := c.GetInt64("schedul_type", 0)
  2808. startTime, _ := c.GetInt64("schedul_time", 0)
  2809. partitionType, _ := c.GetInt64("partition_type", 0)
  2810. keywords := c.GetString("keywords")
  2811. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2812. if err == nil {
  2813. c.ServeSuccessJSON(map[string]interface{}{
  2814. "schedule": dialysisSchedule,
  2815. })
  2816. }
  2817. return
  2818. }
  2819. // /m/api/dialysis/start [post]
  2820. // @param patient_id:int
  2821. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2822. // @param nurse:int 上机护士
  2823. // @param bed:int 床位号
  2824. func (this *DialysisAPIController) StartDialysis() {
  2825. patientID, _ := this.GetInt64("patient_id")
  2826. recordDateStr := this.GetString("record_date")
  2827. nurseID, _ := this.GetInt64("start_nurse")
  2828. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2829. blood_drawing, _ := this.GetInt64("blood_drawing")
  2830. schedual_type, _ := this.GetInt64("schedual_type")
  2831. bedID, _ := this.GetInt64("bed")
  2832. start_time := this.GetString("start_time")
  2833. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2834. change_nurse, _ := this.GetInt64("change_nurse")
  2835. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2836. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2837. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2838. puncture_needle := this.GetString("puncture_needle")
  2839. puncture_way := this.GetString("puncture_way")
  2840. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2841. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2842. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2843. zone_id, _ := this.GetInt64("zone_id")
  2844. elecsign := this.GetString("url")
  2845. nuclein_date_str := this.GetString("nuclein_date_str")
  2846. schedule_remark := this.GetString("schedule_remark")
  2847. order_remark := this.GetString("order_remark")
  2848. catheter_operation := this.GetString("catheter_operation")
  2849. blood_flow_volume := this.GetString("blood_flow_volume")
  2850. dialysis_strainer := this.GetString("dialysis_strainer")
  2851. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2853. return
  2854. }
  2855. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2856. if parseStartDateErr != nil {
  2857. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2859. return
  2860. }
  2861. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2862. if parseErr != nil {
  2863. this.ErrorLog("时间解析失败:%v", parseErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2865. return
  2866. }
  2867. adminUserInfo := this.GetMobileAdminUserInfo()
  2868. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2869. if getPatientErr != nil {
  2870. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2872. return
  2873. } else if patient == nil {
  2874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2875. return
  2876. }
  2877. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2878. if getNurseErr != nil {
  2879. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2881. return
  2882. } else if nurse == nil {
  2883. this.ErrorLog("护士不存在")
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2885. return
  2886. }
  2887. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2888. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2889. if getDeviceNumberErr != nil {
  2890. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2892. return
  2893. } else if deviceNumber == nil {
  2894. this.ErrorLog("床位号不存在")
  2895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2899. if getRecordErr != nil {
  2900. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2902. return
  2903. } else if dialysisRecord != nil {
  2904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2905. return
  2906. }
  2907. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2908. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2909. timeLayout := "2006-01-02 15:04:05"
  2910. loc, _ := time.LoadLocation("Local")
  2911. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2912. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2913. schedulestartTime := theStartTime.Unix()
  2914. scheduleendTime := theEndTime.Unix()
  2915. var theNucleinDate int64
  2916. timeLayoutOne := "2006-01-02"
  2917. if len(nuclein_date_str) > 0 {
  2918. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2919. if err != nil {
  2920. utils.ErrorLog(err.Error())
  2921. }
  2922. theNucleinDate = theTime.Unix()
  2923. }
  2924. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2925. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2926. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2927. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2928. //查询该床位是否有人用了
  2929. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2930. if err == gorm.ErrRecordNotFound { //空床位
  2931. // 修改了床位逻辑
  2932. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2933. if daySchedule.ID > 0 {
  2934. daySchedule.PartitionId = deviceNumber.ZoneID
  2935. daySchedule.BedId = bedID
  2936. daySchedule.ScheduleType = schedual_type
  2937. daySchedule.UpdatedTime = time.Now().Unix()
  2938. xtSchedule := models.Schedule{
  2939. PartitionId: deviceNumber.ZoneID,
  2940. BedId: bedID,
  2941. ScheduleType: schedual_type,
  2942. UpdatedTime: time.Now().Unix(),
  2943. }
  2944. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2945. if err != nil {
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2947. return
  2948. }
  2949. }
  2950. } else if err == nil {
  2951. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2952. if order.ID > 0 { //该机位被其他人占用了
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2954. return
  2955. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2956. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2957. if daySchedule.ID > 0 {
  2958. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2959. if err != nil {
  2960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2961. return
  2962. }
  2963. }
  2964. }
  2965. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2967. return
  2968. }
  2969. //else if order.ID == 0 { //该床位没被占用
  2970. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2971. // if daySchedule.ID > 0 {
  2972. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2973. // //daySchedule.BedId = bedID
  2974. // //daySchedule.ScheduleType = schedual_type
  2975. // //daySchedule.UpdatedTime = time.Now().Unix()
  2976. // //err := service.UpdateSchedule(&daySchedule)
  2977. // xtSchedule := models.Schedule{
  2978. // PartitionId: deviceNumber.ZoneID,
  2979. // BedId: bedID,
  2980. // ScheduleType: schedual_type,
  2981. // UpdatedTime: time.Now().Unix(),
  2982. // }
  2983. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2984. // if err != nil {
  2985. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. // return
  2987. // }
  2988. // }
  2989. //}
  2990. //}
  2991. } else if err != nil {
  2992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2993. return
  2994. }
  2995. // 查询信息规挡的设置天数
  2996. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2997. if infor.ID > 0 && infor.WeekDay > 0 {
  2998. var cha_time int64
  2999. timeNowStr := time.Now().Format("2006-01-02")
  3000. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3001. //今日的日期减去设置的日期
  3002. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3003. if cha_time >= recordDate.Unix() {
  3004. //查询审核是否允许
  3005. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3006. //申请状态不允许的情况 拒绝修改
  3007. if infor.ApplicationStatus != 1 {
  3008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3009. return
  3010. }
  3011. }
  3012. }
  3013. dialysisRecord = &models.DialysisOrder{
  3014. DialysisDate: recordDate.Unix(),
  3015. UserOrgId: adminUserInfo.Org.Id,
  3016. PatientId: patientID,
  3017. Stage: 1,
  3018. BedID: bedID,
  3019. StartNurse: nurseID,
  3020. Status: 1,
  3021. StartTime: startDate.Unix(),
  3022. CreatedTime: time.Now().Unix(),
  3023. UpdatedTime: time.Now().Unix(),
  3024. PunctureNurse: puncture_nurse,
  3025. Creator: adminUserInfo.AdminUser.Id,
  3026. Modifier: adminUserInfo.AdminUser.Id,
  3027. SchedualType: schedual_type,
  3028. WashpipeNurse: washpipe_nurse,
  3029. ChangeNurse: change_nurse,
  3030. DifficultPunctureNurse: difficult_puncture_nurse,
  3031. NewFistulaNurse: new_fistula_nurse,
  3032. ZoneId: zone_id,
  3033. QualityNurseId: quality_nurse_id,
  3034. PunctureNeedle: puncture_needle,
  3035. PunctureWay: puncture_way,
  3036. DialysisIrrigation: dialysis_irrigation,
  3037. DialysisDialyszers: dialysis_dialyszers,
  3038. BloodAccessId: blood_access_id,
  3039. Url: elecsign,
  3040. NucleinDate: theNucleinDate,
  3041. ScheduleRemark: schedule_remark,
  3042. OrderRemark: order_remark,
  3043. CatheterOperation: catheter_operation,
  3044. BloodFlowVolume: blood_flow_volume,
  3045. BloodDrawing: blood_drawing,
  3046. DialysisStrainer: dialysis_strainer,
  3047. }
  3048. //查询该床位是否有人用了
  3049. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3050. if errorscode == gorm.ErrRecordNotFound {
  3051. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3052. finish := models.XtDialysisFinish{
  3053. IsFinish: 1,
  3054. UserOrgId: adminUserInfo.Org.Id,
  3055. Status: 1,
  3056. Ctime: time.Now().Unix(),
  3057. Mtime: 0,
  3058. Module: 6,
  3059. RecordDate: schedulestartTime,
  3060. Sourse: 1,
  3061. PatientId: patientID,
  3062. }
  3063. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3064. if dialysisFinish.ID == 0 {
  3065. service.CreateDialysisFinish(finish)
  3066. }
  3067. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3068. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3069. //统计该患者总次数
  3070. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3071. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3072. }
  3073. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3074. //统计该患者总次数
  3075. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3076. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3077. }
  3078. redis := service.RedisClient()
  3079. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3080. redis.Set(key, "", time.Second)
  3081. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3082. //清空key 值
  3083. redis.Set(keyOne, "", time.Second)
  3084. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3085. //清空key 值
  3086. redis.Set(keyTwo, "", time.Second)
  3087. if createErr != nil {
  3088. this.ErrorLog("上机失败:%v", createErr)
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3090. return
  3091. }
  3092. }
  3093. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3094. var tempdispose string
  3095. // 只针对中能建
  3096. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3097. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3098. }
  3099. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3100. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3101. }
  3102. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3103. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3104. //}
  3105. var ultrafiltration_rate float64
  3106. var ultrafiltration_rate_one string
  3107. var replacement_rate float64
  3108. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3109. //后期预增脱水量
  3110. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3111. if prescription.ID > 0 {
  3112. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3113. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3114. 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
  3115. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3116. }
  3117. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3118. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3119. }
  3120. //针对医师汇
  3121. if adminUserInfo.Org.Id == 10121 {
  3122. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3123. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3124. }
  3125. //针对通道
  3126. if adminUserInfo.Org.Id == 10234 {
  3127. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3128. }
  3129. //针对监利大垸医院
  3130. if template.TemplateId == 41 {
  3131. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3132. }
  3133. //针对肇庆三鹤血液透析中心
  3134. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3135. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3136. }
  3137. if adminUserInfo.Org.Id == 10469 {
  3138. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3139. }
  3140. if adminUserInfo.Org.Id == 10667 {
  3141. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3142. }
  3143. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3144. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3145. }
  3146. // 只针对方济医院
  3147. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3148. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3149. ultrafiltration_rate = value
  3150. }
  3151. //针对
  3152. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10551 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10580 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10629 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10644 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate / 1000
  3175. }
  3176. if adminUserInfo.Org.Id == 10667 {
  3177. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3178. ultrafiltration_rate = ultrafiltration_rate / 1000
  3179. }
  3180. if adminUserInfo.Org.Id == 10693 {
  3181. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3182. ultrafiltration_rate = ultrafiltration_rate
  3183. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3184. }
  3185. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3186. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate
  3188. }
  3189. if adminUserInfo.Org.Id == 10702 {
  3190. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3191. ultrafiltration_rate = ultrafiltration_rate / 1000
  3192. }
  3193. if adminUserInfo.Org.Id == 10723 {
  3194. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3195. ultrafiltration_rate = ultrafiltration_rate / 1000
  3196. }
  3197. if adminUserInfo.Org.Id == 10721 {
  3198. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3199. ultrafiltration_rate = ultrafiltration_rate / 1000
  3200. }
  3201. if adminUserInfo.Org.Id == 10721 {
  3202. replacement_rate = math.Floor(prescription.ReplacementTotal * 1000 / float64(totalMin) * 60 * 1000)
  3203. replacement_rate = replacement_rate / 1000
  3204. }
  3205. }
  3206. }
  3207. record := models.MonitoringRecord{
  3208. UserOrgId: adminUserInfo.Org.Id,
  3209. PatientId: patientID,
  3210. DialysisOrderId: dialysisRecord.ID,
  3211. MonitoringDate: schedulestartTime,
  3212. OperateTime: startDate.Unix(),
  3213. // MonitoringTime: recordTime,
  3214. MonitoringNurse: nurseID,
  3215. Dispose: tempdispose,
  3216. UltrafiltrationRate: ultrafiltration_rate,
  3217. UltrafiltrationVolume: 0,
  3218. Status: 1,
  3219. CreatedTime: time.Now().Unix(),
  3220. UpdatedTime: time.Now().Unix(),
  3221. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3222. ReplacementRate: replacement_rate,
  3223. }
  3224. //只针对广慈医院
  3225. 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 {
  3226. // 查询病人是否有透前评估数据
  3227. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3228. //如果有数据就插入
  3229. if errcode == nil {
  3230. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3231. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3232. record.BreathingRate = befor.BreathingRate
  3233. record.PulseFrequency = befor.PulseFrequency
  3234. record.Temperature = befor.Temperature
  3235. }
  3236. }
  3237. //孝昌
  3238. if adminUserInfo.Org.Id == 10693 {
  3239. // 查询病人是否有透前评估数据
  3240. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3241. //如果有数据就插入
  3242. if errcode == nil {
  3243. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3244. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3245. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3246. record.BreathingRate = befor.BreathingRate
  3247. }
  3248. }
  3249. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3250. if newdialysisRecord.ID > 0 {
  3251. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3252. record.Temperature = 36.5
  3253. record.ArterialPressure = -100
  3254. record.DialysateTemperature = 36.5
  3255. record.Conductivity = 14
  3256. record.BreathingRate = "20"
  3257. record.VenousPressure = 80
  3258. record.TransmembranePressure = 60
  3259. record.Dispose = catheter_operation
  3260. }
  3261. //针对新化博翔
  3262. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3263. record.BloodOxygenSaturation = "99"
  3264. record.Conductivity = 14
  3265. record.DialysateTemperature = 36.5
  3266. record.BreathingRate = "20"
  3267. }
  3268. //针对兰溪人民医院的需求
  3269. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3270. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3271. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3272. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3273. record.Temperature = befor.Temperature
  3274. record.PulseFrequency = befor.PulseFrequency
  3275. record.BreathingRate = befor.BreathingRate
  3276. }
  3277. //针对乐山友谊医院的需求
  3278. if adminUserInfo.Org.Id == 10677 {
  3279. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3280. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3281. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3282. record.Temperature = befor.Temperature
  3283. record.PulseFrequency = befor.PulseFrequency
  3284. record.BreathingRate = befor.BreathingRate
  3285. }
  3286. //新化博翔
  3287. if adminUserInfo.Org.Id == 10447 {
  3288. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3289. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3290. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3291. record.BreathingRate = befor.BreathingRate
  3292. }
  3293. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3294. record.PulseFrequency = 80
  3295. record.Temperature = 36.5
  3296. }
  3297. //诊断灵山圣康
  3298. if adminUserInfo.Org.Id == 10375 {
  3299. record.Conductivity = 13.8
  3300. record.DialysateTemperature = 37
  3301. record.DialysateFlow = 500
  3302. record.BloodFlowVolume = 200
  3303. record.BreathingRate = "18"
  3304. record.SodiumConcentration = 140
  3305. }
  3306. //江成肾病医院
  3307. if adminUserInfo.Org.Id == 10517 {
  3308. record.SodiumConcentration = 138
  3309. record.DialysateTemperature = 36.5
  3310. }
  3311. //濉溪杏康血液透析中心
  3312. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3313. record.BloodFlowVolume = prescription.BloodFlowVolume
  3314. }
  3315. if adminUserInfo.Org.Id != 10683 {
  3316. err = service.CreateMonitor(&record)
  3317. }
  3318. //记录日志
  3319. byterequest, _ := json.Marshal(record)
  3320. monitorRecordLog := models.XtMonitorRecordLog{
  3321. RecordDate: record.MonitoringDate,
  3322. PatientId: record.PatientId,
  3323. Module: 1,
  3324. AdminUserId: adminUserInfo.AdminUser.Id,
  3325. Ctime: time.Now().Unix(),
  3326. Mtime: 0,
  3327. Status: 1,
  3328. UserOrgId: record.UserOrgId,
  3329. ErrLog: string(byterequest),
  3330. Source: "执行上机时新增监测",
  3331. }
  3332. service.CreateMonitorRecordLog(monitorRecordLog)
  3333. finish := models.XtDialysisFinish{
  3334. IsFinish: 1,
  3335. UserOrgId: adminUserInfo.Org.Id,
  3336. Status: 1,
  3337. Ctime: time.Now().Unix(),
  3338. Mtime: 0,
  3339. Module: 7,
  3340. RecordDate: schedulestartTime,
  3341. Sourse: 1,
  3342. PatientId: patientID,
  3343. }
  3344. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3345. if dialysisFinish.ID == 0 {
  3346. service.CreateDialysisFinish(finish)
  3347. }
  3348. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3349. redis := service.RedisClient()
  3350. //清空key 值
  3351. redis.Set(key, "", time.Second)
  3352. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3353. redis.Set(keyOne, "", time.Second)
  3354. defer redis.Close()
  3355. if err != nil {
  3356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3357. return
  3358. }
  3359. }
  3360. go func() {
  3361. ssoDomain := beego.AppConfig.String("call_domain")
  3362. api := ssoDomain + "/index/uppatient"
  3363. values := make(url.Values)
  3364. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3365. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3366. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3367. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3368. http.PostForm(api, values)
  3369. }()
  3370. this.ServeSuccessJSON(map[string]interface{}{
  3371. "dialysis_order": newdialysisRecord,
  3372. "monitor": record,
  3373. })
  3374. return
  3375. }
  3376. func (c *DialysisAPIController) PostSolution() {
  3377. id, _ := c.GetInt64("patient", 0)
  3378. recordDateStr := c.GetString("record_date")
  3379. if id <= 0 {
  3380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3381. return
  3382. }
  3383. adminUserInfo := c.GetMobileAdminUserInfo()
  3384. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3385. if patient.ID == 0 {
  3386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3387. return
  3388. }
  3389. if len(recordDateStr) == 0 {
  3390. recordDateStr = time.Now().Format("2006-01-02")
  3391. }
  3392. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3393. if parseDateErr != nil {
  3394. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. return
  3397. }
  3398. mode_id, _ := c.GetInt64("mode_id", 0)
  3399. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3400. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3401. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3402. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3403. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3404. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3405. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3406. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3407. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3408. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3409. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3410. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3411. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3412. kalium, _ := c.GetFloat("kalium", 0)
  3413. sodium, _ := c.GetFloat("sodium", 0)
  3414. calcium, _ := c.GetFloat("calcium", 0)
  3415. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3416. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3417. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3418. glucose, _ := c.GetFloat("glucose", 0)
  3419. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3420. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3421. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3422. conductivity, _ := c.GetFloat("conductivity", 0)
  3423. remark := c.GetString("remark")
  3424. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3425. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3426. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3427. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3428. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3429. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3430. special_medicine_other := c.GetString("special_medicine_other")
  3431. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3432. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3433. blood_access, _ := c.GetInt64("blood_access", 0)
  3434. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3435. body_fluid_other := c.GetString("body_fluid_other")
  3436. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3437. niprocart, _ := c.GetInt64("niprocart", 0)
  3438. jms, _ := c.GetInt64("jms", 0)
  3439. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3440. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3441. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3442. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3443. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3444. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3445. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3446. injector, _ := c.GetInt64("injector", 0)
  3447. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3448. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3449. safe_package, _ := c.GetInt64("package", 0)
  3450. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3451. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3452. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3453. blood := c.GetString("blood")
  3454. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3455. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3456. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3457. displace_speed := c.GetString("displace_speed")
  3458. illness, _ := c.GetInt64("illness")
  3459. amylaceum := c.GetString("amylaceum")
  3460. single_time := c.GetString("single_time")
  3461. single_water := c.GetString("single_water")
  3462. replacement_flow := c.GetString("replacement_flow")
  3463. plasma_separator := c.GetString("plasma_separator")
  3464. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3465. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3466. oxygen_flow := c.GetString("oxygen_flow")
  3467. oxygen_time := c.GetString("oxygen_time")
  3468. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3469. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3470. puncture_needle := c.GetString("puncture_needle")
  3471. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3472. epo := c.GetString("epo")
  3473. epo_count, _ := c.GetFloat("epo_count", 0)
  3474. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3475. pre_impulse := c.GetString("pre_impulse")
  3476. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3477. admin_user_id, _ := c.GetInt64("admin_user_id")
  3478. is_water := c.GetString("is_water")
  3479. add_amount, _ := c.GetFloat("add_amount")
  3480. reduce_amount, _ := c.GetFloat("reduce_amount")
  3481. prescribing_number, _ := c.GetFloat("prescribing_number")
  3482. treatment_remark := c.GetString("treatment_remark")
  3483. prescription_sodium := c.GetString("prescription_sodium")
  3484. start_sodium := c.GetString("start_sodium")
  3485. sodium_curve := c.GetString("sodium_curve")
  3486. var is_war int64
  3487. if is_water == "是" {
  3488. is_war = 1
  3489. }
  3490. if is_water == "否" {
  3491. is_war = 2
  3492. }
  3493. if is_water == "请选择" {
  3494. is_war = 0
  3495. }
  3496. drhy_water := c.GetString("drhy_water")
  3497. dry_water_hour := c.GetString("dry_water_hour")
  3498. water_machine := c.GetString("water_machine")
  3499. dialysis_remark := c.GetString("dialysis_remark")
  3500. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3501. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3502. prescription_water, _ := c.GetFloat("prescription_water")
  3503. dialysis_strainer := c.GetString("dialysis_strainer")
  3504. chaptalization := c.GetString("chaptalization")
  3505. washing_time := c.GetString("washing_time")
  3506. warsh_count := c.GetString("warsh_count")
  3507. blood_access_part_id := c.GetString("blood_access_part_id")
  3508. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3509. dialyzate := c.GetString("dialyzate")
  3510. if mode_id > 0 {
  3511. var str string
  3512. //查找该机构用的是什么透析器
  3513. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3514. if filedConfig.ID > 0 {
  3515. str = dialyzerPerfusionApparatus
  3516. } else {
  3517. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3518. }
  3519. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3520. }
  3521. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3522. //
  3523. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3524. // if appRole.UserType == 3 {
  3525. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3526. // if getPermissionErr != nil {
  3527. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3528. // return
  3529. // } else if headNursePermission == nil {
  3530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3531. // return
  3532. // }
  3533. // }
  3534. //}
  3535. // 查询信息规挡的设置天数
  3536. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3537. if infor.ID > 0 && infor.WeekDay > 0 {
  3538. var cha_time int64
  3539. timeNowStr := time.Now().Format("2006-01-02")
  3540. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3541. //今日的日期减去设置的日期
  3542. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3543. if cha_time >= recordDate.Unix() {
  3544. //查询审核是否允许
  3545. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3546. //申请状态不允许的情况 拒绝修改
  3547. if infor.ApplicationStatus != 1 {
  3548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3549. return
  3550. }
  3551. }
  3552. }
  3553. prescription := models.DialysisPrescription{
  3554. UserOrgId: adminUserInfo.Org.Id,
  3555. PatientId: id,
  3556. RecordDate: recordDate.Unix(),
  3557. ModeId: mode_id,
  3558. DialysisDuration: dialysis_duration,
  3559. Dialyzer: dialyzer,
  3560. PerfusionApparatus: perfusion_apparatus,
  3561. BloodFlowVolume: blood_flow_volume,
  3562. DewaterAmount: dewater_amount,
  3563. DisplaceLiqui: displace_liqui,
  3564. ReplacementWay: replacement_way,
  3565. Anticoagulant: anticoagulant,
  3566. AnticoagulantShouji: anticoagulant_shouji,
  3567. AnticoagulantWeichi: anticoagulant_weichi,
  3568. AnticoagulantZongliang: anticoagulant_zongliang,
  3569. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3570. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3571. Kalium: kalium,
  3572. Sodium: sodium,
  3573. Calcium: calcium,
  3574. Bicarbonate: bicarbonate,
  3575. Glucose: glucose,
  3576. // DryWeight: dry_weight,
  3577. DialysateFlow: dialysate_flow,
  3578. DialysateTemperature: dialysate_temperature,
  3579. Conductivity: conductivity,
  3580. Remark: remark,
  3581. Status: 1,
  3582. CreatedTime: time.Now().Unix(),
  3583. UpdatedTime: time.Now().Unix(),
  3584. DialysisDurationMinute: dialysisDurationMinute,
  3585. DialysisDurationHour: dialysisDurationHour,
  3586. TargetUltrafiltration: targetUltrafiltration,
  3587. DialysateFormulation: dialysateFormulation,
  3588. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3589. BodyFluid: body_fluid,
  3590. SpecialMedicine: special_medicine,
  3591. SpecialMedicineOther: special_medicine_other,
  3592. DisplaceLiquiPart: displace_liqui_part,
  3593. DisplaceLiquiValue: displace_liqui_value,
  3594. BloodAccess: blood_access,
  3595. Ultrafiltration: ultrafiltration,
  3596. BodyFluidOther: body_fluid_other,
  3597. ReplacementTotal: replacement_total,
  3598. Niprocart: niprocart,
  3599. Jms: jms,
  3600. FistulaNeedleSet: fistula_needle_set,
  3601. FistulaNeedleSet16: fistula_needle_set_16,
  3602. Hemoperfusion: hemoperfusion,
  3603. DialyserSterilised: dialyser_sterilised,
  3604. Filtryzer: filtryzer,
  3605. TargetKtv: target_ktv,
  3606. Dialyzers: dialyzers,
  3607. Injector: injector,
  3608. Bloodlines: bloodlines,
  3609. TubingHemodialysis: tubing_hemodialysis,
  3610. Package: safe_package,
  3611. ALiquid: a_liquid,
  3612. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3613. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3614. Blood: blood,
  3615. DialysisDialyszers: dialysis_dialyszers,
  3616. DialysisIrrigation: dialysis_irrigation,
  3617. AntioxidantCommodityName: antioxidant_commodity_name,
  3618. DisplaceSpeed: displace_speed,
  3619. Illness: illness,
  3620. Amylaceum: amylaceum,
  3621. SingleWater: single_water,
  3622. SingleTime: single_time,
  3623. ReplacementFlow: replacement_flow,
  3624. PlasmaSeparator: plasma_separator,
  3625. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3626. OxygenUptake: oxygen_uptake,
  3627. OxygenTime: oxygen_time,
  3628. OxygenFlow: oxygen_flow,
  3629. HemodialysisPipelines: hemodialysis_pipelines,
  3630. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3631. PunctureNeedle: puncture_needle,
  3632. PunctureNeedleCount: puncture_needle_count,
  3633. Epo: epo,
  3634. EpoCount: epo_count,
  3635. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3636. PreImpulse: impulse,
  3637. AdminUserId: admin_user_id,
  3638. IsWater: is_war,
  3639. DrhyWater: drhy_water,
  3640. DryWaterHour: dry_water_hour,
  3641. WaterMachine: water_machine,
  3642. AddAmount: add_amount,
  3643. ReduceAmount: reduce_amount,
  3644. DialysisRemark: dialysis_remark,
  3645. PrescribingNumber: prescribing_number,
  3646. PrescriptionSodium: prescription_sodium,
  3647. StartSodium: start_sodium,
  3648. SodiumCurve: sodium_curve,
  3649. TreatmentRemark: treatment_remark,
  3650. DialysisFluidFlow: dialysis_fluid_flow,
  3651. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3652. PrescriptionWater: prescription_water,
  3653. DialysisStrainer: dialysis_strainer,
  3654. Chaptalization: chaptalization,
  3655. WashingTime: washing_time,
  3656. WarshCount: warsh_count,
  3657. BloodAccessPartId: blood_access_part_id,
  3658. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3659. Dialyzate: dialyzate,
  3660. }
  3661. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3662. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3663. //
  3664. if appRole.UserType == 2 || appRole.UserType == 1 {
  3665. prescription_doctor = adminUserInfo.AdminUser.Id
  3666. prescription.PrescriptionDoctor = prescription_doctor
  3667. }
  3668. if dialysisPrescription.ID == 0 { //新增
  3669. prescription.Creater = adminUserInfo.AdminUser.Id
  3670. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3671. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3672. }
  3673. } else { //修改
  3674. if dialysisPrescription.Creater == 0 {
  3675. prescription.Creater = adminUserInfo.AdminUser.Id
  3676. } else {
  3677. prescription.Creater = dialysisPrescription.Creater
  3678. if adminUserInfo.Org.Id == 9882 {
  3679. if appRole.UserType == 2 || appRole.UserType == 1 {
  3680. prescription.Creater = adminUserInfo.AdminUser.Id
  3681. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3682. }
  3683. }
  3684. }
  3685. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3686. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3687. }
  3688. //if/**/
  3689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3690. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3691. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3692. // if getPermissionErr != nil {
  3693. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3694. // return
  3695. // } else if headNursePermission == nil {
  3696. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3697. // return
  3698. // }
  3699. //}
  3700. //prescription.Creater = dialysisPrescription.Creater
  3701. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3702. prescription.Modifier = adminUserInfo.AdminUser.Id
  3703. prescription.ID = dialysisPrescription.ID
  3704. }
  3705. solution := models.DialysisSolution{
  3706. RegistrarsId: adminUserInfo.AdminUser.Id,
  3707. UserOrgId: adminUserInfo.Org.Id,
  3708. Doctor: prescription_doctor,
  3709. PatientId: id,
  3710. ModeId: mode_id,
  3711. DialysisDuration: dialysis_duration,
  3712. PerfusionApparatus: perfusion_apparatus,
  3713. BloodFlowVolume: blood_flow_volume,
  3714. Dewater: dewater_amount,
  3715. DisplaceLiqui: displace_liqui,
  3716. ReplacementWay: replacement_way,
  3717. Anticoagulant: anticoagulant,
  3718. AnticoagulantShouji: anticoagulant_shouji,
  3719. AnticoagulantWeichi: anticoagulant_weichi,
  3720. AnticoagulantZongliang: anticoagulant_zongliang,
  3721. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3722. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3723. Kalium: kalium,
  3724. Sodium: sodium,
  3725. Calcium: calcium,
  3726. Bicarbonate: bicarbonate,
  3727. Glucose: glucose,
  3728. // DryWeight: dry_weight,
  3729. DialysateFlow: dialysate_flow,
  3730. DialysateTemperature: dialysate_temperature,
  3731. Conductivity: conductivity,
  3732. Remark: remark,
  3733. Status: 1,
  3734. CreatedTime: time.Now().Unix(),
  3735. UpdatedTime: time.Now().Unix(),
  3736. DialysisDurationMinute: dialysisDurationMinute,
  3737. DialysisDurationHour: dialysisDurationHour,
  3738. TargetUltrafiltration: targetUltrafiltration,
  3739. DialysateFormulation: dialysateFormulation,
  3740. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3741. BodyFluid: body_fluid,
  3742. SpecialMedicine: special_medicine,
  3743. SpecialMedicineOther: special_medicine_other,
  3744. DisplaceLiquiPart: displace_liqui_part,
  3745. DisplaceLiquiValue: displace_liqui_value,
  3746. BloodAccess: blood_access,
  3747. Ultrafiltration: ultrafiltration,
  3748. BodyFluidOther: body_fluid_other,
  3749. ReplacementTotal: replacement_total,
  3750. TargetKtv: target_ktv,
  3751. DialysisDialyszers: dialysis_dialyszers,
  3752. DialysisIrrigation: dialysis_irrigation,
  3753. HemodialysisPipelines: hemodialysis_pipelines,
  3754. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3755. PunctureNeedle: puncture_needle,
  3756. PunctureNeedleCount: puncture_needle_count,
  3757. Epo: epo,
  3758. EpoCount: epo_count,
  3759. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3760. PreImpulse: impulse,
  3761. SolutionStatus: 1,
  3762. DialysisRemark: dialysis_remark,
  3763. PrescribingNumber: prescribing_number,
  3764. PrescriptionSodium: prescription_sodium,
  3765. StartSodium: start_sodium,
  3766. SodiumCurve: sodium_curve,
  3767. TreatmentRemark: treatment_remark,
  3768. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3769. DialysisFluidFlow: dialysis_fluid_flow,
  3770. PrescriptionWater: prescription_water,
  3771. DialysisStrainer: dialysis_strainer,
  3772. Chaptalization: chaptalization,
  3773. WashingTime: washing_time,
  3774. WarshCount: warsh_count,
  3775. BloodAccessPartId: blood_access_part_id,
  3776. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3777. Dialyzate: dialyzate,
  3778. }
  3779. //针对河间咸的
  3780. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3781. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3782. solution.DisplaceLiquiPart = 0
  3783. solution.DisplaceLiquiValue = 0
  3784. }
  3785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3786. prescription.DisplaceLiquiPart = 0
  3787. prescription.DisplaceLiquiValue = 0
  3788. }
  3789. }
  3790. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3791. if solution.PrescribingNumber == 0 {
  3792. solution.PrescribingNumber = 1
  3793. }
  3794. if prescription.PrescribingNumber == 0 {
  3795. prescription.PrescribingNumber = 1
  3796. }
  3797. if solution.PrescribingNumber == 0 && id == 14682 {
  3798. solution.PrescribingNumber = 2
  3799. }
  3800. if solution.PrescribingNumber == 0 && id == 18560 {
  3801. solution.PrescribingNumber = 2
  3802. }
  3803. if prescription.PrescribingNumber == 0 && id == 14682 {
  3804. prescription.PrescribingNumber = 2
  3805. }
  3806. if prescription.PrescribingNumber == 0 && id == 18560 {
  3807. prescription.PrescribingNumber = 2
  3808. }
  3809. }
  3810. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3811. //记录日志
  3812. byterequest, _ := json.Marshal(prescription)
  3813. prescriptionLog := models.XtDialysisPrescriptionLog{
  3814. UserOrgId: prescription.UserOrgId,
  3815. Ctime: time.Now().Unix(),
  3816. Mtime: 0,
  3817. ErrLog: string(byterequest),
  3818. AdminUserId: adminUserInfo.AdminUser.Id,
  3819. RecordDate: prescription.RecordDate,
  3820. PatientId: prescription.PatientId,
  3821. Source: "手机端新增长期处方",
  3822. Status: 1,
  3823. }
  3824. service.CreatePrescriptionLog(prescriptionLog)
  3825. finish := models.XtDialysisFinish{
  3826. IsFinish: 1,
  3827. UserOrgId: adminUserInfo.Org.Id,
  3828. Status: 1,
  3829. Ctime: time.Now().Unix(),
  3830. Mtime: 0,
  3831. Module: 1,
  3832. RecordDate: recordDate.Unix(),
  3833. Sourse: 1,
  3834. PatientId: id,
  3835. }
  3836. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3837. if dialysisFinish.ID == 0 {
  3838. service.CreateDialysisFinish(finish)
  3839. }
  3840. //获取最新1条
  3841. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3842. //更新状态
  3843. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3844. //长沙南雅医院,自动生成抗凝剂的临时处方
  3845. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3846. if prescribing_number == 0 {
  3847. prescribing_number = 1
  3848. }
  3849. advice := models.DoctorAdvice{
  3850. UserOrgId: adminUserInfo.Org.Id,
  3851. PatientId: id,
  3852. GroupNo: 0,
  3853. AdviceType: 2,
  3854. RecordDate: recordDate.Unix(),
  3855. AdviceDate: recordDate.Unix(),
  3856. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3857. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3858. AdviceDesc: "",
  3859. ReminderDate: 0,
  3860. SingleDose: prescription.AnticoagulantZongliang,
  3861. SingleDoseUnit: "iu",
  3862. DrugSpec: 0,
  3863. DrugSpecUnit: "",
  3864. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3865. PrescribingNumberUnit: "支",
  3866. DeliveryWay: "静脉注射",
  3867. ExecutionFrequency: "上机前",
  3868. AdviceDoctor: 0,
  3869. Status: 1,
  3870. CreatedTime: time.Now().Unix(),
  3871. UpdatedTime: time.Now().Unix(),
  3872. IsPrescription: 1,
  3873. ExecutionState: 2,
  3874. StopState: 2,
  3875. IsSettle: 2,
  3876. }
  3877. // 查询排班信息
  3878. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3879. if schedulePatient.ID > 0 {
  3880. if schedulePatient.ScheduleType == 1 {
  3881. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3882. }
  3883. if schedulePatient.ScheduleType == 2 {
  3884. advice.StartTime = recordDate.Unix() + 9*60*60
  3885. }
  3886. }
  3887. // 抗凝剂名称
  3888. switch anticoagulant {
  3889. case 1:
  3890. advice.AdviceName = "无肝素"
  3891. break
  3892. case 2:
  3893. advice.AdviceName = "普通肝素"
  3894. break
  3895. case 3:
  3896. advice.AdviceName = "低分子肝素"
  3897. break
  3898. case 4:
  3899. advice.AdviceName = "阿加曲班"
  3900. break
  3901. case 5:
  3902. advice.AdviceName = "枸橼酸钠"
  3903. break
  3904. case 6:
  3905. advice.AdviceName = "低分子肝素钙"
  3906. break
  3907. case 7:
  3908. advice.AdviceName = "低分子肝素钠"
  3909. break
  3910. case 8:
  3911. advice.AdviceName = "依诺肝素"
  3912. break
  3913. case 9:
  3914. advice.AdviceName = "达肝素"
  3915. break
  3916. case 10:
  3917. advice.AdviceName = "体外抗凝"
  3918. break
  3919. case 11:
  3920. advice.AdviceName = "那曲肝素"
  3921. break
  3922. case 12:
  3923. advice.AdviceName = "无抗凝剂"
  3924. break
  3925. }
  3926. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3927. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3928. advice.AdviceDoctor = appRole.AdminUserId
  3929. }
  3930. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3931. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3932. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3933. advice.AdviceName = "低分子肝素钠注射液"
  3934. // 修改患者临时医嘱里的抗凝剂医嘱
  3935. advice.ID = advicePrescription.ID
  3936. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3937. } else {
  3938. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3939. advice.AdviceName = "低分子肝素钠注射液"
  3940. service.CreateDoctorAdvice(&advice)
  3941. }
  3942. }
  3943. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3944. redis := service.RedisClient()
  3945. defer redis.Close()
  3946. //清空key 值
  3947. redis.Set(key, "", time.Second)
  3948. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3949. redis.Set(keyOne, "", time.Second)
  3950. }
  3951. //获取key,清空redis
  3952. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3953. redis := service.RedisClient()
  3954. defer redis.Close()
  3955. //清空key 值
  3956. redis.Set(key, "", time.Second)
  3957. //清空长期医嘱的key
  3958. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3959. redis.Set(soulution_key, "", time.Second)
  3960. //查询最近透析准备表里是否存在 透析器 灌流器
  3961. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3962. redis.Set(keyOne, "", time.Second)
  3963. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3964. redis.Set(keyTwo, "", time.Second)
  3965. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3966. redis.Set(keyThree, "", time.Second)
  3967. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3968. redis.Set(keyFour, "", time.Second)
  3969. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3970. //
  3971. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3972. //
  3973. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3974. //if len(mation)>0{
  3975. // for _, item := range splitStr {
  3976. // for _,it := range mation{
  3977. // if(item == it.SpecificationName){
  3978. //
  3979. // //查询最近一次的透析器
  3980. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3981. //
  3982. // if errcode == gorm.ErrRecordNotFound{
  3983. // //插入数据
  3984. // prepare := models.DialysisBeforePrepare{
  3985. // UserOrgId: adminUserInfo.Org.Id,
  3986. // PatientId: id,
  3987. // RecordDate: recordDate.Unix(),
  3988. // GoodTypeId: it.GoodTypeId,
  3989. // GoodId: it.ID,
  3990. // Count: 1,
  3991. // Ctime: time.Now().Unix(),
  3992. // Creater: adminUserInfo.AdminUser.Id,
  3993. // Status:1,
  3994. //
  3995. // }
  3996. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3997. // fmt.Println("",errcode)
  3998. // }
  3999. // }
  4000. // }
  4001. //
  4002. // }
  4003. //
  4004. // for _, item := range splitIrrigation {
  4005. // for _,it := range mation{
  4006. // if(item == it.SpecificationName){
  4007. // //查询最近一次的透析器
  4008. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4009. // if errcode == gorm.ErrRecordNotFound{
  4010. // //插入数据
  4011. // prepare := models.DialysisBeforePrepare{
  4012. // UserOrgId: adminUserInfo.Org.Id,
  4013. // PatientId: id,
  4014. // RecordDate: recordDate.Unix(),
  4015. // GoodTypeId: it.GoodTypeId,
  4016. // GoodId: it.ID,
  4017. // Count: 1,
  4018. // Ctime: time.Now().Unix(),
  4019. // Creater: adminUserInfo.AdminUser.Id,
  4020. // Status:1,
  4021. //
  4022. // }
  4023. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4024. // fmt.Println(errcode)
  4025. // }
  4026. // }
  4027. // }
  4028. // }
  4029. //}
  4030. c.ServeSuccessJSON(map[string]interface{}{
  4031. "solution": &solution,
  4032. "prescription": &prescription,
  4033. })
  4034. }
  4035. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4036. patient, _ := c.GetInt64("patient", 0)
  4037. adminUserInfo := c.GetMobileAdminUserInfo()
  4038. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4039. c.ServeSuccessJSON(map[string]interface{}{
  4040. "receiveTreatmentAsses": receiveTreatmentAsses,
  4041. })
  4042. }
  4043. func (this *DialysisAPIController) PostSignInfo() {
  4044. patientID, _ := this.GetInt64("patient_id")
  4045. recordDateStr := this.GetString("date")
  4046. if patientID <= 0 {
  4047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4048. return
  4049. }
  4050. if len(recordDateStr) == 0 {
  4051. recordDateStr = time.Now().Format("2006-01-02")
  4052. }
  4053. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4054. if parseDateErr != nil {
  4055. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4057. return
  4058. }
  4059. adminInfo := this.GetMobileAdminUserInfo()
  4060. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4061. if err != nil {
  4062. this.ErrorLog("签名失败:%v", err)
  4063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4064. return
  4065. }
  4066. this.ServeSuccessJSON(map[string]interface{}{
  4067. "doctor_id": adminInfo.AdminUser.Id,
  4068. })
  4069. }
  4070. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4071. patientID, _ := this.GetInt64("patient_id")
  4072. adminInfo := this.GetMobileAdminUserInfo()
  4073. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4074. this.ServeSuccessJSON(map[string]interface{}{
  4075. "monitor": record,
  4076. })
  4077. }
  4078. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4079. thisTime := time.Now()
  4080. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4081. timeLayout := "2006-01-02 15:04:05"
  4082. loc, _ := time.LoadLocation("Local")
  4083. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4084. theAssessmentDateTime := theStartTime.Unix()
  4085. patientID, _ := this.GetInt64("patient_id")
  4086. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4087. adminInfo := this.GetMobileAdminUserInfo()
  4088. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4089. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4090. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4091. var ultrafiltration_rate float64
  4092. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4093. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4094. fmt.Println(evaluation)
  4095. fmt.Println("prescription.ID", prescription.ID)
  4096. if prescription.ID > 0 {
  4097. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4098. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4099. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4100. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4104. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if adminInfo.Org.Id == 10510 {
  4108. record.UltrafiltrationRate = 0
  4109. }
  4110. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4111. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4112. record.UltrafiltrationRate = ultrafiltration_rate
  4113. }
  4114. if template.TemplateId == 20 || template.TemplateId == 22 {
  4115. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4116. record.UltrafiltrationRate = ultrafiltration_rate
  4117. }
  4118. // 只针对方济医院
  4119. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4120. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4121. ultrafiltration_rate = value
  4122. record.UltrafiltrationRate = ultrafiltration_rate
  4123. }
  4124. if template.TemplateId == 41 || template.TemplateId == 47 {
  4125. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4126. record.UltrafiltrationRate = ultrafiltration_rate
  4127. }
  4128. if template.TemplateId == 43 {
  4129. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4130. record.UltrafiltrationRate = ultrafiltration_rate
  4131. }
  4132. if template.TemplateId == 46 || template.TemplateId == 54 {
  4133. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4134. record.UltrafiltrationRate = ultrafiltration_rate
  4135. }
  4136. 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 {
  4137. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4138. record.UltrafiltrationRate = ultrafiltration_rate
  4139. }
  4140. if adminInfo.Org.Id == 10469 {
  4141. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4142. record.UltrafiltrationRate = ultrafiltration_rate
  4143. }
  4144. if adminInfo.Org.Id == 10667 {
  4145. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4146. record.UltrafiltrationRate = ultrafiltration_rate
  4147. }
  4148. if adminInfo.Org.Id == 10471 {
  4149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4150. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4151. }
  4152. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4154. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4155. }
  4156. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4158. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4159. }
  4160. if adminInfo.Org.Id == 10721 {
  4161. fmt.Println("prescription.PrescriptionWater-------------------", prescription.PrescriptionWater)
  4162. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4163. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4164. }
  4165. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4166. record.UltrafiltrationRate = 0
  4167. }
  4168. //if template.TemplateId == 47 {
  4169. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4170. // record.UltrafiltrationRate = ultrafiltration_rate
  4171. //}
  4172. }
  4173. }
  4174. // record.UltrafiltrationRate = ultrafiltration_rate
  4175. record.UltrafiltrationVolume = 0
  4176. 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
  4177. if ultrafiltration_rate > 0 {
  4178. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4179. record.UltrafiltrationVolume = value
  4180. }
  4181. }
  4182. 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
  4183. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4184. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4185. record.UltrafiltrationVolume = ultrafiltration_volume
  4186. }
  4187. }
  4188. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4189. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4190. record.UltrafiltrationVolume = ultrafiltration_volume
  4191. }
  4192. //长沙南雅
  4193. 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 {
  4194. if ultrafiltration_rate > 0 {
  4195. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4196. record.UltrafiltrationVolume = ultrafiltration_volume
  4197. }
  4198. }
  4199. if adminInfo.Org.Id == 10471 {
  4200. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4201. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4202. }
  4203. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4204. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4205. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4206. }
  4207. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4208. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4209. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4210. }
  4211. //长沙南雅累计血容量自动计算
  4212. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4213. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4214. //}
  4215. if template.TemplateId == 47 || template.TemplateId == 54 {
  4216. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4217. }
  4218. if adminInfo.Org.Id == 10510 {
  4219. record.UltrafiltrationVolume = 0
  4220. }
  4221. if adminInfo.Org.Id == 10721 {
  4222. if ultrafiltration_rate > 0 {
  4223. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4224. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4225. }
  4226. }
  4227. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4228. this.ServeSuccessJSON(map[string]interface{}{
  4229. "monitor": record,
  4230. "lastMonitorRecordList": lastMonitorRecordList,
  4231. })
  4232. }
  4233. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4234. record_id, _ := this.GetInt64("id")
  4235. nurseID, _ := this.GetInt64("start_nurse")
  4236. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4237. bedID, _ := this.GetInt64("bed")
  4238. start_time := this.GetString("start_time")
  4239. schedual_type, _ := this.GetInt64("schedual_type")
  4240. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4241. change_nurse, _ := this.GetInt64("change_nurse")
  4242. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4243. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4244. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4245. patient_id, _ := this.GetInt64("patient_id")
  4246. record_date, _ := this.GetInt64("record_date")
  4247. puncture_needle := this.GetString("puncture_needle")
  4248. puncture_way := this.GetString("puncture_way")
  4249. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4250. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4251. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4252. nuclein_date_str := this.GetString("nuclein_date_str")
  4253. order_remark := this.GetString("order_remark")
  4254. schedule_remark := this.GetString("schedule_remark")
  4255. catheter_operation := this.GetString("catheter_operation")
  4256. blood_flow_volume := this.GetString("blood_flow_volume")
  4257. blood_drawing, _ := this.GetInt64("blood_drawing")
  4258. dialysis_strainer := this.GetString("dialysis_strainer")
  4259. if record_id == 0 {
  4260. this.ErrorLog("id:%v", record_id)
  4261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4262. return
  4263. }
  4264. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4265. if parseStartDateErr != nil {
  4266. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4268. return
  4269. }
  4270. adminUserInfo := this.GetMobileAdminUserInfo()
  4271. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4272. if getNurseErr != nil {
  4273. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4275. return
  4276. } else if nurse == nil {
  4277. this.ErrorLog("护士不存在")
  4278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4279. return
  4280. }
  4281. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4282. //if getNurseErr != nil {
  4283. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4284. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4285. // return
  4286. //} else if nurse == nil {
  4287. // this.ErrorLog("护士不存在")
  4288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4289. // return
  4290. //}
  4291. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4292. if getDeviceNumberErr != nil {
  4293. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4295. return
  4296. } else if deviceNumber == nil {
  4297. this.ErrorLog("床位号不存在")
  4298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4299. return
  4300. }
  4301. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4302. //
  4303. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4304. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4305. // if getPermissionErr != nil {
  4306. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4307. // return
  4308. // } else if headNursePermission == nil {
  4309. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4310. // return
  4311. // }
  4312. //}
  4313. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4314. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4315. timeLayout := "2006-01-02 15:04:05"
  4316. loc, _ := time.LoadLocation("Local")
  4317. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4318. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4319. schedulestartTime := theStartTime.Unix()
  4320. scheduleendTime := theEndTime.Unix()
  4321. var theNucleinDate int64
  4322. timeLayoutOne := "2006-01-02"
  4323. if len(nuclein_date_str) > 0 {
  4324. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4325. if err != nil {
  4326. utils.ErrorLog(err.Error())
  4327. }
  4328. theNucleinDate = theTime.Unix()
  4329. }
  4330. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4331. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4332. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4333. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4334. if err == gorm.ErrRecordNotFound { //空床位
  4335. // 修改了床位逻辑
  4336. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4337. if daySchedule.ID > 0 {
  4338. //daySchedule.BedId = bedID
  4339. //daySchedule.PartitionId = deviceNumber.ZoneID
  4340. //daySchedule.ScheduleType = schedual_type
  4341. //daySchedule.UpdatedTime = time.Now().Unix()
  4342. //err := service.UpdateSchedule(&daySchedule)
  4343. xtSchedule := models.Schedule{
  4344. PartitionId: deviceNumber.ZoneID,
  4345. BedId: bedID,
  4346. ScheduleType: schedual_type,
  4347. UpdatedTime: time.Now().Unix(),
  4348. }
  4349. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4350. if err != nil {
  4351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4352. return
  4353. }
  4354. }
  4355. } else if err == nil {
  4356. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4357. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4358. if daySchedule.ID > 0 {
  4359. //daySchedule.BedId = bedID
  4360. //daySchedule.PartitionId = deviceNumber.ZoneID
  4361. //
  4362. //daySchedule.ScheduleType = schedual_type
  4363. //daySchedule.UpdatedTime = time.Now().Unix()
  4364. //err := service.UpdateSchedule(&daySchedule)
  4365. xtSchedule := models.Schedule{
  4366. PartitionId: deviceNumber.ZoneID,
  4367. BedId: bedID,
  4368. ScheduleType: schedual_type,
  4369. UpdatedTime: time.Now().Unix(),
  4370. }
  4371. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4372. if err != nil {
  4373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4374. return
  4375. }
  4376. }
  4377. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4379. return
  4380. }
  4381. } else if err != nil {
  4382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4383. return
  4384. }
  4385. }
  4386. dialysisRecord := &models.DialysisOrder{
  4387. ID: record_id,
  4388. UserOrgId: adminUserInfo.Org.Id,
  4389. BedID: bedID,
  4390. StartNurse: nurseID,
  4391. StartTime: startDate.Unix(),
  4392. PunctureNurse: puncture_nurse,
  4393. Creator: adminUserInfo.AdminUser.Id,
  4394. Modifier: adminUserInfo.AdminUser.Id,
  4395. WashpipeNurse: washpipe_nurse,
  4396. SchedualType: schedual_type,
  4397. ChangeNurse: change_nurse,
  4398. DifficultPunctureNurse: difficult_puncture_nurse,
  4399. NewFistulaNurse: new_fistula_nurse,
  4400. QualityNurseId: quality_nurse_id,
  4401. PunctureNeedle: puncture_needle,
  4402. PunctureWay: puncture_way,
  4403. DialysisDialyszers: dialysis_dialyszers,
  4404. DialysisIrrigation: dialysis_irrigation,
  4405. BloodAccessId: blood_access_id,
  4406. NucleinDate: theNucleinDate,
  4407. OrderRemark: order_remark,
  4408. ScheduleRemark: schedule_remark,
  4409. CatheterOperation: catheter_operation,
  4410. BloodFlowVolume: blood_flow_volume,
  4411. BloodDrawing: blood_drawing,
  4412. DialysisStrainer: dialysis_strainer,
  4413. }
  4414. //修改床位号需要重新消毒
  4415. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4416. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4417. //查询第一条监测
  4418. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4419. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4420. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4421. redis := service.RedisClient()
  4422. //清空key 值
  4423. redis.Set(key, "", time.Second)
  4424. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4425. redis.Set(keyOne, "", time.Second)
  4426. defer redis.Close()
  4427. }
  4428. // 查询信息规挡的设置天数
  4429. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4430. if infor.ID > 0 && infor.WeekDay > 0 {
  4431. var cha_time int64
  4432. timeNowStr := time.Now().Format("2006-01-02")
  4433. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4434. //今日的日期减去设置的日期
  4435. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4436. if cha_time >= record_date {
  4437. //查询审核是否允许
  4438. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4439. //申请状态不允许的情况 拒绝修改
  4440. if infor.ApplicationStatus != 1 {
  4441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4442. return
  4443. }
  4444. }
  4445. }
  4446. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4447. //修改床位后重新生成消毒计划
  4448. if adminUserInfo.Org.Id == 10340 {
  4449. //根据床位号获取设备型号
  4450. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4451. //查询使用消毒最后一条消毒记录
  4452. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4453. fmt.Println("err", err)
  4454. if err == gorm.ErrRecordNotFound {
  4455. //查找排班
  4456. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4457. //查询改设备是否有消毒计划
  4458. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4459. //根据床位号获取设备id
  4460. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4461. //查询病人信息
  4462. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4463. var con = ""
  4464. if patients.IsInfectious == 0 {
  4465. con = ""
  4466. }
  4467. if patients.IsInfectious == 1 {
  4468. con = "无"
  4469. }
  4470. if patients.IsInfectious == 2 {
  4471. con = "有"
  4472. }
  4473. if errcode == nil {
  4474. var end_time int64
  4475. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4476. //新增消毒
  4477. information := models.DeviceInformation{
  4478. Date: dialysisRecord.DialysisDate,
  4479. Zone: dialysisRecord.ZoneId,
  4480. Class: dialysisRecord.SchedualType,
  4481. BedNumber: dialysisRecord.BedID,
  4482. PatientId: dialysisRecord.PatientId,
  4483. DialysisMode: scheduleByPatient.ModeId,
  4484. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4485. Disinfection: 1,
  4486. DialysisConcentration: 1,
  4487. DisinfectionStatus: 1,
  4488. Move: 1,
  4489. UserOrgId: dialysisRecord.UserOrgId,
  4490. DisinfectType: plan.Way,
  4491. DisinfectantType: plan.MachineDisinfectant,
  4492. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4493. Disinfectant: plan.Disinfectant,
  4494. Ctime: time.Now().Unix(),
  4495. Status: 1,
  4496. SignName: nurseID,
  4497. EquimentId: addmacher.ID,
  4498. DisinfectionResidue: 2,
  4499. Bed: addmacher.BedNumber,
  4500. StartTime: dialysisRecord.StartTime,
  4501. EndTime: dialysisRecord.EndTime,
  4502. Contagion: con,
  4503. WeightLoss: 0,
  4504. Hyperfiltratio: 0,
  4505. DialysisHour: "",
  4506. MachineRun: 1,
  4507. DisinfecStartime: dialysisRecord.EndTime,
  4508. DisinfecEndtime: end_time,
  4509. }
  4510. err := service.CreateInformationTwo(&information)
  4511. fmt.Println("报错", err)
  4512. }
  4513. }
  4514. }
  4515. order, _ := service.GetLastPatientOrder(record_id)
  4516. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4517. redis := service.RedisClient()
  4518. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4519. redis.Set(key, "", time.Second)
  4520. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4521. //清空key 值
  4522. redis.Set(keyOne, "", time.Second)
  4523. scheduleDateStartOne := startDate.Format("2006-01-02")
  4524. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4525. redis.Set(keyTwo, "", time.Second)
  4526. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4527. redis.Set(keyThree, "", time.Second)
  4528. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4529. redis.Set(keyFour, "", time.Second)
  4530. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4531. redis.Set(keyFive, "", time.Second)
  4532. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4533. redis.Set(keySix, "", time.Second)
  4534. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4535. redis.Set(keySeven, "", time.Second)
  4536. if updateErr != nil {
  4537. this.ErrorLog("修改上机失败:%v", updateErr)
  4538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4539. return
  4540. }
  4541. if updateErr == nil {
  4542. if tempDialysisRecord.Stage == 2 {
  4543. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4544. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4545. fmt.Println(value)
  4546. a, b := math.Modf(value)
  4547. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4548. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4549. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4550. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4551. redis := service.RedisClient()
  4552. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4553. redis.Set(key, "", time.Second)
  4554. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4555. redis.Set(keyOne, "", time.Second)
  4556. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4557. //清空key 值
  4558. redis.Set(keySix, "", time.Second)
  4559. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4560. redis.Set(keySeven, "", time.Second)
  4561. redis.Close()
  4562. if updateAssessmentErr != nil {
  4563. utils.ErrorLog("%v", updateAssessmentErr)
  4564. }
  4565. }
  4566. }
  4567. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4568. this.ServeSuccessJSON(map[string]interface{}{
  4569. "dialysis_order": dialysisRecords,
  4570. })
  4571. }
  4572. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4573. record_id, _ := c.GetInt64("id")
  4574. nurseID, _ := c.GetInt64("nurse")
  4575. end_time := c.GetString("end_time")
  4576. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4577. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4578. catheter := c.GetString("catheter")
  4579. cruor := c.GetString("cruor")
  4580. mission := c.GetString("mission")
  4581. condenser := c.GetString("condenser")
  4582. if record_id <= 0 || nurseID <= 0 {
  4583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4584. return
  4585. }
  4586. adminUserInfo := c.GetMobileAdminUserInfo()
  4587. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4588. if getNurseErr != nil {
  4589. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4591. return
  4592. } else if nurse == nil {
  4593. c.ErrorLog("护士不存在")
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4595. return
  4596. }
  4597. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4598. if parseEndDateErr != nil {
  4599. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4601. return
  4602. }
  4603. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4604. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4605. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4606. // if getPermissionErr != nil {
  4607. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4608. // return
  4609. // } else if headNursePermission == nil {
  4610. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4611. // return
  4612. // }
  4613. //}
  4614. // 查询信息规挡的设置天数
  4615. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4616. if infor.ID > 0 {
  4617. var cha_time int64
  4618. timeNowStr := time.Now().Format("2006-01-02")
  4619. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4620. //今日的日期减去设置的日期
  4621. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4622. if cha_time >= tempDialysisRecords.DialysisDate {
  4623. //查询审核是否允许
  4624. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4625. //申请状态不允许的情况 拒绝修改
  4626. if infor.ApplicationStatus != 1 {
  4627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4628. return
  4629. }
  4630. }
  4631. }
  4632. dialysisRecord := &models.DialysisOrder{
  4633. ID: record_id,
  4634. UserOrgId: adminUserInfo.Org.Id,
  4635. EndTime: endDate.Unix(),
  4636. FinishNurse: nurseID,
  4637. FinishModifier: adminUserInfo.AdminUser.Id,
  4638. PuncturePointHaematoma: puncture_point_haematoma,
  4639. BloodAccessInternalFistula: blood_access_internal_fistula,
  4640. Catheter: catheter,
  4641. Cruor: cruor,
  4642. Mission: mission,
  4643. Condenser: condenser,
  4644. }
  4645. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4646. redis := service.RedisClient()
  4647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4648. //清空key 值
  4649. redis.Set(key, "", time.Second)
  4650. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4651. //清空key 值
  4652. redis.Set(keyOne, "", time.Second)
  4653. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4654. redis.Set(keySeven, "", time.Second)
  4655. redis.Close()
  4656. if updateErr != nil {
  4657. c.ErrorLog("修改下机失败:%v", updateErr)
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4659. return
  4660. }
  4661. if updateErr == nil {
  4662. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4663. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4664. a, b := math.Modf(value)
  4665. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4666. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4667. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4668. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4669. redis := service.RedisClient()
  4670. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4671. redis.Set(keyTen, "", time.Second)
  4672. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4673. redis.Set(keyTwo, "", time.Second)
  4674. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4675. redis.Set(key, "", time.Second)
  4676. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4677. redis.Set(keyThree, "", time.Second)
  4678. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4679. redis.Set(keySeven, "", time.Second)
  4680. defer redis.Close()
  4681. if updateAssessmentErr != nil {
  4682. utils.ErrorLog("%v", updateAssessmentErr)
  4683. }
  4684. }
  4685. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4686. c.ServeSuccessJSON(map[string]interface{}{
  4687. "dialysis_order": dialysisRecords,
  4688. })
  4689. }
  4690. func (c *DialysisAPIController) GetLongAdvice() {
  4691. patient_id, _ := c.GetInt64("id")
  4692. adminUserInfo := c.GetMobileAdminUserInfo()
  4693. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4694. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4695. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4696. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4697. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4698. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4699. c.ServeSuccessJSON(map[string]interface{}{
  4700. "status": "1",
  4701. })
  4702. return
  4703. } else { //开启推送提醒
  4704. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4705. var advice_three []*models.DoctorAdvice
  4706. recordDateStr := time.Now().Format("2006-01-02")
  4707. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4708. nowtime := recordDate.Unix()
  4709. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4710. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4711. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4712. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4713. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4714. for _, advice := range advices {
  4715. if advice.FrequencyType == 3 {
  4716. t := time.Now()
  4717. week := int(t.Weekday())
  4718. fmt.Println(t.Weekday())
  4719. fmt.Println(week)
  4720. switch week {
  4721. case 1:
  4722. if strings.Index(advice.WeekDay, "周一") == -1 {
  4723. advice_three = append(advice_three, advice)
  4724. }
  4725. break
  4726. case 2:
  4727. if strings.Index(advice.WeekDay, "周二") == -1 {
  4728. advice_three = append(advice_three, advice)
  4729. }
  4730. break
  4731. case 3:
  4732. if strings.Index(advice.WeekDay, "周三") == -1 {
  4733. advice_three = append(advice_three, advice)
  4734. }
  4735. break
  4736. case 4:
  4737. if strings.Index(advice.WeekDay, "周四") == -1 {
  4738. advice_three = append(advice_three, advice)
  4739. }
  4740. break
  4741. case 5:
  4742. if strings.Index(advice.WeekDay, "周五") == -1 {
  4743. advice_three = append(advice_three, advice)
  4744. }
  4745. break
  4746. case 6:
  4747. if strings.Index(advice.WeekDay, "周六") == -1 {
  4748. advice_three = append(advice_three, advice)
  4749. }
  4750. break
  4751. case 0:
  4752. if strings.Index(advice.WeekDay, "周日") == -1 {
  4753. advice_three = append(advice_three, advice)
  4754. }
  4755. break
  4756. }
  4757. }
  4758. }
  4759. for _, advice := range advices_two {
  4760. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4761. now := p.Unix()
  4762. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4763. dayStr2 := "-" + dayStr
  4764. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4765. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4766. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4767. for _, ad := range advices {
  4768. advice_three = append(advice_three, ad)
  4769. }
  4770. }
  4771. if err == nil {
  4772. c.ServeSuccessJSON(map[string]interface{}{
  4773. "status": "2",
  4774. "advices": advices,
  4775. "advices_two": RemoveRepeatedElement(advice_three),
  4776. "is_open_remind": config.IsOpenRemind,
  4777. "his_config_open": hisConfig.IsOpen,
  4778. "is_advice_open": is_advice_open.IsAdviceOpen,
  4779. "prescription_open": prescription_open.IsOpen,
  4780. })
  4781. }
  4782. }
  4783. }
  4784. func (c *DialysisAPIController) GetLongAdviceOne() {
  4785. patient_id, _ := c.GetInt64("id")
  4786. startTime := c.GetString("schedule_date")
  4787. timeLayout := "2006-01-02"
  4788. loc, _ := time.LoadLocation("Local")
  4789. var theStartTime int64
  4790. if len(startTime) > 0 {
  4791. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4792. if err != nil {
  4793. utils.ErrorLog(err.Error())
  4794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4795. return
  4796. }
  4797. theStartTime = theTime.Unix()
  4798. }
  4799. adminUserInfo := c.GetMobileAdminUserInfo()
  4800. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4801. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4802. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4803. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4804. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4805. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4806. c.ServeSuccessJSON(map[string]interface{}{
  4807. "status": "1",
  4808. })
  4809. return
  4810. } else { //开启推送提醒
  4811. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4812. var advice_three []*models.DoctorAdvice
  4813. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4814. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4815. for _, advice := range advices {
  4816. if advice.FrequencyType == 3 {
  4817. t := time.Now()
  4818. week := int(t.Weekday())
  4819. fmt.Println(t.Weekday())
  4820. fmt.Println(week)
  4821. switch week {
  4822. case 1:
  4823. if strings.Index(advice.WeekDay, "周一") == -1 {
  4824. advice_three = append(advice_three, advice)
  4825. }
  4826. break
  4827. case 2:
  4828. if strings.Index(advice.WeekDay, "周二") == -1 {
  4829. advice_three = append(advice_three, advice)
  4830. }
  4831. break
  4832. case 3:
  4833. if strings.Index(advice.WeekDay, "周三") == -1 {
  4834. advice_three = append(advice_three, advice)
  4835. }
  4836. break
  4837. case 4:
  4838. if strings.Index(advice.WeekDay, "周四") == -1 {
  4839. advice_three = append(advice_three, advice)
  4840. }
  4841. break
  4842. case 5:
  4843. if strings.Index(advice.WeekDay, "周五") == -1 {
  4844. advice_three = append(advice_three, advice)
  4845. }
  4846. break
  4847. case 6:
  4848. if strings.Index(advice.WeekDay, "周六") == -1 {
  4849. advice_three = append(advice_three, advice)
  4850. }
  4851. break
  4852. case 0:
  4853. if strings.Index(advice.WeekDay, "周日") == -1 {
  4854. advice_three = append(advice_three, advice)
  4855. }
  4856. break
  4857. }
  4858. }
  4859. }
  4860. for _, advice := range advices_two {
  4861. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4862. now := p.Unix()
  4863. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4864. dayStr2 := "-" + dayStr
  4865. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4866. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4867. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4868. for _, ad := range advices {
  4869. advice_three = append(advice_three, ad)
  4870. }
  4871. }
  4872. if err == nil {
  4873. c.ServeSuccessJSON(map[string]interface{}{
  4874. "status": "2",
  4875. "advices": advices,
  4876. "advices_two": RemoveRepeatedElement(advice_three),
  4877. "is_open_remind": config.IsOpenRemind,
  4878. "his_config_open": hisConfig.IsOpen,
  4879. "is_advice_open": is_advice_open.IsAdviceOpen,
  4880. "prescription_open": prescription_open.IsOpen,
  4881. })
  4882. }
  4883. }
  4884. }
  4885. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4886. newArr = make([]*models.DoctorAdvice, 0)
  4887. for i := 0; i < len(arr); i++ {
  4888. repeat := false
  4889. for j := i + 1; j < len(arr); j++ {
  4890. if arr[i].ID == arr[j].ID {
  4891. repeat = true
  4892. break
  4893. }
  4894. }
  4895. if !repeat {
  4896. newArr = append(newArr, arr[i])
  4897. }
  4898. }
  4899. return
  4900. }
  4901. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4902. patient, _ := c.GetInt64("id", 0)
  4903. groupNo, _ := c.GetInt64("groupno", 0)
  4904. if patient <= 0 {
  4905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4906. return
  4907. }
  4908. adminUserInfo := c.GetMobileAdminUserInfo()
  4909. dataBody := make(map[string]interface{}, 0)
  4910. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4911. if err != nil {
  4912. utils.ErrorLog(err.Error())
  4913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. utils.ErrorLog("%v", dataBody)
  4917. timeLayout := "2006-01-02 15:04"
  4918. loc, _ := time.LoadLocation("Local")
  4919. timeLayout2 := "2006-01-02"
  4920. loc2, _ := time.LoadLocation("Local")
  4921. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4922. utils.ErrorLog("advice_type")
  4923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4924. return
  4925. }
  4926. adviceType := int64(2)
  4927. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4928. utils.ErrorLog("advice_date")
  4929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4930. return
  4931. }
  4932. adviceDate, _ := dataBody["advice_date"].(string)
  4933. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4934. AdviceDate := theTime.Unix()
  4935. RecordDate := theTime.Unix()
  4936. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4937. utils.ErrorLog("start_time")
  4938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4939. return
  4940. }
  4941. startTime, _ := dataBody["start_time"].(string)
  4942. if len(startTime) == 0 {
  4943. utils.ErrorLog("len(start_time) == 0")
  4944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4945. return
  4946. }
  4947. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4948. if err != nil {
  4949. utils.ErrorLog(err.Error())
  4950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4951. return
  4952. }
  4953. StartTime := theTime.Unix()
  4954. Remark := ""
  4955. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4956. remark, _ := dataBody["remark"].(string)
  4957. Remark = remark
  4958. }
  4959. var advices []*models.GroupAdvice
  4960. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4961. utils.ErrorLog("advices")
  4962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4963. return
  4964. }
  4965. adviceNames := dataBody["advices"].([]interface{})
  4966. for _, adviceNameMap := range adviceNames {
  4967. adviceNameM := adviceNameMap.(map[string]interface{})
  4968. var advice models.GroupAdvice
  4969. advice.Remark = Remark
  4970. advice.AdviceType = adviceType
  4971. advice.StartTime = StartTime
  4972. advice.AdviceDate = AdviceDate
  4973. advice.RecordDate = RecordDate
  4974. advice.Status = 1
  4975. advice.CreatedTime = time.Now().Unix()
  4976. advice.UpdatedTime = time.Now().Unix()
  4977. advice.StopState = 2
  4978. advice.ExecutionState = 2
  4979. advice.UserOrgId = adminUserInfo.Org.Id
  4980. advice.PatientId = patient
  4981. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4982. advice.IsSettle = 2
  4983. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4984. utils.ErrorLog("advice_name")
  4985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4986. return
  4987. }
  4988. adviceName, _ := adviceNameM["advice_name"].(string)
  4989. if len(adviceName) == 0 {
  4990. utils.ErrorLog("len(advice_name) == 0")
  4991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4992. return
  4993. }
  4994. advice.AdviceName = adviceName
  4995. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4996. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4997. advice.DrugSpec = drugSpec
  4998. }
  4999. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5000. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5001. advice.AdviceDesc = adviceDesc
  5002. }
  5003. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5004. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5005. advice.DrugSpecUnit = drugSpecUnit
  5006. }
  5007. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5008. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5009. // advice.SingleDose = singleDose
  5010. //}
  5011. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5012. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5013. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5014. }
  5015. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5016. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5017. advice.SingleDoseUnit = singleDoseUnit
  5018. }
  5019. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5020. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5021. // advice.PrescribingNumber = prescribingNumber
  5022. //}
  5023. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5024. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5025. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5026. }
  5027. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5028. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5029. advice.PrescribingNumberUnit = prescribingNumberUnit
  5030. }
  5031. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5032. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5033. advice.DeliveryWay = deliveryWay
  5034. }
  5035. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5036. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5037. advice.ExecutionFrequency = executionFrequency
  5038. }
  5039. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5040. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5041. advice.FrequencyType = frequency_type
  5042. }
  5043. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5044. day_count := int64(adviceNameM["day_count"].(float64))
  5045. advice.DayCount = day_count
  5046. }
  5047. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5048. week_day, _ := adviceNameM["week_day"].(string)
  5049. advice.WeekDay = week_day
  5050. }
  5051. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5052. way := int64(adviceNameM["way"].(float64))
  5053. advice.Way = way
  5054. }
  5055. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5056. drug_id := int64(adviceNameM["drug_id"].(float64))
  5057. advice.DrugId = drug_id
  5058. }
  5059. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5060. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5061. advice.DrugNameId = drug_name_id
  5062. }
  5063. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5064. remark, _ := adviceNameM["remark"].(string)
  5065. advice.Remark = remark
  5066. }
  5067. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5068. groupno := int64(adviceNameM["groupno"].(float64))
  5069. advice.GroupNo = groupno
  5070. }
  5071. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5072. template_id, _ := adviceNameM["template_id"].(string)
  5073. advice.TemplateId = template_id
  5074. }
  5075. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5076. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5077. advice.ExecutionFrequency = executionFrequency
  5078. }
  5079. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5080. children := adviceNameM["child"].([]interface{})
  5081. if len(children) > 0 {
  5082. for _, childrenMap := range children {
  5083. childMap := childrenMap.(map[string]interface{})
  5084. var child models.GroupAdvice
  5085. child.Remark = Remark
  5086. child.AdviceType = adviceType
  5087. child.StartTime = StartTime
  5088. child.AdviceDate = AdviceDate
  5089. child.RecordDate = RecordDate
  5090. child.Status = 1
  5091. child.CreatedTime = time.Now().Unix()
  5092. child.UpdatedTime = time.Now().Unix()
  5093. child.StopState = 2
  5094. child.ExecutionState = 2
  5095. child.UserOrgId = adminUserInfo.Org.Id
  5096. child.PatientId = patient
  5097. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5098. child.IsSettle = 1
  5099. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5100. utils.ErrorLog("child advice_name")
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5102. return
  5103. }
  5104. childAdviceName, _ := childMap["advice_name"].(string)
  5105. if len(childAdviceName) == 0 {
  5106. utils.ErrorLog("len(child advice_name) == 0")
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5108. return
  5109. }
  5110. child.AdviceName = childAdviceName
  5111. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5112. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5113. child.AdviceDesc = childAdviceDesc
  5114. }
  5115. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5116. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5117. child.DrugSpec = childDrugSpec
  5118. }
  5119. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5120. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5121. child.DrugSpecUnit = childDrugSpecUnit
  5122. }
  5123. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5124. child.SingleDose = childMap["single_dose"].(float64)
  5125. }
  5126. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5127. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5128. child.SingleDoseUnit = childSingleDoseUnit
  5129. }
  5130. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5131. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5132. }
  5133. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5134. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5135. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5136. }
  5137. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5138. groupno := int64(childMap["groupno"].(float64))
  5139. advice.GroupNo = groupno
  5140. }
  5141. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5142. remark, _ := childMap["remark"].(string)
  5143. child.Remark = remark
  5144. }
  5145. child.DeliveryWay = advice.DeliveryWay
  5146. child.ExecutionFrequency = advice.ExecutionFrequency
  5147. advice.Children = append(advice.Children, &child)
  5148. }
  5149. }
  5150. }
  5151. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5152. if temp_advice.ID == 0 {
  5153. advices = append(advices, &advice)
  5154. }
  5155. }
  5156. if len(advices) > 0 {
  5157. finish := models.XtDialysisFinish{
  5158. IsFinish: 1,
  5159. UserOrgId: adminUserInfo.Org.Id,
  5160. Status: 1,
  5161. Ctime: time.Now().Unix(),
  5162. Mtime: 0,
  5163. Module: 4,
  5164. RecordDate: AdviceDate,
  5165. Sourse: 1,
  5166. PatientId: patient,
  5167. }
  5168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5169. if dialysisFinish.ID == 0 {
  5170. service.CreateDialysisFinish(finish)
  5171. }
  5172. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5173. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5174. for _, item := range advices {
  5175. byterequest, _ := json.Marshal(item)
  5176. adviceLog := models.XtDoctorAdviceLog{
  5177. UserOrgId: adminUserInfo.Org.Id,
  5178. PatientId: patient,
  5179. AdminUserId: adminUserInfo.AdminUser.Id,
  5180. Module: 1,
  5181. ErrLog: string(byterequest),
  5182. Status: 1,
  5183. Ctime: time.Now().Unix(),
  5184. Mtime: 0,
  5185. Source: "手机端医嘱推送",
  5186. RecordDate: item.AdviceDate,
  5187. }
  5188. service.CreateDoctorAdviceLog(adviceLog)
  5189. }
  5190. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5191. redis := service.RedisClient()
  5192. //清空key 值
  5193. redis.Set(key, "", time.Second)
  5194. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5195. redis.Set(keyOne, "", time.Second)
  5196. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5197. defer redis.Close()
  5198. redis.Set(keyThree, "", time.Second)
  5199. if err != nil {
  5200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5201. return
  5202. }
  5203. c.ServeSuccessJSON(map[string]interface{}{
  5204. "msg": "ok",
  5205. "advices": list,
  5206. })
  5207. } else {
  5208. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5209. for _, item := range advices {
  5210. byterequest, _ := json.Marshal(item)
  5211. adviceLog := models.XtDoctorAdviceLog{
  5212. UserOrgId: adminUserInfo.Org.Id,
  5213. PatientId: patient,
  5214. AdminUserId: adminUserInfo.AdminUser.Id,
  5215. Module: 1,
  5216. ErrLog: string(byterequest),
  5217. Status: 1,
  5218. Ctime: time.Now().Unix(),
  5219. Mtime: 0,
  5220. Source: "手机端医嘱推送",
  5221. RecordDate: item.AdviceDate,
  5222. }
  5223. service.CreateDoctorAdviceLog(adviceLog)
  5224. }
  5225. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5226. redis := service.RedisClient()
  5227. //清空key 值
  5228. redis.Set(key, "", time.Second)
  5229. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5230. redis.Set(keyOne, "", time.Second)
  5231. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5232. defer redis.Close()
  5233. redis.Set(keyThree, "", time.Second)
  5234. if err != nil {
  5235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5236. return
  5237. }
  5238. c.ServeSuccessJSON(map[string]interface{}{
  5239. "msg": "ok",
  5240. "advices": list,
  5241. })
  5242. }
  5243. } else {
  5244. c.ServeSuccessJSON(map[string]interface{}{
  5245. "msg": "ok",
  5246. })
  5247. }
  5248. return
  5249. }
  5250. func (c *DialysisAPIController) UploadDryWeight() {
  5251. patient_id, _ := c.GetInt64("id")
  5252. dry_weight, _ := c.GetFloat("dry_weight")
  5253. doctor_id, _ := c.GetInt64("doctor_id")
  5254. remark := c.GetString("remark")
  5255. adminUserInfo := c.GetMobileAdminUserInfo()
  5256. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5257. if err == gorm.ErrRecordNotFound {
  5258. dryWeight := &models.SgjPatientDryweight{
  5259. PatientId: patient_id,
  5260. DryWeight: dry_weight,
  5261. Remakes: remark,
  5262. Ctime: time.Now().Unix(),
  5263. Mtime: time.Now().Unix(),
  5264. Creator: doctor_id,
  5265. Status: 1,
  5266. UserOrgId: adminUserInfo.Org.Id,
  5267. AdjustedValue: "/",
  5268. UserId: adminUserInfo.AdminUser.Id,
  5269. }
  5270. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5271. redis := service.RedisClient()
  5272. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5273. redis.Set(keyOne, "", time.Second)
  5274. loc, _ := time.LoadLocation("Local")
  5275. nowTime := time.Now()
  5276. nowDay := nowTime.Format("2006-01-02")
  5277. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5278. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5279. redis.Set(key, "", time.Second)
  5280. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5281. redis.Set(keyTwo, "", time.Second)
  5282. redis.Close()
  5283. if createErr == nil {
  5284. c.ServeSuccessJSON(map[string]interface{}{
  5285. "msg": "提交成功",
  5286. "weight": dryWeight,
  5287. })
  5288. }
  5289. } else {
  5290. dryWeight := &models.SgjPatientDryweight{
  5291. PatientId: patient_id,
  5292. DryWeight: dry_weight,
  5293. Remakes: remark,
  5294. Ctime: time.Now().Unix(),
  5295. Mtime: time.Now().Unix(),
  5296. Creator: doctor_id,
  5297. Status: 1,
  5298. UserOrgId: adminUserInfo.Org.Id,
  5299. AdjustedValue: "/",
  5300. UserId: adminUserInfo.AdminUser.Id,
  5301. }
  5302. var value float64
  5303. value = dry_weight - weightAdjust.DryWeight
  5304. if value < 0 {
  5305. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5306. } else if value == 0 {
  5307. dryWeight.AdjustedValue = "/"
  5308. } else if value > 0 {
  5309. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5310. }
  5311. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5312. //康桥
  5313. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5314. timeNowStr := time.Now().Format("2006-01-02")
  5315. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5316. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5317. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5318. if beforAssesment.ID > 0 {
  5319. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5320. var dewater_amount float64
  5321. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5322. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5323. //获取key,清空redis
  5324. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5325. redis := service.RedisClient()
  5326. //清空key 值
  5327. redis.Set(key, "", time.Second)
  5328. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5329. //清空key 值
  5330. redis.Set(keyOne, "", time.Second)
  5331. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5332. //清空key 值
  5333. redis.Set(keyTwo, "", time.Second)
  5334. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5335. redis.Set(keySix, "", time.Second)
  5336. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5337. redis.Set(keySeven, "", time.Second)
  5338. }
  5339. }
  5340. redis := service.RedisClient()
  5341. loc, _ := time.LoadLocation("Local")
  5342. nowTime := time.Now()
  5343. nowDay := nowTime.Format("2006-01-02")
  5344. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5345. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5346. redis.Set(keyOne, "", time.Second)
  5347. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5348. redis.Set(key, "", time.Second)
  5349. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5350. redis.Set(keyTwo, "", time.Second)
  5351. redis.Close()
  5352. if createErr == nil {
  5353. c.ServeSuccessJSON(map[string]interface{}{
  5354. "msg": "提交成功",
  5355. "weight": dryWeight,
  5356. })
  5357. }
  5358. }
  5359. }
  5360. func (c *DialysisAPIController) GetSolution() {
  5361. patient_id, _ := c.GetInt64("patient_id")
  5362. mode_id, _ := c.GetInt64("mode_id")
  5363. adminUserInfo := c.GetMobileAdminUserInfo()
  5364. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5365. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5366. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5367. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5368. if err != nil {
  5369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5370. return
  5371. }
  5372. c.ServeSuccessJSON(map[string]interface{}{
  5373. "solution": solution,
  5374. "prescription": prescription,
  5375. "system_prescription": system_prescription,
  5376. "dialysisPrescription": dialysisPrescription,
  5377. })
  5378. }
  5379. func (c *DialysisAPIController) GetSchedule() {
  5380. schedual_type, _ := c.GetInt64("schedual_type")
  5381. adminUserInfo := c.GetMobileAdminUserInfo()
  5382. scheduleTime, _ := c.GetInt64("record_date")
  5383. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5384. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5385. c.ServeSuccessJSON(map[string]interface{}{
  5386. "number": deviceNumber,
  5387. "list": list,
  5388. })
  5389. }
  5390. func (c *DialysisAPIController) GetPatientId() {
  5391. id, _ := c.GetInt64("id")
  5392. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5393. patientId, _ := service.GetPatientId(id)
  5394. //获取该患者的所有传染病
  5395. list, _ := service.GetPatientInfectious(id)
  5396. c.ServeSuccessJSON(map[string]interface{}{
  5397. "patient": patientId,
  5398. "infectioulist": list,
  5399. })
  5400. }
  5401. func (this *DialysisAPIController) GetDialysisSchedule() {
  5402. schedualDate := this.GetString("date")
  5403. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5404. if parseDateErr != nil {
  5405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5406. return
  5407. }
  5408. adminInfo := this.GetMobileAdminUserInfo()
  5409. orgID := adminInfo.Org.Id
  5410. redis := service.RedisClient()
  5411. defer redis.Close()
  5412. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5413. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5414. if len(scheduals) > 0 {
  5415. //缓存数据
  5416. scheduals_json, err := json.Marshal(scheduals)
  5417. if err == nil {
  5418. redis.Set(key, scheduals_json, time.Second*30)
  5419. }
  5420. }
  5421. this.ServeSuccessJSON(map[string]interface{}{
  5422. "scheduals": scheduals,
  5423. })
  5424. }
  5425. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5426. change_type, _ := this.GetInt64("type", 0)
  5427. record_date := this.GetString("record_time")
  5428. patient_id, _ := this.GetInt64("patient_id", 0)
  5429. timeLayout := "2006-01-02"
  5430. loc, _ := time.LoadLocation("Local")
  5431. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5432. record_time := theAdviceRecordTime.Unix()
  5433. adminUserInfo := this.GetMobileAdminUserInfo()
  5434. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5435. if err == nil {
  5436. if len(advices) == 0 {
  5437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5438. return
  5439. } else {
  5440. this.ServeSuccessJSON(map[string]interface{}{
  5441. "advices": advices,
  5442. "schedule": sch,
  5443. })
  5444. return
  5445. }
  5446. } else {
  5447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5448. return
  5449. }
  5450. }
  5451. func (c *DialysisAPIController) CreateConsumables() {
  5452. record_date := c.GetString("record_time")
  5453. patient_id, _ := c.GetInt64("patient_id", 0)
  5454. active, _ := c.GetInt64("active")
  5455. adminUser := c.GetMobileAdminUserInfo()
  5456. timeLayout := "2006-01-02"
  5457. loc, _ := time.LoadLocation("Local")
  5458. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5459. record_time := theRecordTime.Unix()
  5460. // 查询信息规挡的设置天数
  5461. orgid := c.GetMobileAdminUserInfo().Org.Id
  5462. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5463. if infor.ID > 0 {
  5464. var cha_time int64
  5465. timeNowStr := time.Now().Format("2006-01-02")
  5466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5467. //今日的日期减去设置的日期
  5468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5469. if cha_time >= record_time {
  5470. //查询审核是否允许
  5471. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5472. //申请状态不允许的情况 拒绝修改
  5473. if infor.ApplicationStatus != 1 {
  5474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5475. return
  5476. }
  5477. }
  5478. }
  5479. dataBody := make(map[string]interface{}, 0)
  5480. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5481. if err != nil {
  5482. utils.ErrorLog(err.Error())
  5483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5484. return
  5485. }
  5486. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5487. var beforePrepares []*models.DialysisBeforePrepareGoods
  5488. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5489. var dialysisBefor []*models.DialysisBeforePrepare
  5490. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5491. goods, _ := dataBody["goods"].([]interface{})
  5492. if len(goods) > 0 {
  5493. for _, item := range goods {
  5494. items := item.(map[string]interface{})
  5495. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5496. utils.ErrorLog("good_id")
  5497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5498. return
  5499. }
  5500. good_id := int64(items["good_id"].(float64))
  5501. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5502. utils.ErrorLog("good_type_id")
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5504. return
  5505. }
  5506. good_type_id := int64(items["good_type_id"].(float64))
  5507. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5508. utils.ErrorLog("count")
  5509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5510. return
  5511. }
  5512. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5513. commdity_code := items["commdity_code"].(string)
  5514. fmt.Println("commdity", commdity_code)
  5515. prepareGoods := &models.DialysisBeforePrepareGoods{
  5516. GoodTypeId: good_type_id,
  5517. GoodId: good_id,
  5518. Count: count,
  5519. StorehouseId: houseConfig.StorehouseOutInfo,
  5520. }
  5521. beforePrepares = append(beforePrepares, prepareGoods)
  5522. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5523. GoodTypeId: good_type_id,
  5524. GoodId: good_id,
  5525. Count: count,
  5526. StorehouseId: houseConfig.StorehouseOutInfo,
  5527. }
  5528. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5529. prepare := &models.DialysisBeforePrepare{
  5530. GoodTypeId: good_type_id,
  5531. GoodId: good_id,
  5532. Count: count,
  5533. PatientId: patient_id,
  5534. RecordDate: record_time,
  5535. UserOrgId: adminUser.Org.Id,
  5536. Status: 1,
  5537. Ctime: time.Now().Unix(),
  5538. Creater: adminUser.AdminUser.Id,
  5539. CommdityCode: commdity_code,
  5540. StorehouseId: houseConfig.StorehouseOutInfo,
  5541. }
  5542. dialysisBefor = append(dialysisBefor, prepare)
  5543. }
  5544. }
  5545. //查询是否有库存
  5546. for _, item := range dialysisBefor {
  5547. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5548. if err == gorm.ErrRecordNotFound {
  5549. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5550. c.ServeSuccessJSON(map[string]interface{}{
  5551. "message": "1",
  5552. "good_name": goodObj.GoodName,
  5553. "specification_name": goodObj.SpecificationName,
  5554. })
  5555. return
  5556. }
  5557. if err != nil {
  5558. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5559. c.ServeSuccessJSON(map[string]interface{}{
  5560. "message": "1",
  5561. "good_name": goodObj.GoodName,
  5562. "specification_name": goodObj.SpecificationName,
  5563. })
  5564. return
  5565. }
  5566. }
  5567. fmt.Println("active-----------------------", active)
  5568. fmt.Println("len(goods)-----------------------", len(goods))
  5569. //新增
  5570. if active == 1 && len(goods) > 0 {
  5571. for _, item := range dialysisBefor {
  5572. dialyPrepareOne := models.DialysisBeforePrepare{
  5573. GoodTypeId: item.GoodTypeId,
  5574. GoodId: item.GoodId,
  5575. PatientId: item.PatientId,
  5576. RecordDate: item.RecordDate,
  5577. UserOrgId: item.UserOrgId,
  5578. Count: item.Count,
  5579. Ctime: time.Now().Unix(),
  5580. Creater: item.Creater,
  5581. CommdityCode: item.CommdityCode,
  5582. Status: 1,
  5583. StorehouseId: houseConfig.StorehouseOutInfo,
  5584. }
  5585. //先清除再插入
  5586. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5587. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5588. //查询默认仓库
  5589. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5590. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5591. var total_count int64
  5592. for _, it := range stockList {
  5593. total_count += it.StockCount
  5594. }
  5595. //基础库插入数据
  5596. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5597. //更新库存
  5598. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5599. var flush_count int64
  5600. for _, it := range goodList {
  5601. flush_count += it.StockCount
  5602. }
  5603. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5604. }
  5605. if err == nil {
  5606. c.ServeSuccessJSON(map[string]interface{}{
  5607. "msg": "保存成功",
  5608. "message": "2",
  5609. })
  5610. return
  5611. } else {
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5613. return
  5614. }
  5615. }
  5616. if len(beforePrepares) > 0 && active == 2 {
  5617. for _, item := range beforePrepares {
  5618. //1.查看该患者该耗材型号最后一次出库数量
  5619. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5620. //判断当前出库数量和最后一次出库数量的大小
  5621. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5622. if item.Count <= goodInfo.Count {
  5623. //退库
  5624. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5625. //查询今日出库数据
  5626. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5627. for _, it := range list {
  5628. prepare := models.DialysisBeforePrepare{
  5629. UserOrgId: it.OrgId,
  5630. PatientId: patient_id,
  5631. RecordDate: it.RecordTime,
  5632. GoodId: it.GoodId,
  5633. GoodTypeId: it.GoodTypeId,
  5634. Count: it.Count,
  5635. Ctime: time.Now().Unix(),
  5636. Creater: adminUser.AdminUser.Id,
  5637. Status: 1,
  5638. StorehouseId: houseConfig.StorehouseOutInfo,
  5639. }
  5640. //删除准备表数据
  5641. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5642. service.CreateDialysisBeforePrepareOne(&prepare)
  5643. }
  5644. }
  5645. var last_total int64
  5646. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5647. if item.Count >= goodInfo.Count {
  5648. //查询当前批次当前耗材最后一条出库数据
  5649. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5650. //计算当前出库和最后一次出库数据相差数据
  5651. last_total = item.Count - lastOutInfo.Count
  5652. //查询该批次剩余库存
  5653. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5654. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5655. if lastInfo.StockCount >= last_total {
  5656. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5657. //查询今日出库数据
  5658. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5659. for _, it := range list {
  5660. prepare := models.DialysisBeforePrepare{
  5661. UserOrgId: it.OrgId,
  5662. PatientId: patient_id,
  5663. RecordDate: it.RecordTime,
  5664. GoodId: it.GoodId,
  5665. GoodTypeId: it.GoodTypeId,
  5666. Count: it.Count,
  5667. Ctime: time.Now().Unix(),
  5668. Creater: adminUser.AdminUser.Id,
  5669. Status: 1,
  5670. StorehouseId: houseConfig.StorehouseOutInfo,
  5671. }
  5672. //删除准备表数据
  5673. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5674. service.CreateDialysisBeforePrepareOne(&prepare)
  5675. //查询默认仓库
  5676. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5677. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5678. var total_count int64
  5679. for _, it := range stockList {
  5680. total_count += it.StockCount
  5681. }
  5682. //基础库插入数据
  5683. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5684. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5685. var flush_count int64
  5686. for _, it := range goodList {
  5687. flush_count += it.StockCount
  5688. }
  5689. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5690. }
  5691. }
  5692. //如果库存不够,则出库到下一个批次
  5693. if lastInfo.StockCount < last_total {
  5694. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5695. //查询今日出库数据
  5696. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5697. for _, it := range list {
  5698. prepare := models.DialysisBeforePrepare{
  5699. UserOrgId: it.OrgId,
  5700. PatientId: patient_id,
  5701. RecordDate: it.RecordTime,
  5702. GoodId: it.GoodId,
  5703. GoodTypeId: it.GoodTypeId,
  5704. Count: it.Count,
  5705. Ctime: time.Now().Unix(),
  5706. Creater: adminUser.AdminUser.Id,
  5707. Status: 1,
  5708. StorehouseId: houseConfig.StorehouseOutInfo,
  5709. }
  5710. //删除准备表数据
  5711. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5712. service.CreateDialysisBeforePrepareOne(&prepare)
  5713. //查询默认仓库
  5714. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5715. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5716. var total_count int64
  5717. for _, it := range stockList {
  5718. total_count += it.StockCount
  5719. }
  5720. //基础库插入数据
  5721. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5722. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5723. var flush_count int64
  5724. for _, it := range goodList {
  5725. flush_count += it.StockCount
  5726. }
  5727. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5728. }
  5729. if err != nil {
  5730. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5731. c.ServeSuccessJSON(map[string]interface{}{
  5732. "message": "1",
  5733. "good_name": goodObj.GoodName,
  5734. "specification_name": goodObj.SpecificationName,
  5735. })
  5736. return
  5737. }
  5738. }
  5739. }
  5740. if err != nil {
  5741. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5742. c.ServeSuccessJSON(map[string]interface{}{
  5743. "message": "1",
  5744. "good_name": goodObj.GoodName,
  5745. "specification_name": goodObj.SpecificationName,
  5746. })
  5747. return
  5748. }
  5749. }
  5750. }
  5751. }
  5752. var errs error
  5753. if errs == nil {
  5754. c.ServeSuccessJSON(map[string]interface{}{
  5755. "msg": "提交成功",
  5756. "message": "2",
  5757. "good_name": "",
  5758. "specification_name": "",
  5759. })
  5760. return
  5761. } else {
  5762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5763. return
  5764. }
  5765. }
  5766. func (c *DialysisAPIController) CreateStockOutInfo() {
  5767. patient_id, _ := c.GetInt64("patient_id", 0)
  5768. record_date := c.GetString("record_time")
  5769. if patient_id <= 0 {
  5770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5771. return
  5772. }
  5773. adminInfo := c.GetMobileAdminUserInfo()
  5774. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5775. timeLayout := "2006-01-02"
  5776. loc, _ := time.LoadLocation("Local")
  5777. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5778. record_time := theRecordTime.Unix()
  5779. // 查询信息规挡的设置天数
  5780. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5781. if infor.ID > 0 && infor.WeekDay > 0 {
  5782. var cha_time int64
  5783. timeNowStr := time.Now().Format("2006-01-02")
  5784. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5785. //今日的日期减去设置的日期
  5786. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5787. if cha_time >= record_time {
  5788. //查询审核是否允许
  5789. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5790. //申请状态不允许的情况 拒绝修改
  5791. if infor.ApplicationStatus != 1 {
  5792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5793. return
  5794. }
  5795. }
  5796. }
  5797. //创建步骤表
  5798. finish := models.XtDialysisFinish{
  5799. IsFinish: 1,
  5800. UserOrgId: adminInfo.Org.Id,
  5801. Status: 1,
  5802. Ctime: time.Now().Unix(),
  5803. Mtime: 0,
  5804. Module: 11,
  5805. RecordDate: record_time,
  5806. Sourse: 1,
  5807. PatientId: patient_id,
  5808. }
  5809. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5810. if dialysisFinish.ID == 0 {
  5811. service.CreateDialysisFinish(finish)
  5812. }
  5813. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5814. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5815. //去重
  5816. consumables = RemoveRepeatedGood(consumables)
  5817. if adminInfo.Org.Id == 9919 {
  5818. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5819. //查询是否有库存
  5820. for _, item := range consumables {
  5821. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5822. if item.Count > warehouse.Count {
  5823. goodErrcode := models.XtGoodErrcode{
  5824. UserOrgId: item.UserOrgId,
  5825. Errcode: "自动出库库存不足",
  5826. GoodId: item.GoodId,
  5827. Status: 1,
  5828. Ctime: time.Now().Unix(),
  5829. Mtime: 0,
  5830. Count: 0,
  5831. StockCount: 0,
  5832. Creater: creator,
  5833. BatchNumberId: warehouse.ID,
  5834. WarehouseOutId: 0,
  5835. }
  5836. service.CreateGoodErrcode(goodErrcode)
  5837. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5838. c.ServeSuccessJSON(map[string]interface{}{
  5839. "message": "1",
  5840. "good_name": goodObj.GoodName,
  5841. "specification_name": goodObj.SpecificationName,
  5842. })
  5843. return
  5844. }
  5845. }
  5846. //查询是否有出库单
  5847. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5848. if err == gorm.ErrRecordNotFound {
  5849. //没有记录,则创建出库单
  5850. timeStr := time.Now().Format("2006-01-02")
  5851. timeArr := strings.Split(timeStr, "-")
  5852. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5853. total = total + 1
  5854. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5855. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5856. number = number + total
  5857. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5858. creater := adminInfo.AdminUser.Id
  5859. warehouseOut := models.WarehouseOut{
  5860. WarehouseOutOrderNumber: warehousing_out_order,
  5861. OperationTime: time.Now().Unix(),
  5862. OrgId: adminInfo.Org.Id,
  5863. Creater: creater,
  5864. Ctime: time.Now().Unix(),
  5865. Status: 1,
  5866. WarehouseOutTime: record_time,
  5867. Dealer: 0,
  5868. Manufacturer: 0,
  5869. Type: 1,
  5870. IsSys: 1,
  5871. StorehouseId: houseConfig.StorehouseOutInfo,
  5872. IsCheck: 1,
  5873. }
  5874. err := service.AddSigleWarehouseOut(&warehouseOut)
  5875. if err != nil {
  5876. goodErrcode := models.XtGoodErrcode{
  5877. UserOrgId: adminInfo.Org.Id,
  5878. Errcode: "创建出库单失败",
  5879. GoodId: 0,
  5880. Status: 1,
  5881. Ctime: time.Now().Unix(),
  5882. Mtime: 0,
  5883. Count: 0,
  5884. StockCount: 0,
  5885. Creater: creator,
  5886. BatchNumberId: 0,
  5887. WarehouseOutId: 0,
  5888. }
  5889. service.CreateGoodErrcode(goodErrcode)
  5890. utils.TraceLog("创建出库单失败 err = %v", err)
  5891. } else {
  5892. for _, item := range consumables {
  5893. //出库
  5894. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5895. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5896. if err == nil {
  5897. goodErrcode := models.XtGoodErrcode{
  5898. UserOrgId: adminInfo.Org.Id,
  5899. Errcode: "自动出库接口报错",
  5900. GoodId: 0,
  5901. Status: 1,
  5902. Ctime: time.Now().Unix(),
  5903. Mtime: 0,
  5904. Count: 0,
  5905. StockCount: 0,
  5906. Creater: creator,
  5907. BatchNumberId: 0,
  5908. WarehouseOutId: 0,
  5909. }
  5910. service.CreateGoodErrcode(goodErrcode)
  5911. utils.TraceLog("创建出库单失败 err = %v", err)
  5912. }
  5913. //查询
  5914. //出库数量相加
  5915. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5916. if errs != nil {
  5917. goodErrcode := models.XtGoodErrcode{
  5918. UserOrgId: item.UserOrgId,
  5919. Errcode: "创建剩余库存字段报错",
  5920. GoodId: item.GoodId,
  5921. Status: 1,
  5922. Ctime: time.Now().Unix(),
  5923. Mtime: 0,
  5924. Count: 0,
  5925. StockCount: 0,
  5926. Creater: creater,
  5927. BatchNumberId: 0,
  5928. WarehouseOutId: 0,
  5929. }
  5930. service.CreateGoodErrcode(goodErrcode)
  5931. }
  5932. }
  5933. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5934. if len(list) == 0 {
  5935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5936. return
  5937. }
  5938. for _, item := range list {
  5939. prepare := models.DialysisBeforePrepare{
  5940. UserOrgId: adminInfo.Org.Id,
  5941. PatientId: patient_id,
  5942. RecordDate: record_time,
  5943. GoodId: item.GoodId,
  5944. GoodTypeId: item.GoodTypeId,
  5945. Count: item.Count,
  5946. Creater: adminInfo.AdminUser.Id,
  5947. Status: 1,
  5948. Ctime: time.Now().Unix(),
  5949. StorehouseId: houseConfig.StorehouseOutInfo,
  5950. }
  5951. //清空准备表数据
  5952. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5953. if err != nil {
  5954. goodErrcode := models.XtGoodErrcode{
  5955. UserOrgId: item.OrgId,
  5956. Errcode: "自动出库清空准备表数据报错",
  5957. GoodId: item.GoodId,
  5958. Status: 1,
  5959. Ctime: time.Now().Unix(),
  5960. Mtime: 0,
  5961. Count: 0,
  5962. StockCount: 0,
  5963. Creater: creater,
  5964. BatchNumberId: 0,
  5965. WarehouseOutId: 0,
  5966. }
  5967. service.CreateGoodErrcode(goodErrcode)
  5968. }
  5969. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5970. if errs != nil {
  5971. goodErrcode := models.XtGoodErrcode{
  5972. UserOrgId: item.OrgId,
  5973. Errcode: "自动出库创建准备表数据报错",
  5974. GoodId: item.GoodId,
  5975. Status: 1,
  5976. Ctime: time.Now().Unix(),
  5977. Mtime: 0,
  5978. Count: 0,
  5979. StockCount: 0,
  5980. Creater: creater,
  5981. BatchNumberId: 0,
  5982. WarehouseOutId: 0,
  5983. }
  5984. service.CreateGoodErrcode(goodErrcode)
  5985. }
  5986. //查询默认仓库
  5987. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5988. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5989. var total_count int64
  5990. for _, it := range stockList {
  5991. total_count += it.StockCount
  5992. }
  5993. //基础库插入数据
  5994. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5995. if errcodes != nil {
  5996. goodErrcode := models.XtGoodErrcode{
  5997. UserOrgId: item.OrgId,
  5998. Errcode: "自动出库基础库插入数据",
  5999. GoodId: item.GoodId,
  6000. Status: 1,
  6001. Ctime: time.Now().Unix(),
  6002. Mtime: 0,
  6003. Count: 0,
  6004. StockCount: 0,
  6005. Creater: creater,
  6006. BatchNumberId: 0,
  6007. WarehouseOutId: 0,
  6008. }
  6009. service.CreateGoodErrcode(goodErrcode)
  6010. }
  6011. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6012. var flush_count int64
  6013. for _, it := range goodList {
  6014. flush_count += it.StockCount
  6015. }
  6016. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6017. if errsss != nil {
  6018. goodErrcode := models.XtGoodErrcode{
  6019. UserOrgId: item.OrgId,
  6020. Errcode: "自动出库剩余库存更新数据",
  6021. GoodId: item.GoodId,
  6022. Status: 1,
  6023. Ctime: time.Now().Unix(),
  6024. Mtime: 0,
  6025. Count: 0,
  6026. StockCount: 0,
  6027. Creater: creater,
  6028. BatchNumberId: 0,
  6029. WarehouseOutId: 0,
  6030. }
  6031. service.CreateGoodErrcode(goodErrcode)
  6032. }
  6033. }
  6034. }
  6035. //
  6036. } else if err == nil {
  6037. for _, item := range consumables {
  6038. //出库
  6039. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6040. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6041. if err != nil {
  6042. goodErrcode := models.XtGoodErrcode{
  6043. UserOrgId: adminInfo.Org.Id,
  6044. Errcode: "自动出库接口报错",
  6045. GoodId: 0,
  6046. Status: 1,
  6047. Ctime: time.Now().Unix(),
  6048. Mtime: 0,
  6049. Count: 0,
  6050. StockCount: 0,
  6051. Creater: creator,
  6052. BatchNumberId: 0,
  6053. WarehouseOutId: 0,
  6054. }
  6055. service.CreateGoodErrcode(goodErrcode)
  6056. }
  6057. //出库数量相加
  6058. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6059. if errss != nil {
  6060. goodErrcode := models.XtGoodErrcode{
  6061. UserOrgId: item.UserOrgId,
  6062. Errcode: "创建剩余库存字段报错",
  6063. GoodId: item.GoodId,
  6064. Status: 1,
  6065. Ctime: time.Now().Unix(),
  6066. Mtime: time.Now().Unix(),
  6067. Count: 0,
  6068. StockCount: 0,
  6069. Creater: item.Creater,
  6070. BatchNumberId: 0,
  6071. WarehouseOutId: 0,
  6072. }
  6073. service.CreateGoodErrcode(goodErrcode)
  6074. }
  6075. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6076. if len(list) == 0 {
  6077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6078. return
  6079. }
  6080. for _, item := range list {
  6081. prepare := models.DialysisBeforePrepare{
  6082. UserOrgId: adminInfo.Org.Id,
  6083. PatientId: patient_id,
  6084. RecordDate: record_time,
  6085. GoodId: item.GoodId,
  6086. GoodTypeId: item.GoodTypeId,
  6087. Count: item.Count,
  6088. Creater: adminInfo.AdminUser.Id,
  6089. Status: 1,
  6090. Ctime: time.Now().Unix(),
  6091. StorehouseId: houseConfig.StorehouseOutInfo,
  6092. }
  6093. //清空准备表数据
  6094. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6095. if errs != nil {
  6096. goodErrcode := models.XtGoodErrcode{
  6097. UserOrgId: adminInfo.Org.Id,
  6098. Errcode: "自动出库清空准备表数据报错",
  6099. GoodId: 0,
  6100. Status: 1,
  6101. Ctime: time.Now().Unix(),
  6102. Mtime: 0,
  6103. Count: 0,
  6104. StockCount: 0,
  6105. Creater: creator,
  6106. BatchNumberId: 0,
  6107. WarehouseOutId: 0,
  6108. }
  6109. service.CreateGoodErrcode(goodErrcode)
  6110. }
  6111. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6112. if errcodes != nil {
  6113. goodErrcode := models.XtGoodErrcode{
  6114. UserOrgId: adminInfo.Org.Id,
  6115. Errcode: "自动出库创建准备表数据报错",
  6116. GoodId: 0,
  6117. Status: 1,
  6118. Ctime: time.Now().Unix(),
  6119. Mtime: 0,
  6120. Count: 0,
  6121. StockCount: 0,
  6122. Creater: creator,
  6123. BatchNumberId: 0,
  6124. WarehouseOutId: 0,
  6125. }
  6126. service.CreateGoodErrcode(goodErrcode)
  6127. }
  6128. //查询默认仓库
  6129. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6130. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6131. var total_count int64
  6132. for _, it := range stockList {
  6133. total_count += it.StockCount
  6134. }
  6135. //基础库插入数据
  6136. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6137. if errcodes != nil {
  6138. goodErrcode := models.XtGoodErrcode{
  6139. UserOrgId: adminInfo.Org.Id,
  6140. Errcode: "自动出库基础库插入数据报错",
  6141. GoodId: 0,
  6142. Status: 1,
  6143. Ctime: time.Now().Unix(),
  6144. Mtime: 0,
  6145. Count: 0,
  6146. StockCount: 0,
  6147. Creater: creator,
  6148. BatchNumberId: 0,
  6149. WarehouseOutId: 0,
  6150. }
  6151. service.CreateGoodErrcode(goodErrcode)
  6152. }
  6153. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6154. var flush_count int64
  6155. for _, it := range goodList {
  6156. flush_count += it.StockCount
  6157. }
  6158. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6159. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6160. if errss != nil {
  6161. goodErrcode := models.XtGoodErrcode{
  6162. UserOrgId: item.OrgId,
  6163. Errcode: "自动出库剩余库存更新数据",
  6164. GoodId: item.GoodId,
  6165. Status: 1,
  6166. Ctime: time.Now().Unix(),
  6167. Mtime: 0,
  6168. Count: 0,
  6169. StockCount: 0,
  6170. Creater: creater,
  6171. BatchNumberId: 0,
  6172. WarehouseOutId: 0,
  6173. }
  6174. service.CreateGoodErrcode(goodErrcode)
  6175. }
  6176. }
  6177. }
  6178. }
  6179. c.ServeSuccessJSON(map[string]interface{}{
  6180. "msg": "提交成功",
  6181. "message": "2",
  6182. "good_name": "",
  6183. "specification_name": "",
  6184. })
  6185. return
  6186. }
  6187. if record.IsOpen == 1 {
  6188. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6189. //查询是否有库存
  6190. for _, item := range consumables {
  6191. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6192. if item.Count > warehouse.Count {
  6193. goodErrcode := models.XtGoodErrcode{
  6194. UserOrgId: item.UserOrgId,
  6195. Errcode: "自动出库库存不足",
  6196. GoodId: item.GoodId,
  6197. Status: 1,
  6198. Ctime: time.Now().Unix(),
  6199. Mtime: 0,
  6200. Count: 0,
  6201. StockCount: 0,
  6202. Creater: creator,
  6203. BatchNumberId: warehouse.ID,
  6204. WarehouseOutId: 0,
  6205. }
  6206. service.CreateGoodErrcode(goodErrcode)
  6207. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6208. c.ServeSuccessJSON(map[string]interface{}{
  6209. "message": "1",
  6210. "good_name": goodObj.GoodName,
  6211. "specification_name": goodObj.SpecificationName,
  6212. })
  6213. return
  6214. }
  6215. }
  6216. //查询是否有出库单
  6217. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6218. if err == gorm.ErrRecordNotFound {
  6219. //没有记录,则创建出库单
  6220. timeStr := time.Now().Format("2006-01-02")
  6221. timeArr := strings.Split(timeStr, "-")
  6222. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6223. total = total + 1
  6224. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6225. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6226. number = number + total
  6227. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6228. creater := adminInfo.AdminUser.Id
  6229. warehouseOut := models.WarehouseOut{
  6230. WarehouseOutOrderNumber: warehousing_out_order,
  6231. OperationTime: time.Now().Unix(),
  6232. OrgId: adminInfo.Org.Id,
  6233. Creater: creater,
  6234. Ctime: time.Now().Unix(),
  6235. Status: 1,
  6236. WarehouseOutTime: record_time,
  6237. Dealer: 0,
  6238. Manufacturer: 0,
  6239. Type: 1,
  6240. IsSys: 1,
  6241. StorehouseId: houseConfig.StorehouseOutInfo,
  6242. IsCheck: 1,
  6243. }
  6244. err := service.AddSigleWarehouseOut(&warehouseOut)
  6245. if err != nil {
  6246. goodErrcode := models.XtGoodErrcode{
  6247. UserOrgId: adminInfo.Org.Id,
  6248. Errcode: "创建出库单失败",
  6249. GoodId: 0,
  6250. Status: 1,
  6251. Ctime: time.Now().Unix(),
  6252. Mtime: 0,
  6253. Count: 0,
  6254. StockCount: 0,
  6255. Creater: creator,
  6256. BatchNumberId: 0,
  6257. WarehouseOutId: 0,
  6258. }
  6259. service.CreateGoodErrcode(goodErrcode)
  6260. utils.TraceLog("创建出库单失败 err = %v", err)
  6261. } else {
  6262. for _, item := range consumables {
  6263. //出库
  6264. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6265. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6266. if err == nil {
  6267. goodErrcode := models.XtGoodErrcode{
  6268. UserOrgId: adminInfo.Org.Id,
  6269. Errcode: "自动出库接口报错",
  6270. GoodId: 0,
  6271. Status: 1,
  6272. Ctime: time.Now().Unix(),
  6273. Mtime: 0,
  6274. Count: 0,
  6275. StockCount: 0,
  6276. Creater: creator,
  6277. BatchNumberId: 0,
  6278. WarehouseOutId: 0,
  6279. }
  6280. service.CreateGoodErrcode(goodErrcode)
  6281. utils.TraceLog("创建出库单失败 err = %v", err)
  6282. }
  6283. //查询
  6284. //出库数量相加
  6285. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6286. if errs != nil {
  6287. goodErrcode := models.XtGoodErrcode{
  6288. UserOrgId: item.UserOrgId,
  6289. Errcode: "创建剩余库存字段报错",
  6290. GoodId: item.GoodId,
  6291. Status: 1,
  6292. Ctime: time.Now().Unix(),
  6293. Mtime: 0,
  6294. Count: 0,
  6295. StockCount: 0,
  6296. Creater: creater,
  6297. BatchNumberId: 0,
  6298. WarehouseOutId: 0,
  6299. }
  6300. service.CreateGoodErrcode(goodErrcode)
  6301. }
  6302. }
  6303. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6304. if len(list) == 0 {
  6305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6306. return
  6307. }
  6308. for _, item := range list {
  6309. prepare := models.DialysisBeforePrepare{
  6310. UserOrgId: adminInfo.Org.Id,
  6311. PatientId: patient_id,
  6312. RecordDate: record_time,
  6313. GoodId: item.GoodId,
  6314. GoodTypeId: item.GoodTypeId,
  6315. Count: item.Count,
  6316. Creater: adminInfo.AdminUser.Id,
  6317. Status: 1,
  6318. Ctime: time.Now().Unix(),
  6319. StorehouseId: houseConfig.StorehouseOutInfo,
  6320. }
  6321. //清空准备表数据
  6322. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6323. if err != nil {
  6324. goodErrcode := models.XtGoodErrcode{
  6325. UserOrgId: item.OrgId,
  6326. Errcode: "自动出库清空准备表数据报错",
  6327. GoodId: item.GoodId,
  6328. Status: 1,
  6329. Ctime: time.Now().Unix(),
  6330. Mtime: 0,
  6331. Count: 0,
  6332. StockCount: 0,
  6333. Creater: creater,
  6334. BatchNumberId: 0,
  6335. WarehouseOutId: 0,
  6336. }
  6337. service.CreateGoodErrcode(goodErrcode)
  6338. }
  6339. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6340. if errs != nil {
  6341. goodErrcode := models.XtGoodErrcode{
  6342. UserOrgId: item.OrgId,
  6343. Errcode: "自动出库创建准备表数据报错",
  6344. GoodId: item.GoodId,
  6345. Status: 1,
  6346. Ctime: time.Now().Unix(),
  6347. Mtime: 0,
  6348. Count: 0,
  6349. StockCount: 0,
  6350. Creater: creater,
  6351. BatchNumberId: 0,
  6352. WarehouseOutId: 0,
  6353. }
  6354. service.CreateGoodErrcode(goodErrcode)
  6355. }
  6356. //查询默认仓库
  6357. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6358. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6359. var total_count int64
  6360. for _, it := range stockList {
  6361. total_count += it.StockCount
  6362. }
  6363. //基础库插入数据
  6364. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6365. if errcodes != nil {
  6366. goodErrcode := models.XtGoodErrcode{
  6367. UserOrgId: item.OrgId,
  6368. Errcode: "自动出库基础库插入数据",
  6369. GoodId: item.GoodId,
  6370. Status: 1,
  6371. Ctime: time.Now().Unix(),
  6372. Mtime: 0,
  6373. Count: 0,
  6374. StockCount: 0,
  6375. Creater: creater,
  6376. BatchNumberId: 0,
  6377. WarehouseOutId: 0,
  6378. }
  6379. service.CreateGoodErrcode(goodErrcode)
  6380. }
  6381. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6382. var flush_count int64
  6383. for _, it := range goodList {
  6384. flush_count += it.StockCount
  6385. }
  6386. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6387. if errsss != nil {
  6388. goodErrcode := models.XtGoodErrcode{
  6389. UserOrgId: item.OrgId,
  6390. Errcode: "自动出库剩余库存更新数据",
  6391. GoodId: item.GoodId,
  6392. Status: 1,
  6393. Ctime: time.Now().Unix(),
  6394. Mtime: 0,
  6395. Count: 0,
  6396. StockCount: 0,
  6397. Creater: creater,
  6398. BatchNumberId: 0,
  6399. WarehouseOutId: 0,
  6400. }
  6401. service.CreateGoodErrcode(goodErrcode)
  6402. }
  6403. }
  6404. }
  6405. //
  6406. } else if err == nil {
  6407. for _, item := range consumables {
  6408. //出库
  6409. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6410. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6411. if err != nil {
  6412. goodErrcode := models.XtGoodErrcode{
  6413. UserOrgId: adminInfo.Org.Id,
  6414. Errcode: "自动出库接口报错",
  6415. GoodId: 0,
  6416. Status: 1,
  6417. Ctime: time.Now().Unix(),
  6418. Mtime: 0,
  6419. Count: 0,
  6420. StockCount: 0,
  6421. Creater: creator,
  6422. BatchNumberId: 0,
  6423. WarehouseOutId: 0,
  6424. }
  6425. service.CreateGoodErrcode(goodErrcode)
  6426. }
  6427. //出库数量相加
  6428. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6429. if errss != nil {
  6430. goodErrcode := models.XtGoodErrcode{
  6431. UserOrgId: item.UserOrgId,
  6432. Errcode: "创建剩余库存字段报错",
  6433. GoodId: item.GoodId,
  6434. Status: 1,
  6435. Ctime: time.Now().Unix(),
  6436. Mtime: time.Now().Unix(),
  6437. Count: 0,
  6438. StockCount: 0,
  6439. Creater: item.Creater,
  6440. BatchNumberId: 0,
  6441. WarehouseOutId: 0,
  6442. }
  6443. service.CreateGoodErrcode(goodErrcode)
  6444. }
  6445. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6446. if len(list) == 0 {
  6447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6448. return
  6449. }
  6450. for _, item := range list {
  6451. prepare := models.DialysisBeforePrepare{
  6452. UserOrgId: adminInfo.Org.Id,
  6453. PatientId: patient_id,
  6454. RecordDate: record_time,
  6455. GoodId: item.GoodId,
  6456. GoodTypeId: item.GoodTypeId,
  6457. Count: item.Count,
  6458. Creater: adminInfo.AdminUser.Id,
  6459. Status: 1,
  6460. Ctime: time.Now().Unix(),
  6461. StorehouseId: houseConfig.StorehouseOutInfo,
  6462. }
  6463. //清空准备表数据
  6464. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6465. if errs != nil {
  6466. goodErrcode := models.XtGoodErrcode{
  6467. UserOrgId: adminInfo.Org.Id,
  6468. Errcode: "自动出库清空准备表数据报错",
  6469. GoodId: 0,
  6470. Status: 1,
  6471. Ctime: time.Now().Unix(),
  6472. Mtime: 0,
  6473. Count: 0,
  6474. StockCount: 0,
  6475. Creater: creator,
  6476. BatchNumberId: 0,
  6477. WarehouseOutId: 0,
  6478. }
  6479. service.CreateGoodErrcode(goodErrcode)
  6480. }
  6481. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6482. if errcodes != nil {
  6483. goodErrcode := models.XtGoodErrcode{
  6484. UserOrgId: adminInfo.Org.Id,
  6485. Errcode: "自动出库创建准备表数据报错",
  6486. GoodId: 0,
  6487. Status: 1,
  6488. Ctime: time.Now().Unix(),
  6489. Mtime: 0,
  6490. Count: 0,
  6491. StockCount: 0,
  6492. Creater: creator,
  6493. BatchNumberId: 0,
  6494. WarehouseOutId: 0,
  6495. }
  6496. service.CreateGoodErrcode(goodErrcode)
  6497. }
  6498. //查询默认仓库
  6499. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6500. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6501. var total_count int64
  6502. for _, it := range stockList {
  6503. total_count += it.StockCount
  6504. }
  6505. //基础库插入数据
  6506. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6507. if errcodes != nil {
  6508. goodErrcode := models.XtGoodErrcode{
  6509. UserOrgId: adminInfo.Org.Id,
  6510. Errcode: "自动出库基础库插入数据报错",
  6511. GoodId: 0,
  6512. Status: 1,
  6513. Ctime: time.Now().Unix(),
  6514. Mtime: 0,
  6515. Count: 0,
  6516. StockCount: 0,
  6517. Creater: creator,
  6518. BatchNumberId: 0,
  6519. WarehouseOutId: 0,
  6520. }
  6521. service.CreateGoodErrcode(goodErrcode)
  6522. }
  6523. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6524. var flush_count int64
  6525. for _, it := range goodList {
  6526. flush_count += it.StockCount
  6527. }
  6528. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6529. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6530. if errss != nil {
  6531. goodErrcode := models.XtGoodErrcode{
  6532. UserOrgId: item.OrgId,
  6533. Errcode: "自动出库剩余库存更新数据",
  6534. GoodId: item.GoodId,
  6535. Status: 1,
  6536. Ctime: time.Now().Unix(),
  6537. Mtime: 0,
  6538. Count: 0,
  6539. StockCount: 0,
  6540. Creater: creater,
  6541. BatchNumberId: 0,
  6542. WarehouseOutId: 0,
  6543. }
  6544. service.CreateGoodErrcode(goodErrcode)
  6545. }
  6546. }
  6547. }
  6548. }
  6549. c.ServeSuccessJSON(map[string]interface{}{
  6550. "msg": "提交成功",
  6551. "message": "2",
  6552. "good_name": "",
  6553. "specification_name": "",
  6554. })
  6555. return
  6556. } else {
  6557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6558. return
  6559. }
  6560. }
  6561. func (c *DialysisAPIController) EditConsumables() {
  6562. patient_id, _ := c.GetInt64("patient_id", 0)
  6563. record_date := c.GetString("record_time")
  6564. if patient_id <= 0 {
  6565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6566. return
  6567. }
  6568. adminInfo := c.GetMobileAdminUserInfo()
  6569. timeLayout := "2006-01-02"
  6570. loc, _ := time.LoadLocation("Local")
  6571. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6572. record_time := theRecordTime.Unix()
  6573. // 查询信息规挡的设置天数
  6574. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6575. if infor.ID > 0 && infor.WeekDay > 0 {
  6576. var cha_time int64
  6577. timeNowStr := time.Now().Format("2006-01-02")
  6578. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6579. //今日的日期减去设置的日期
  6580. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6581. if cha_time >= record_time {
  6582. //查询审核是否允许
  6583. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6584. //申请状态不允许的情况 拒绝修改
  6585. if infor.ApplicationStatus != 1 {
  6586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6587. return
  6588. }
  6589. }
  6590. }
  6591. dataBody := make(map[string]interface{}, 0)
  6592. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6593. if err != nil {
  6594. utils.ErrorLog(err.Error())
  6595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6596. return
  6597. }
  6598. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6599. var beforePrepares []*models.DialysisBeforePrepareGoods
  6600. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6601. var cancelbefor []*models.DialysisBeforePrepareGoods
  6602. var outbefor []*models.DialysisBeforePrepareGoods
  6603. //判断是否开启自动出库
  6604. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6605. if record.IsOpen == 1 {
  6606. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6607. goods, _ := dataBody["goods"].([]interface{})
  6608. if len(goods) > 0 {
  6609. for _, item := range goods {
  6610. items := item.(map[string]interface{})
  6611. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6612. utils.ErrorLog("good_id")
  6613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6614. return
  6615. }
  6616. good_id := int64(items["good_id"].(float64))
  6617. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6618. utils.ErrorLog("good_type_id")
  6619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6620. return
  6621. }
  6622. good_type_id := int64(items["good_type_id"].(float64))
  6623. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6624. utils.ErrorLog("count")
  6625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6626. return
  6627. }
  6628. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6629. commdity_code := items["commdity_code"].(string)
  6630. fmt.Println(commdity_code)
  6631. prepareGoods := &models.DialysisBeforePrepareGoods{
  6632. GoodTypeId: good_type_id,
  6633. GoodId: good_id,
  6634. Count: count,
  6635. StorehouseId: houseConfig.StorehouseOutInfo,
  6636. }
  6637. beforePrepares = append(beforePrepares, prepareGoods)
  6638. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6639. GoodTypeId: good_type_id,
  6640. GoodId: good_id,
  6641. Count: count,
  6642. StorehouseId: houseConfig.StorehouseOutInfo,
  6643. }
  6644. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6645. }
  6646. for _, item := range beforePrepares {
  6647. //1.查看该患者该耗材型号最后一次出库数量
  6648. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6649. //判断当前出库数量和最后一次出库数量的大小
  6650. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6651. if item.Count < goodInfo.Count {
  6652. cancelbefor = append(cancelbefor, item)
  6653. }
  6654. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6655. if item.Count > goodInfo.Count {
  6656. outbefor = append(outbefor, item)
  6657. }
  6658. //处理编辑耗材新增不了的问题
  6659. if goodInfo.Count == item.Count {
  6660. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6661. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6662. }
  6663. }
  6664. if len(cancelbefor) > 0 {
  6665. //退库
  6666. for _, item := range cancelbefor {
  6667. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6668. creater := adminInfo.AdminUser.Id
  6669. //查询该患者当天已经出库的耗材信息
  6670. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6671. var delete_count int64 = 0
  6672. delete_count = warehouseOutInfos.Count - item.Count
  6673. //增加库存数量
  6674. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6675. //减少实际出库库存数量
  6676. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6677. // 删除出库完成后,要增加对应批次的库存数量
  6678. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6679. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6680. //更新剩余库存
  6681. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6682. var flush_count int64
  6683. for _, it := range goodListOne {
  6684. flush_count += it.StockCount
  6685. }
  6686. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6687. //查询剩余库存
  6688. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6689. var sum_count int64
  6690. for _, item := range goodList {
  6691. sum_count += item.StockCount
  6692. }
  6693. // 在出库记录表里记录退库详情
  6694. warehouseOutInfo := &models.WarehouseOutInfo{
  6695. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6696. WarehouseOutId: warehouseOut.ID,
  6697. Status: 1,
  6698. Ctime: time.Now().Unix(),
  6699. OrgId: adminInfo.Org.Id,
  6700. Type: 1,
  6701. IsSys: 1,
  6702. SysRecordTime: record_time,
  6703. GoodTypeId: item.GoodTypeId,
  6704. GoodId: item.GoodId,
  6705. PatientId: patient_id,
  6706. ConsumableType: 2,
  6707. StorehouseId: houseConfig.StorehouseOutInfo,
  6708. IsCheck: 1,
  6709. OverCount: sum_count,
  6710. }
  6711. warehouseOutInfo.Count = item.Count
  6712. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6713. warehouseOutInfo.Price = stockInInfo.Price
  6714. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6715. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6716. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6717. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6718. warehouseOutInfo.Number = warehouseOutInfos.Number
  6719. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6720. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6721. //查找当天是否存在出库记录
  6722. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6723. if errcod == gorm.ErrRecordNotFound {
  6724. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6725. //插入详情明细表
  6726. stockFlow := models.VmStockFlow{
  6727. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6728. WarehouseOutId: warehouseOut.ID,
  6729. GoodId: item.GoodId,
  6730. Number: warehouseOutInfos.Number,
  6731. ProductDate: stockInInfo.ProductDate,
  6732. ExpireDate: stockInInfo.ExpiryDate,
  6733. Count: item.Count,
  6734. Price: stockInInfo.Price,
  6735. Status: 1,
  6736. Ctime: record_time,
  6737. UserOrgId: adminInfo.Org.Id,
  6738. Manufacturer: stockInInfo.Manufacturer,
  6739. Dealer: stockInInfo.Dealer,
  6740. LicenseNumber: stockInInfo.LicenseNumber,
  6741. IsEdit: 2,
  6742. Creator: creater,
  6743. SystemTime: record_time,
  6744. ConsumableType: 3,
  6745. WarehousingDetailId: 0,
  6746. IsSys: 1,
  6747. UpdateCreator: creater,
  6748. PatientId: patient_id,
  6749. StorehouseId: houseConfig.StorehouseOutInfo,
  6750. }
  6751. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6752. if errflow == gorm.ErrRecordNotFound {
  6753. //创建流水表
  6754. err := service.CreateStockFlowOne(stockFlow)
  6755. fmt.Println("err", err)
  6756. } else if errflow == nil {
  6757. //插入详情明细表
  6758. stockFlow := models.VmStockFlow{
  6759. ID: exsit.ID,
  6760. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6761. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6762. WarehouseOutId: warehouseOut.ID,
  6763. GoodId: item.GoodId,
  6764. Number: warehouseOutInfos.Number,
  6765. ProductDate: stockInInfo.ProductDate,
  6766. ExpireDate: stockInInfo.ExpiryDate,
  6767. Count: exsit.Count - delete_count,
  6768. Price: stockInInfo.Price,
  6769. Status: 1,
  6770. Ctime: record_time,
  6771. UserOrgId: adminInfo.Org.Id,
  6772. Manufacturer: stockInInfo.Manufacturer,
  6773. Dealer: stockInInfo.Dealer,
  6774. LicenseNumber: stockInInfo.LicenseNumber,
  6775. IsEdit: 2,
  6776. Creator: creater,
  6777. SystemTime: record_time,
  6778. ConsumableType: 3,
  6779. WarehousingDetailId: 0,
  6780. IsSys: 1,
  6781. UpdateCreator: creater,
  6782. PatientId: patient_id,
  6783. StorehouseId: houseConfig.StorehouseOutInfo,
  6784. }
  6785. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6786. }
  6787. } else if errcod == nil {
  6788. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6789. //查询剩余库存
  6790. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6791. var sum_count int64
  6792. for _, item := range goodList {
  6793. sum_count += item.StockCount
  6794. }
  6795. //创建退库单,生成退库数据
  6796. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6797. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6798. operation_time := time.Now().Unix()
  6799. creater := adminInfo.AdminUser.Id
  6800. //创建退库单
  6801. timeStr := time.Now().Format("2006-01-02")
  6802. timeArr := strings.Split(timeStr, "-")
  6803. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6804. total = total + 1
  6805. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6806. cancelStock := models.CancelStock{
  6807. OrderNumber: orderNumber,
  6808. OperaTime: operation_time,
  6809. OrgId: adminInfo.Org.Id,
  6810. Creater: creater,
  6811. Ctime: time.Now().Unix(),
  6812. Status: 1,
  6813. ReturnTime: record_time,
  6814. Type: 1,
  6815. StorehouseId: houseConfig.StorehouseOutInfo,
  6816. IsCheck: 1,
  6817. }
  6818. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6819. if msgerrkonde == gorm.ErrRecordNotFound {
  6820. service.AddSigleCancelStock(&cancelStock)
  6821. }
  6822. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6823. //查询是否有出库
  6824. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6825. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6826. deaerler, _ := service.GetDealerById(info.Dealer)
  6827. if info.ID > 0 {
  6828. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6829. cancelStockInfo := models.CancelStockInfo{
  6830. GoodId: item.GoodId,
  6831. CancelStockId: cancel.ID,
  6832. GoodTypeId: good.GoodTypeId,
  6833. Count: delete_count,
  6834. Price: info.Price,
  6835. Total: 0,
  6836. ProductDate: info.ProductDate,
  6837. ExpiryDate: info.ExpiryDate,
  6838. Ctime: time.Now().Unix(),
  6839. Status: 1,
  6840. OrgId: adminInfo.Org.Id,
  6841. OrderNumber: cancel.OrderNumber,
  6842. Type: 0,
  6843. Dealer: deaerler.DealerName,
  6844. Manufacturer: manufacturer.ManufacturerName,
  6845. Number: info.Number,
  6846. RegisterAccount: "",
  6847. Remark: "",
  6848. WarehouseInfoId: info.WarehouseInfotId,
  6849. PatientId: info.PatientId,
  6850. RecordDate: info.SysRecordTime,
  6851. StorehouseId: houseConfig.StorehouseOutInfo,
  6852. IsCheck: 1,
  6853. }
  6854. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6855. //退库数量增加
  6856. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6857. //查询剩余库存
  6858. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6859. var over_count int64
  6860. for _, it := range goodList {
  6861. over_count += it.StockCount
  6862. }
  6863. flow := models.VmStockFlow{
  6864. WarehousingId: info.WarehouseInfotId,
  6865. GoodId: item.GoodId,
  6866. Number: info.Number,
  6867. LicenseNumber: info.LicenseNumber,
  6868. Count: delete_count,
  6869. UserOrgId: adminInfo.Org.Id,
  6870. PatientId: patient_id,
  6871. SystemTime: info.SysRecordTime,
  6872. ConsumableType: 7,
  6873. IsSys: 0,
  6874. WarehousingOrder: "",
  6875. WarehouseOutId: info.WarehouseOutId,
  6876. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6877. IsEdit: 0,
  6878. CancelStockId: cancel.ID,
  6879. CancelOrderNumber: cancel.OrderNumber,
  6880. Manufacturer: manufacturer.ID,
  6881. Dealer: 0,
  6882. Creator: adminInfo.AdminUser.Id,
  6883. UpdateCreator: 0,
  6884. Status: 1,
  6885. Ctime: record_time,
  6886. Mtime: 0,
  6887. Price: info.Price,
  6888. WarehousingDetailId: info.WarehouseInfotId,
  6889. WarehouseOutDetailId: info.ID,
  6890. CancelOutDetailId: cancelInfo.ID,
  6891. ProductDate: info.ProductDate,
  6892. ExpireDate: info.ExpiryDate,
  6893. StorehouseId: houseConfig.StorehouseOutInfo,
  6894. OverCount: over_count,
  6895. }
  6896. service.CreateStockFlowOne(flow)
  6897. }
  6898. }
  6899. //更改自动出库的表格
  6900. details := models.BloodAutomaticReduceDetail{
  6901. WarehouseOutId: warehouseOutInfo.ID,
  6902. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6903. PatientId: patient_id,
  6904. Ctime: time.Now().Unix(),
  6905. Mtime: time.Now().Unix(),
  6906. Status: 1,
  6907. RecordTime: record_time,
  6908. OrgId: adminInfo.Org.Id,
  6909. GoodId: item.GoodId,
  6910. GoodTypeId: item.GoodTypeId,
  6911. Count: item.Count,
  6912. StorehouseId: houseConfig.StorehouseOutInfo,
  6913. }
  6914. //查询当天耗材是否已经存在数据
  6915. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6916. if errcode == gorm.ErrRecordNotFound {
  6917. service.CreateAutoReduceRecord(&details)
  6918. } else if errcode == nil {
  6919. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6920. service.CreateAutoReduceRecord(&details)
  6921. }
  6922. //查询默认仓库
  6923. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6924. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6925. var total_count int64
  6926. for _, it := range stockList {
  6927. total_count += it.StockCount
  6928. }
  6929. //基础库插入数据
  6930. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6931. }
  6932. }
  6933. if len(outbefor) > 0 {
  6934. //出库
  6935. for _, item := range outbefor {
  6936. var last_total int64
  6937. //1.查看该患者该耗材型号最后一次出库数量
  6938. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6939. //计算当前出库和最后一次出库数据相差数据
  6940. last_total = item.Count - goodInfoOne.Count
  6941. //查询该耗材的总库存
  6942. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6943. // 如果库存差大于剩余库存则提示库存不足
  6944. if last_total > wareinfo.StockCount {
  6945. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6946. c.ServeSuccessJSON(map[string]interface{}{
  6947. "message": "1",
  6948. "good_name": goodObj.GoodName,
  6949. "specification_name": goodObj.SpecificationName,
  6950. })
  6951. return
  6952. } else {
  6953. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6954. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6955. if err == gorm.ErrRecordNotFound {
  6956. //没有记录,则创建出库单
  6957. timeStr := time.Now().Format("2006-01-02")
  6958. timeArr := strings.Split(timeStr, "-")
  6959. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6960. total = total + 1
  6961. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6962. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6963. number = number + total
  6964. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6965. warehouseOut := models.WarehouseOut{
  6966. WarehouseOutOrderNumber: warehousing_out_order,
  6967. OperationTime: time.Now().Unix(),
  6968. OrgId: adminInfo.Org.Id,
  6969. Creater: adminInfo.AdminUser.Id,
  6970. Ctime: time.Now().Unix(),
  6971. Status: 1,
  6972. WarehouseOutTime: record_time,
  6973. Dealer: 0,
  6974. Manufacturer: 0,
  6975. Type: 1,
  6976. IsSys: 1,
  6977. StorehouseId: houseConfig.StorehouseOutInfo,
  6978. IsCheck: 1,
  6979. }
  6980. service.AddSigleWarehouseOut(&warehouseOut)
  6981. }
  6982. //出库
  6983. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6984. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6985. //1.查看该患者该耗材型号最后一次出库数量
  6986. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6987. prepare := models.DialysisBeforePrepare{
  6988. UserOrgId: adminInfo.Org.Id,
  6989. PatientId: patient_id,
  6990. RecordDate: record_time,
  6991. GoodId: item.GoodId,
  6992. GoodTypeId: item.GoodTypeId,
  6993. Count: item.Count - goodInfoTwo.Count,
  6994. Ctime: time.Now().Unix(),
  6995. Mtime: 0,
  6996. Creater: adminInfo.AdminUser.Id,
  6997. Modifier: adminInfo.AdminUser.Id,
  6998. Status: 1,
  6999. CommdityCode: "",
  7000. NewCount: 0,
  7001. ProjectId: 0,
  7002. StorehouseId: houseConfig.StorehouseOutInfo,
  7003. }
  7004. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7005. //增加出库数量
  7006. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7007. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7008. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7009. var total_count int64
  7010. for _, it := range stockList {
  7011. total_count += it.StockCount
  7012. }
  7013. //基础库插入数据
  7014. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7015. //剩余库存
  7016. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7017. var flush_count int64
  7018. for _, it := range goodList {
  7019. flush_count += it.StockCount
  7020. }
  7021. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7022. }
  7023. }
  7024. }
  7025. //查询今日出库数据
  7026. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7027. for _, it := range list {
  7028. prepare := models.DialysisBeforePrepare{
  7029. UserOrgId: it.OrgId,
  7030. PatientId: patient_id,
  7031. RecordDate: it.RecordTime,
  7032. GoodId: it.GoodId,
  7033. GoodTypeId: it.GoodTypeId,
  7034. Count: it.Count,
  7035. Ctime: time.Now().Unix(),
  7036. Creater: adminInfo.AdminUser.Id,
  7037. Status: 1,
  7038. StorehouseId: houseConfig.StorehouseOutInfo,
  7039. ProjectId: it.ProjectId,
  7040. }
  7041. //删除准备表数据
  7042. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7043. service.CreateDialysisBeforePrepareOne(&prepare)
  7044. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7045. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7046. var total_count int64
  7047. for _, it := range stockList {
  7048. total_count += it.StockCount
  7049. }
  7050. //基础库插入数据
  7051. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7052. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7053. var flush_count int64
  7054. for _, it := range goodList {
  7055. flush_count += it.StockCount
  7056. }
  7057. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7058. }
  7059. }
  7060. }
  7061. //更新自动出库的地方
  7062. var errs error
  7063. if errs == nil {
  7064. c.ServeSuccessJSON(map[string]interface{}{
  7065. "msg": "修改成功",
  7066. "message": "2",
  7067. "good_name": "",
  7068. "specification_name": "",
  7069. })
  7070. return
  7071. } else {
  7072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7073. return
  7074. }
  7075. }
  7076. }
  7077. func (c *DialysisAPIController) GetDialysisGoods() {
  7078. schedualDate := c.GetString("schedule_date")
  7079. schedule_type, _ := c.GetInt64("schedule_type")
  7080. partition_id, _ := c.GetInt64("partition_id")
  7081. page, _ := c.GetInt("page")
  7082. patient_id, _ := c.GetInt64("patient_id")
  7083. schedualEndDate := int64(0)
  7084. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7085. if parseDateErr != nil && len(schedualDate) != 0 {
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7087. return
  7088. }
  7089. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7090. if parseDateErr != nil && len(schedualDate) != 0 {
  7091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7092. return
  7093. }
  7094. schedualEndDate = endDate.Unix()
  7095. adminUser := c.GetMobileAdminUserInfo()
  7096. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7097. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7098. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7099. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7100. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7101. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7102. //获取当天该病人的透析处方
  7103. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7104. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7105. if err == gorm.ErrRecordNotFound {
  7106. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7107. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7108. if patient_id != 0 {
  7109. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7110. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7111. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7112. //获取患者总的出库数据
  7113. item.LastAutomaticReduceDetail = goodUser
  7114. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7115. item.Project = project
  7116. for _, it := range item.AutomaticReduceDetail {
  7117. var total int64
  7118. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7119. for _, its := range auto {
  7120. total += its.Count
  7121. }
  7122. it.Count = total
  7123. }
  7124. }
  7125. }
  7126. c.ServeSuccessJSON(map[string]interface{}{
  7127. "dialysis_goods": dialysisGoods,
  7128. "good_type": goodTypes,
  7129. "total": total,
  7130. "prescribe": prescribe,
  7131. "good_info": good_info,
  7132. "warehouseOutList": warehouseOutList,
  7133. "config": config,
  7134. "outConfig": outConfig,
  7135. "settleConfig": settleConfig,
  7136. })
  7137. return
  7138. } else if err == nil {
  7139. //获取当天排班的每个患者的库存使用情况
  7140. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7141. //获取患者总的出库数据
  7142. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7143. if patient_id != 0 {
  7144. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7145. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7146. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7147. item.Project = project
  7148. item.LastAutomaticReduceDetail = goodUser
  7149. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7150. for _, it := range item.AutomaticReduceDetail {
  7151. var total int64
  7152. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7153. for _, its := range auto {
  7154. total += its.Count
  7155. }
  7156. it.Count = total
  7157. }
  7158. }
  7159. }
  7160. if err == nil {
  7161. c.ServeSuccessJSON(map[string]interface{}{
  7162. "dialysis_goods": dialysisGoods,
  7163. "good_type": goodTypes,
  7164. "total": total,
  7165. "prescribe": prescribe,
  7166. "good_info": good_info,
  7167. "project": project,
  7168. "warehouseOutList": warehouseOutList,
  7169. "config": config,
  7170. "outConfig": outConfig,
  7171. "settleConfig": settleConfig,
  7172. })
  7173. return
  7174. } else {
  7175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7176. return
  7177. }
  7178. } else if err != nil {
  7179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7180. return
  7181. }
  7182. }
  7183. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7184. start_time := c.GetString("start_time")
  7185. end_time := c.GetString("end_time")
  7186. timeLayout := "2006-01-02"
  7187. loc, _ := time.LoadLocation("Local")
  7188. var theStartTime int64
  7189. if len(start_time) > 0 {
  7190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7191. if err != nil {
  7192. utils.ErrorLog(err.Error())
  7193. }
  7194. theStartTime = theTime.Unix()
  7195. }
  7196. var theEndtTime int64
  7197. if len(end_time) > 0 {
  7198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7199. if err != nil {
  7200. utils.ErrorLog(err.Error())
  7201. }
  7202. theEndtTime = theTime.Unix()
  7203. }
  7204. adminUser := c.GetMobileAdminUserInfo()
  7205. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7206. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7207. if err == nil {
  7208. c.ServeSuccessJSON(map[string]interface{}{
  7209. "stock_out": outInfo,
  7210. "stockCount": stockCount,
  7211. })
  7212. return
  7213. } else {
  7214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7215. return
  7216. }
  7217. }
  7218. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7219. patient_id, _ := c.GetInt64("patient_id", 0)
  7220. record_time := c.GetString("record_time")
  7221. adminUser := c.GetMobileAdminUserInfo()
  7222. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7223. if parseDateErr != nil && len(record_time) != 0 {
  7224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7225. return
  7226. }
  7227. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7228. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7229. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7230. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7231. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7232. //获取今日患者的透析处方参数
  7233. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7234. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7235. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7236. c.ServeSuccessJSON(map[string]interface{}{
  7237. "good_type": goodTypes,
  7238. "good_user": goodUser,
  7239. "good_info": good_info,
  7240. "last_good_user": lastGoodUserDetial,
  7241. "project": project,
  7242. "prescription": prescribe,
  7243. "outInfo": outInfo,
  7244. "configs": configs,
  7245. })
  7246. return
  7247. }
  7248. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7249. patient_id, _ := c.GetInt64("patient_id", 0)
  7250. record_date := c.GetString("record_time")
  7251. timeLayout := "2006-01-02"
  7252. loc, _ := time.LoadLocation("Local")
  7253. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7254. record_time := theRecordTime.Unix()
  7255. adminInfo := c.GetMobileAdminUserInfo()
  7256. dataBody := make(map[string]interface{}, 0)
  7257. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7258. if err != nil {
  7259. utils.ErrorLog(err.Error())
  7260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7261. return
  7262. }
  7263. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7264. var beforePrepares []*models.DialysisBeforePrepareGoods
  7265. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7266. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7267. goods, _ := dataBody["goods"].([]interface{})
  7268. if len(goods) > 0 {
  7269. for _, item := range goods {
  7270. items := item.(map[string]interface{})
  7271. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7272. utils.ErrorLog("good_id")
  7273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7274. return
  7275. }
  7276. good_id := int64(items["good_id"].(float64))
  7277. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7278. utils.ErrorLog("good_type_id")
  7279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7280. return
  7281. }
  7282. good_type_id := int64(items["good_type_id"].(float64))
  7283. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7284. utils.ErrorLog("count")
  7285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7286. return
  7287. }
  7288. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7289. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7290. utils.ErrorLog("project_id")
  7291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7292. return
  7293. }
  7294. project_id := int64(items["project_id"].(float64))
  7295. new_count := int64(items["new_count"].(float64))
  7296. old_count := int64(items["old_count"].(float64))
  7297. prepare := &models.DialysisBeforePrepareGoods{
  7298. GoodId: good_id,
  7299. GoodTypeId: good_type_id,
  7300. Count: count,
  7301. ProjectId: project_id,
  7302. StorehouseId: houseConfig.StorehouseOutInfo,
  7303. NewCount: new_count,
  7304. OldCount: old_count,
  7305. }
  7306. beforePrepares = append(beforePrepares, prepare)
  7307. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7308. GoodId: good_id,
  7309. GoodTypeId: good_type_id,
  7310. Count: count,
  7311. ProjectId: project_id,
  7312. StorehouseId: houseConfig.StorehouseOutInfo,
  7313. NewCount: new_count,
  7314. OldCount: old_count,
  7315. }
  7316. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7317. }
  7318. }
  7319. }
  7320. //查询是否有库存
  7321. for _, item := range beforePrepares {
  7322. if item.NewCount > 0 {
  7323. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7324. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7325. if item.Count > warehouse.Count {
  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. }
  7334. }
  7335. }
  7336. // 查询信息规挡的设置天数
  7337. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7338. if infor.ID > 0 && infor.WeekDay > 0 {
  7339. var cha_time int64
  7340. timeNowStr := time.Now().Format("2006-01-02")
  7341. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7342. //今日的日期减去设置的日期
  7343. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7344. if cha_time >= record_time {
  7345. //查询审核是否允许
  7346. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7347. //申请状态不允许的情况 拒绝修改
  7348. if infor.ApplicationStatus != 1 {
  7349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7350. return
  7351. }
  7352. }
  7353. }
  7354. //出库逻辑
  7355. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7356. if err != nil {
  7357. utils.ErrorLog(err.Error())
  7358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7359. return
  7360. }
  7361. finish := models.XtDialysisFinish{
  7362. IsFinish: 1,
  7363. UserOrgId: adminInfo.Org.Id,
  7364. Status: 1,
  7365. Ctime: time.Now().Unix(),
  7366. Mtime: 0,
  7367. Module: 11,
  7368. RecordDate: record_time,
  7369. Sourse: 1,
  7370. PatientId: patient_id,
  7371. }
  7372. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7373. if dialysisFinish.ID == 0 {
  7374. service.CreateDialysisFinish(finish)
  7375. }
  7376. //查询当天出库的数据
  7377. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7378. for _, item := range list {
  7379. prepare := models.DialysisBeforePrepare{
  7380. UserOrgId: item.OrgId,
  7381. PatientId: item.PatientId,
  7382. RecordDate: item.RecordTime,
  7383. GoodId: item.GoodId,
  7384. GoodTypeId: item.GoodTypeId,
  7385. Count: item.Count,
  7386. Creater: adminInfo.AdminUser.Id,
  7387. Status: 1,
  7388. Ctime: time.Now().Unix(),
  7389. ProjectId: item.ProjectId,
  7390. StorehouseId: houseConfig.StorehouseOutInfo,
  7391. }
  7392. //清空准备表的数据
  7393. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7394. //插入准备表数据
  7395. service.CreateDialysisBeforePrepareOne(&prepare)
  7396. //查询默认仓库
  7397. //查询默认仓库
  7398. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7399. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7400. var total_count int64
  7401. for _, it := range stockList {
  7402. total_count += it.StockCount
  7403. }
  7404. //基础库插入数据
  7405. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7406. ////更新剩余库存
  7407. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7408. var flush_count int64
  7409. for _, it := range goodList {
  7410. flush_count += it.StockCount
  7411. }
  7412. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7413. if errs != nil {
  7414. goodErrcode := models.XtGoodErrcode{
  7415. UserOrgId: item.OrgId,
  7416. Errcode: "手动出库更新剩余出库失败",
  7417. GoodId: item.GoodId,
  7418. Status: 1,
  7419. Ctime: time.Now().Unix(),
  7420. Mtime: 0,
  7421. Count: 0,
  7422. StockCount: 0,
  7423. Creater: adminInfo.AdminUser.Id,
  7424. BatchNumberId: 0,
  7425. WarehouseOutId: 0,
  7426. }
  7427. service.CreateGoodErrcode(goodErrcode)
  7428. }
  7429. }
  7430. //更新自动出库的地方
  7431. var errs error
  7432. if errs == nil {
  7433. c.ServeSuccessJSON(map[string]interface{}{
  7434. "msg": "修改成功",
  7435. "message": "2",
  7436. "good_name": "",
  7437. "specification_name": "",
  7438. })
  7439. return
  7440. } else {
  7441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7442. return
  7443. }
  7444. }
  7445. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7446. newArr = make([]*models.DialysisBeforePrepare, 0)
  7447. for i := 0; i < len(arr); i++ {
  7448. repeat := false
  7449. for j := i + 1; j < len(arr); j++ {
  7450. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7451. repeat = true
  7452. break
  7453. }
  7454. }
  7455. if !repeat {
  7456. newArr = append(newArr, arr[i])
  7457. }
  7458. }
  7459. return
  7460. }
  7461. func (c *DialysisAPIController) GetAllDrug() {
  7462. patient_id, _ := c.GetInt64("patient_id", 0)
  7463. adminInfo := c.GetMobileAdminUserInfo()
  7464. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7465. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7466. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7467. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7468. c.ServeSuccessJSON(map[string]interface{}{
  7469. "base_drug_config": drugStockConfig,
  7470. "private_drug_config": privateDrugConfig,
  7471. "base_drug_list": drugList,
  7472. "private_drug_list": privateDrugList,
  7473. })
  7474. }
  7475. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7476. newArr = make([]*models.DialysisBeforePrepare, 0)
  7477. for i := 0; i < len(arr); i++ {
  7478. repeat := false
  7479. for j := i + 1; j < len(arr); j++ {
  7480. if arr[i].GoodId == arr[j].GoodId {
  7481. repeat = true
  7482. break
  7483. }
  7484. }
  7485. if !repeat {
  7486. newArr = append(newArr, arr[i])
  7487. }
  7488. }
  7489. return
  7490. }
  7491. func (c *DialysisAPIController) GetDepartment() {
  7492. adminInfo := c.GetMobileAdminUserInfo()
  7493. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7494. if err == nil {
  7495. c.ServeSuccessJSON(map[string]interface{}{
  7496. "departments": departments,
  7497. })
  7498. } else {
  7499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7500. return
  7501. }
  7502. }
  7503. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7504. types, _ := c.GetInt("type", 0)
  7505. start_time := c.GetString("start_time")
  7506. end_time := c.GetString("end_time")
  7507. orgId := c.GetMobileAdminUserInfo().Org.Id
  7508. timeLayout := "2006-01-02"
  7509. loc, _ := time.LoadLocation("Local")
  7510. var startTime int64
  7511. if len(start_time) > 0 {
  7512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7513. if err != nil {
  7514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7515. return
  7516. }
  7517. startTime = theTime.Unix()
  7518. }
  7519. var endTime int64
  7520. if len(end_time) > 0 {
  7521. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7522. if err != nil {
  7523. utils.ErrorLog(err.Error())
  7524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7525. return
  7526. }
  7527. endTime = theTime.Unix()
  7528. }
  7529. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7530. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7531. if err != nil {
  7532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7533. } else {
  7534. c.ServeSuccessJSON(map[string]interface{}{
  7535. "list": list,
  7536. "type": types,
  7537. "stockTotal": stockTotal,
  7538. })
  7539. }
  7540. }
  7541. func (c *DialysisAPIController) GetPrescriptionList() {
  7542. start_time := c.GetString("start_time")
  7543. end_time := c.GetString("end_time")
  7544. schedule_type, _ := c.GetInt64("schedule_type")
  7545. partion_id, _ := c.GetInt64("partion_id")
  7546. orgId := c.GetMobileAdminUserInfo().Org.Id
  7547. timeLayout := "2006-01-02"
  7548. loc, _ := time.LoadLocation("Local")
  7549. var startTime int64
  7550. if len(start_time) > 0 {
  7551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7552. if err != nil {
  7553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7554. return
  7555. }
  7556. startTime = theTime.Unix()
  7557. }
  7558. var endTime int64
  7559. if len(end_time) > 0 {
  7560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7561. if err != nil {
  7562. utils.ErrorLog(err.Error())
  7563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7564. return
  7565. }
  7566. endTime = theTime.Unix()
  7567. }
  7568. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7569. fmt.Println("schedulelist22222222", schedulelist)
  7570. c.ServeSuccessJSON(map[string]interface{}{
  7571. "list": schedulelist,
  7572. })
  7573. return
  7574. }
  7575. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7576. ids := c.GetString("ids")
  7577. //patient_id, _ := c.GetInt64("patient_id")
  7578. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7579. idArray := strings.Split(ids, ",")
  7580. err := service.BatchDeleteMonitor(idArray)
  7581. fmt.Print("err", err)
  7582. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7583. //redis := service.RedisClient()
  7584. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7585. //redis.Set(key, "", time.Second)
  7586. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7587. //redis.Set(keyOne, "", time.Second)
  7588. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7589. //redis.Close()
  7590. c.ServeSuccessJSON(map[string]interface{}{
  7591. "msg": "批量删除成功",
  7592. })
  7593. return
  7594. }
  7595. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7596. id, _ := c.GetInt64("id")
  7597. timeLayout := "2006-01-02"
  7598. loc, _ := time.LoadLocation("Local")
  7599. //start_time := time.Now().Format("2006-01-02")
  7600. start_time := c.GetString("start_time")
  7601. end_time := c.GetString("end_time")
  7602. var startdateunix int64
  7603. if len(start_time) > 0 {
  7604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7605. if err != nil {
  7606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7607. return
  7608. }
  7609. startdateunix = theTime.Unix()
  7610. }
  7611. var enddateunix int64
  7612. if len(end_time) > 0 {
  7613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7614. if err != nil {
  7615. utils.ErrorLog(err.Error())
  7616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7617. return
  7618. }
  7619. enddateunix = theTime.Unix()
  7620. }
  7621. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7622. //nowTime := time.Now()
  7623. //endTime := nowTime.AddDate(-30, 0, 0)
  7624. //endTimes := endTime.Format("2006-01-02")
  7625. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7626. org_id := c.GetMobileAdminUserInfo().Org.Id
  7627. //if org_id == 10579 {
  7628. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7629. // c.ServeSuccessJSON(map[string]interface{}{
  7630. // "list": list,
  7631. // })
  7632. // return
  7633. //} else {
  7634. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7635. // c.ServeSuccessJSON(map[string]interface{}{
  7636. // "list": list,
  7637. // })
  7638. // return
  7639. //}
  7640. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7641. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7642. c.ServeSuccessJSON(map[string]interface{}{
  7643. "list": list,
  7644. })
  7645. return
  7646. } else {
  7647. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7648. c.ServeSuccessJSON(map[string]interface{}{
  7649. "list": list,
  7650. })
  7651. }
  7652. return
  7653. }
  7654. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7655. dataBody := make(map[string]interface{}, 0)
  7656. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7657. ids := c.GetString("ids")
  7658. idArray := strings.Split(ids, ",")
  7659. origin, _ := c.GetInt64("origin")
  7660. if origin == 1 {
  7661. err = service.BatchDeleteAdvice(idArray)
  7662. fmt.Print("err", err)
  7663. c.ServeSuccessJSON(map[string]interface{}{
  7664. "msg": "批量删除成功",
  7665. })
  7666. return
  7667. }
  7668. if origin == 2 {
  7669. service.BatchDeleteHisAdvice(idArray)
  7670. }
  7671. }
  7672. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7673. good_id, _ := c.GetInt64("good_id")
  7674. count, _ := c.GetInt64("count")
  7675. record_time, _ := c.GetInt64("record_time")
  7676. patient_id, _ := c.GetInt64("patient_id")
  7677. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7678. c.ServeSuccessJSON(map[string]interface{}{
  7679. "detail": detail,
  7680. })
  7681. return
  7682. }
  7683. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7684. good_id, _ := c.GetInt64("good_id")
  7685. record_time, _ := c.GetInt64("record_time")
  7686. patient_id, _ := c.GetInt64("patient_id")
  7687. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7688. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7689. fmt.Print("err", err)
  7690. c.ServeSuccessJSON(map[string]interface{}{
  7691. "msg": "批量删除成功",
  7692. })
  7693. return
  7694. }
  7695. func (c *DialysisAPIController) BatchAdviceCheck() {
  7696. ids := c.GetString("ids")
  7697. idArray := strings.Split(ids, ",")
  7698. creator, _ := c.GetInt64("creator")
  7699. origin, _ := c.GetInt64("origin")
  7700. if origin == 1 {
  7701. err := service.BatchAdviceCheck(idArray, creator)
  7702. fmt.Println(err)
  7703. list, _ := service.GetAdviceExecutionById(idArray)
  7704. c.ServeSuccessJSON(map[string]interface{}{
  7705. "list": list,
  7706. })
  7707. return
  7708. }
  7709. if origin == 2 {
  7710. service.BatchHisAdviceCheck(idArray, creator)
  7711. list, _ := service.GetHisAdviceExecutionById(idArray)
  7712. c.ServeSuccessJSON(map[string]interface{}{
  7713. "list": list,
  7714. })
  7715. return
  7716. }
  7717. }
  7718. func (c *DialysisAPIController) BatchAdviceExecution() {
  7719. ids := c.GetString("ids")
  7720. idArray := strings.Split(ids, ",")
  7721. executionTime := c.GetString("execution_time")
  7722. creator, _ := c.GetInt64("creator")
  7723. timeLayout := "2006-01-02 15:04:05"
  7724. loc, _ := time.LoadLocation("Local")
  7725. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7726. orgin, _ := c.GetInt64("origin")
  7727. if orgin == 1 {
  7728. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7729. list, _ := service.GetAdviceExecutionById(idArray)
  7730. fmt.Println(err)
  7731. c.ServeSuccessJSON(map[string]interface{}{
  7732. "list": list,
  7733. })
  7734. return
  7735. }
  7736. if orgin == 2 {
  7737. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7738. list, _ := service.GetHisAdviceExecutionById(idArray)
  7739. fmt.Println(err)
  7740. c.ServeSuccessJSON(map[string]interface{}{
  7741. "list": list,
  7742. })
  7743. return
  7744. }
  7745. }
  7746. func (c *DialysisAPIController) UpdateStockGoods() {
  7747. good_id, _ := c.GetInt64("good_id")
  7748. record_time, _ := c.GetInt64("record_time")
  7749. patient_id, _ := c.GetInt64("patient_id")
  7750. count, _ := c.GetInt64("count")
  7751. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7752. fmt.Print("err", err)
  7753. c.ServeSuccessJSON(map[string]interface{}{
  7754. "msg": "更新成功",
  7755. })
  7756. return
  7757. }
  7758. // 当前数据比上一次出库数据少
  7759. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7760. //查询该患者当天已经出库的耗材信息
  7761. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7762. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7763. for i := len(goods_yc) - 1; i >= 0; i-- {
  7764. goods_yc_temp := goods_yc[i]
  7765. for j := len(goods) - 1; j >= 0; j-- {
  7766. goods_temp := goods[j]
  7767. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7768. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7769. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7770. if goods_yc_temp.Count == goods_temp.Count {
  7771. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7772. goods = append(goods[:j], goods[j+1:]...)
  7773. break
  7774. }
  7775. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7776. if goods_yc_temp.Count > goods_temp.Count {
  7777. temp_count := goods_yc_temp.Count - goods_temp.Count
  7778. goods_yc[i].Count = temp_count
  7779. goods = append(goods[:j], goods[j+1:]...)
  7780. break
  7781. }
  7782. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7783. if goods_yc_temp.Count < goods_temp.Count {
  7784. temp_count := goods_temp.Count - goods_yc_temp.Count
  7785. goods[j].Count = temp_count
  7786. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7787. break
  7788. }
  7789. }
  7790. }
  7791. }
  7792. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7793. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7794. //退库
  7795. if len(goods_yc) > 0 {
  7796. for _, good_yc := range goods_yc {
  7797. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7798. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7799. }
  7800. }
  7801. return nil
  7802. }
  7803. // 耗材出库删除
  7804. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7805. // 先根据相关信息查询当天该耗材的出库信息
  7806. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7807. if err != nil {
  7808. return err
  7809. }
  7810. var delete_count int64 = 0
  7811. delete_count = warehouseOutInfos.Count - count
  7812. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7813. // 在出库记录表里记录退库详情
  7814. warehouseOutInfo := &models.WarehouseOutInfo{
  7815. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7816. WarehouseOutId: warehouseOut.ID,
  7817. Status: 1,
  7818. Ctime: time.Now().Unix(),
  7819. OrgId: orgID,
  7820. Type: 1,
  7821. IsSys: 1,
  7822. SysRecordTime: record_time,
  7823. GoodTypeId: good_yc.GoodTypeId,
  7824. GoodId: good_yc.GoodId,
  7825. PatientId: good_yc.PatientId,
  7826. ConsumableType: 2,
  7827. StorehouseId: houseConfig.StorehouseOutInfo,
  7828. IsCheck: 1,
  7829. }
  7830. warehouseOutInfo.Count = count
  7831. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7832. warehouseOutInfo.Price = stockInInfo.Price
  7833. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7834. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7835. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7836. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7837. warehouseOutInfo.Number = warehouseOutInfos.Number
  7838. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7839. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7840. //查找当天是否存在出库记录
  7841. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7842. if errcod == gorm.ErrRecordNotFound {
  7843. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7844. //插入详情明细表
  7845. stockFlow := models.VmStockFlow{
  7846. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7847. WarehouseOutId: warehouseOut.ID,
  7848. GoodId: good_yc.GoodId,
  7849. Number: warehouseOutInfos.Number,
  7850. ProductDate: stockInInfo.ProductDate,
  7851. ExpireDate: stockInInfo.ExpiryDate,
  7852. Count: count,
  7853. Price: stockInInfo.Price,
  7854. Status: 1,
  7855. Ctime: time.Now().Unix(),
  7856. UserOrgId: good_yc.OrgId,
  7857. Manufacturer: stockInInfo.Manufacturer,
  7858. Dealer: stockInInfo.Dealer,
  7859. LicenseNumber: stockInInfo.LicenseNumber,
  7860. IsEdit: 2,
  7861. Creator: creater,
  7862. SystemTime: record_time,
  7863. ConsumableType: 3,
  7864. WarehousingDetailId: 0,
  7865. IsSys: 1,
  7866. UpdateCreator: creater,
  7867. PatientId: patient_id,
  7868. StorehouseId: houseConfig.StorehouseOutInfo,
  7869. }
  7870. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7871. if errflow == gorm.ErrRecordNotFound {
  7872. //创建流水表
  7873. err := service.CreateStockFlowOne(stockFlow)
  7874. fmt.Println("err", err)
  7875. } else if errflow == nil {
  7876. //插入详情明细表
  7877. stockFlow := models.VmStockFlow{
  7878. ID: exsit.ID,
  7879. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7880. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7881. WarehouseOutId: warehouseOut.ID,
  7882. GoodId: good_yc.GoodId,
  7883. Number: warehouseOutInfos.Number,
  7884. ProductDate: stockInInfo.ProductDate,
  7885. ExpireDate: stockInInfo.ExpiryDate,
  7886. Count: exsit.Count - delete_count,
  7887. Price: stockInInfo.Price,
  7888. Status: 1,
  7889. Ctime: time.Now().Unix(),
  7890. UserOrgId: good_yc.OrgId,
  7891. Manufacturer: stockInInfo.Manufacturer,
  7892. Dealer: stockInInfo.Dealer,
  7893. LicenseNumber: stockInInfo.LicenseNumber,
  7894. IsEdit: 2,
  7895. Creator: creater,
  7896. SystemTime: record_time,
  7897. ConsumableType: 3,
  7898. WarehousingDetailId: 0,
  7899. IsSys: 1,
  7900. UpdateCreator: creater,
  7901. PatientId: patient_id,
  7902. StorehouseId: houseConfig.StorehouseOutInfo,
  7903. }
  7904. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7905. }
  7906. if errOne != nil {
  7907. return errOne
  7908. }
  7909. } else if errcod == nil {
  7910. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7911. //插入详情明细表
  7912. stockFlow := models.VmStockFlow{
  7913. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7914. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7915. WarehouseOutId: warehouseOut.ID,
  7916. GoodId: good_yc.GoodId,
  7917. Number: warehouseOutInfos.Number,
  7918. ProductDate: stockInInfo.ProductDate,
  7919. ExpireDate: stockInInfo.ExpiryDate,
  7920. Count: count,
  7921. Price: stockInInfo.Price,
  7922. Status: 1,
  7923. Ctime: time.Now().Unix(),
  7924. UserOrgId: good_yc.OrgId,
  7925. Manufacturer: stockInInfo.Manufacturer,
  7926. Dealer: stockInInfo.Dealer,
  7927. LicenseNumber: stockInInfo.LicenseNumber,
  7928. IsEdit: 2,
  7929. Creator: creater,
  7930. SystemTime: record_time,
  7931. ConsumableType: 3,
  7932. WarehousingDetailId: 0,
  7933. IsSys: 1,
  7934. UpdateCreator: creater,
  7935. PatientId: patient_id,
  7936. ReturnCount: delete_count,
  7937. StorehouseId: houseConfig.StorehouseOutInfo,
  7938. }
  7939. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7940. if errflows == gorm.ErrRecordNotFound {
  7941. //创建流水表
  7942. service.CreateStockFlowOne(stockFlow)
  7943. } else if errflows == nil {
  7944. stockFlow := models.VmStockFlow{
  7945. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7946. ID: exsit.ID,
  7947. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7948. WarehouseOutId: warehouseOut.ID,
  7949. GoodId: good_yc.GoodId,
  7950. Number: warehouseOutInfos.Number,
  7951. ProductDate: stockInInfo.ProductDate,
  7952. ExpireDate: stockInInfo.ExpiryDate,
  7953. Count: exsit.Count - delete_count,
  7954. Price: stockInInfo.Price,
  7955. Status: 1,
  7956. Ctime: time.Now().Unix(),
  7957. UserOrgId: good_yc.OrgId,
  7958. Manufacturer: stockInInfo.Manufacturer,
  7959. Dealer: stockInInfo.Dealer,
  7960. LicenseNumber: stockInInfo.LicenseNumber,
  7961. IsEdit: 2,
  7962. Creator: creater,
  7963. SystemTime: record_time,
  7964. ConsumableType: 3,
  7965. WarehousingDetailId: 0,
  7966. IsSys: 1,
  7967. UpdateCreator: creater,
  7968. PatientId: patient_id,
  7969. ReturnCount: delete_count,
  7970. StorehouseId: houseConfig.StorehouseOutInfo,
  7971. }
  7972. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7973. }
  7974. }
  7975. //更改自动出库的表格
  7976. details := models.BloodAutomaticReduceDetail{
  7977. WarehouseOutId: warehouseOutInfo.ID,
  7978. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7979. PatientId: patient_id,
  7980. Ctime: time.Now().Unix(),
  7981. Mtime: time.Now().Unix(),
  7982. Status: 1,
  7983. RecordTime: record_time,
  7984. OrgId: orgID,
  7985. GoodId: good_yc.GoodId,
  7986. GoodTypeId: good_yc.GoodTypeId,
  7987. Count: count,
  7988. StorehouseId: houseConfig.StorehouseOutInfo,
  7989. }
  7990. //查询当天耗材是否已经存在数据
  7991. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7992. if errcode == gorm.ErrRecordNotFound {
  7993. errTwo := service.CreateAutoReduceRecord(&details)
  7994. if errTwo != nil {
  7995. return errTwo
  7996. }
  7997. } else if errcode == nil {
  7998. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7999. service.CreateAutoReduceRecord(&details)
  8000. }
  8001. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8002. //增加出库库存数量
  8003. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8004. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8005. fmt.Println("errOne", errOne)
  8006. // 删除出库完成后,要增加对应批次的库存数量
  8007. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8008. if errThree != nil {
  8009. return errThree
  8010. }
  8011. if good_yc.Count == 0 {
  8012. return nil
  8013. } else {
  8014. return errors.New("退库和出库数据不匹配")
  8015. }
  8016. }
  8017. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8018. //查询该患者当天已经出库的耗材信息
  8019. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8020. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8021. for i := len(goods_yc) - 1; i >= 0; i-- {
  8022. goods_yc_temp := goods_yc[i]
  8023. for j := len(goods) - 1; j >= 0; j-- {
  8024. goods_temp := goods[j]
  8025. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8026. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8027. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8028. if goods_yc_temp.Count == goods_temp.Count {
  8029. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8030. goods = append(goods[:j], goods[j+1:]...)
  8031. break
  8032. }
  8033. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8034. if goods_yc_temp.Count > goods_temp.Count {
  8035. temp_count := goods_yc_temp.Count - goods_temp.Count
  8036. goods_yc[i].Count = temp_count
  8037. goods = append(goods[:j], goods[j+1:]...)
  8038. break
  8039. }
  8040. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8041. if goods_yc_temp.Count < goods_temp.Count {
  8042. temp_count := goods_temp.Count - goods_yc_temp.Count
  8043. goods[j].Count = temp_count
  8044. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8045. break
  8046. }
  8047. }
  8048. }
  8049. }
  8050. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8051. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8052. fmt.Println("剩余需要出库的", len(goods))
  8053. if len(goods) > 0 {
  8054. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8055. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8056. if err == gorm.ErrRecordNotFound {
  8057. //没有记录,则创建出库单
  8058. timeStr := time.Now().Format("2006-01-02")
  8059. timeArr := strings.Split(timeStr, "-")
  8060. total, _ := service.FindAllWarehouseOut(orgID)
  8061. total = total + 1
  8062. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8063. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8064. number = number + total
  8065. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8066. warehouseOut := models.WarehouseOut{
  8067. WarehouseOutOrderNumber: warehousing_out_order,
  8068. OperationTime: time.Now().Unix(),
  8069. OrgId: orgID,
  8070. Creater: creater,
  8071. Ctime: time.Now().Unix(),
  8072. Status: 1,
  8073. WarehouseOutTime: record_time,
  8074. Dealer: 0,
  8075. Manufacturer: 0,
  8076. Type: 1,
  8077. IsSys: 1,
  8078. StorehouseId: houseConfig.StorehouseOutInfo,
  8079. IsCheck: 1,
  8080. }
  8081. err := service.AddSigleWarehouseOut(&warehouseOut)
  8082. if err != nil {
  8083. utils.TraceLog("创建出库单失败 err = %v", err)
  8084. return err
  8085. } else {
  8086. out = warehouseOut
  8087. }
  8088. }
  8089. for _, item := range goods {
  8090. var newCount int64 = 0
  8091. for _, it := range goodOne {
  8092. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8093. newCount = it.Count
  8094. }
  8095. }
  8096. prepare := models.DialysisBeforePrepare{
  8097. GoodTypeId: item.GoodTypeId,
  8098. GoodId: item.GoodId,
  8099. Count: item.Count,
  8100. StorehouseId: houseConfig.StorehouseOutInfo,
  8101. }
  8102. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8103. //增加出库数量
  8104. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8105. }
  8106. }
  8107. if len(goods_yc) > 0 {
  8108. for _, good_yc := range goods_yc {
  8109. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8110. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8111. }
  8112. }
  8113. return nil
  8114. }
  8115. // 耗材出库删除
  8116. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8117. // 先根据相关信息查询当天该耗材的出库信息
  8118. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8119. if err != nil {
  8120. return err
  8121. }
  8122. var delete_count int64 = 0
  8123. for _, ware := range warehouseOutInfos {
  8124. // 判断当前出库的数据和删除出库数量
  8125. if good_yc.Count <= ware.Count {
  8126. delete_count = good_yc.Count
  8127. } else {
  8128. delete_count = ware.Count
  8129. }
  8130. warehouseOutInfo := &models.WarehouseOutInfo{
  8131. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8132. WarehouseOutId: warehouseOut.ID,
  8133. Status: 1,
  8134. Ctime: time.Now().Unix(),
  8135. Remark: "",
  8136. OrgId: orgID,
  8137. Type: 1,
  8138. Manufacturer: 0,
  8139. Dealer: 0,
  8140. IsSys: 0,
  8141. SysRecordTime: record_time,
  8142. GoodTypeId: good_yc.GoodTypeId,
  8143. GoodId: good_yc.GoodId,
  8144. StorehouseId: warehouseOut.StorehouseId,
  8145. IsCheck: 1,
  8146. }
  8147. warehouseOutInfo.Count = delete_count
  8148. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8149. warehouseOutInfo.Price = stockInInfo.Price
  8150. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8151. if errOne != nil {
  8152. return errOne
  8153. }
  8154. // 删除出库完成后,要改变流水库存(有疑问)
  8155. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8156. fmt.Println("errOne", errOne)
  8157. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8158. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8159. //扣减出库数量
  8160. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8161. if errThree != nil {
  8162. return errThree
  8163. }
  8164. }
  8165. if good_yc.Count == 0 {
  8166. return nil
  8167. } else {
  8168. return errors.New("退库和出库数据不匹配")
  8169. }
  8170. }
  8171. func (this *DialysisAPIController) GetMobileScheduleList() {
  8172. limit, _ := this.GetInt64("limit")
  8173. page, _ := this.GetInt64("page")
  8174. type_options_visible, _ := this.GetInt64("type_options_visible")
  8175. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8176. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8177. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8178. }
  8179. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8180. newArr = make([]*models.HisPrescriptionProject, 0)
  8181. for i := 0; i < len(arr); i++ {
  8182. repeat := false
  8183. for j := i + 1; j < len(arr); j++ {
  8184. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8185. repeat = true
  8186. break
  8187. }
  8188. }
  8189. if !repeat {
  8190. newArr = append(newArr, arr[i])
  8191. }
  8192. }
  8193. return
  8194. }
  8195. func (this *DialysisAPIController) GetRoleList() {
  8196. admin_user_id, _ := this.GetInt64("admin_user_id")
  8197. orgid := this.GetMobileAdminUserInfo().Org.Id
  8198. list, err := service.GetRoleList(orgid, admin_user_id)
  8199. fmt.Println(err)
  8200. this.ServeSuccessJSON(map[string]interface{}{
  8201. "list": list,
  8202. })
  8203. return
  8204. }
  8205. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8206. // 先根据相关信息查询当天该耗材的出库信息
  8207. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8208. if err != nil {
  8209. return err
  8210. }
  8211. var delete_count int64 = 0
  8212. delete_count = warehouseOutInfos.Count - count
  8213. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8214. // 删除出库完成后,要增加对应批次的库存数量
  8215. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8216. if errThree != nil {
  8217. return errThree
  8218. }
  8219. //增加退库数量
  8220. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8221. //扣减出库数量
  8222. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8223. //查询剩余库存
  8224. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8225. var sum_count int64
  8226. for _, item := range goodList {
  8227. sum_count += item.StockCount
  8228. }
  8229. // 在出库记录表里记录退库详情
  8230. warehouseOutInfo := &models.WarehouseOutInfo{
  8231. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8232. WarehouseOutId: warehouseOut.ID,
  8233. Status: 1,
  8234. Ctime: time.Now().Unix(),
  8235. OrgId: orgID,
  8236. Type: 1,
  8237. IsSys: 1,
  8238. SysRecordTime: record_time,
  8239. GoodTypeId: good_yc.GoodTypeId,
  8240. GoodId: good_yc.GoodId,
  8241. PatientId: good_yc.PatientId,
  8242. ConsumableType: 2,
  8243. StorehouseId: houseConfig.StorehouseOutInfo,
  8244. IsCheck: 1,
  8245. OverCount: sum_count,
  8246. }
  8247. warehouseOutInfo.Count = count
  8248. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8249. warehouseOutInfo.Price = stockInInfo.Price
  8250. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8251. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8252. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8253. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8254. warehouseOutInfo.Number = warehouseOutInfos.Number
  8255. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8256. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8257. //查找当天是否存在出库记录
  8258. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8259. if errcod == gorm.ErrRecordNotFound {
  8260. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8261. //插入详情明细表
  8262. if errOne != nil {
  8263. return errOne
  8264. }
  8265. //插入详情明细表
  8266. stockFlow := models.VmStockFlow{
  8267. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8268. WarehouseOutId: warehouseOut.ID,
  8269. GoodId: good_yc.GoodId,
  8270. Number: warehouseOutInfos.Number,
  8271. ProductDate: stockInInfo.ProductDate,
  8272. ExpireDate: stockInInfo.ExpiryDate,
  8273. Count: count,
  8274. Price: stockInInfo.Price,
  8275. Status: 1,
  8276. Ctime: record_time,
  8277. UserOrgId: good_yc.OrgId,
  8278. Manufacturer: stockInInfo.Manufacturer,
  8279. Dealer: stockInInfo.Dealer,
  8280. LicenseNumber: stockInInfo.LicenseNumber,
  8281. IsEdit: 2,
  8282. Creator: creater,
  8283. SystemTime: record_time,
  8284. ConsumableType: 3,
  8285. WarehousingDetailId: 0,
  8286. IsSys: 1,
  8287. UpdateCreator: creater,
  8288. PatientId: patient_id,
  8289. StorehouseId: houseConfig.StorehouseOutInfo,
  8290. OverCount: sum_count,
  8291. ProjectId: good_yc.ProjectId,
  8292. }
  8293. err := service.CreateStockFlowOne(stockFlow)
  8294. fmt.Println("err", err)
  8295. } else if errcod == nil {
  8296. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8297. }
  8298. //创建退库单
  8299. operation_time := time.Now().Unix()
  8300. //创建退库单
  8301. timeStr := time.Now().Format("2006-01-02")
  8302. timeArr := strings.Split(timeStr, "-")
  8303. total, _ := service.FindAllCancelStockTotal(orgID)
  8304. total = total + 1
  8305. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8306. cancelStock := models.CancelStock{
  8307. OrderNumber: orderNumber,
  8308. OperaTime: operation_time,
  8309. OrgId: orgID,
  8310. Creater: warehouseOut.Creater,
  8311. Ctime: time.Now().Unix(),
  8312. Status: 1,
  8313. ReturnTime: record_time,
  8314. Type: 1,
  8315. StorehouseId: stockInInfo.StorehouseId,
  8316. IsCheck: 1,
  8317. }
  8318. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8319. if msgerrkonde == gorm.ErrRecordNotFound {
  8320. service.AddSigleCancelStock(&cancelStock)
  8321. }
  8322. cancel, _ := service.GetLastCancelStockById(orgID)
  8323. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8324. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8325. cancelStockInfo := models.CancelStockInfo{
  8326. GoodId: stockInInfo.GoodId,
  8327. CancelStockId: cancel.ID,
  8328. GoodTypeId: stockInInfo.GoodTypeId,
  8329. Count: delete_count,
  8330. Price: stockInInfo.PackingPrice,
  8331. Total: 0,
  8332. ProductDate: stockInInfo.ProductDate,
  8333. ExpiryDate: stockInInfo.ExpiryDate,
  8334. Ctime: record_time,
  8335. Status: 1,
  8336. OrgId: orgID,
  8337. OrderNumber: cancel.OrderNumber,
  8338. Type: 0,
  8339. Dealer: deaerler.DealerName,
  8340. Manufacturer: manufacturer.ManufacturerName,
  8341. Number: stockInInfo.Number,
  8342. RegisterAccount: "",
  8343. Remark: "",
  8344. WarehouseInfoId: stockInInfo.ID,
  8345. PatientId: patient_id,
  8346. RecordDate: record_time,
  8347. StorehouseId: stockInInfo.StorehouseId,
  8348. IsCheck: 1,
  8349. }
  8350. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8351. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8352. flow := models.VmStockFlow{
  8353. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8354. GoodId: good_yc.GoodId,
  8355. Number: warehouseOutInfos.Number,
  8356. LicenseNumber: stockInInfo.LicenseNumber,
  8357. Count: delete_count,
  8358. UserOrgId: orgID,
  8359. PatientId: patient_id,
  8360. SystemTime: record_time,
  8361. ConsumableType: 7,
  8362. IsSys: 0,
  8363. WarehousingOrder: "",
  8364. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8365. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8366. IsEdit: 0,
  8367. CancelStockId: cancel.ID,
  8368. CancelOrderNumber: cancel.OrderNumber,
  8369. Manufacturer: manufacturer.ID,
  8370. Dealer: 0,
  8371. Creator: warehouseOut.Creater,
  8372. UpdateCreator: 0,
  8373. Status: 1,
  8374. Ctime: record_time,
  8375. Mtime: 0,
  8376. Price: stockInInfo.Price,
  8377. WarehousingDetailId: stockInInfo.ID,
  8378. WarehouseOutDetailId: warehouseOutInfos.ID,
  8379. CancelOutDetailId: cancelInfo.ID,
  8380. ProductDate: stockInInfo.ProductDate,
  8381. ExpireDate: stockInInfo.ExpiryDate,
  8382. StorehouseId: houseConfig.StorehouseOutInfo,
  8383. OverCount: sum_count,
  8384. }
  8385. service.CreateStockFlowOne(flow)
  8386. //更改自动出库的表格
  8387. details := models.BloodAutomaticReduceDetail{
  8388. WarehouseOutId: warehouseOutInfo.ID,
  8389. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8390. PatientId: patient_id,
  8391. Ctime: time.Now().Unix(),
  8392. Mtime: time.Now().Unix(),
  8393. Status: 1,
  8394. RecordTime: record_time,
  8395. OrgId: orgID,
  8396. GoodId: good_yc.GoodId,
  8397. GoodTypeId: good_yc.GoodTypeId,
  8398. Count: count,
  8399. StorehouseId: houseConfig.StorehouseOutInfo,
  8400. }
  8401. //查询当天耗材是否已经存在数据
  8402. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8403. if errcode == gorm.ErrRecordNotFound {
  8404. errTwo := service.CreateAutoReduceRecord(&details)
  8405. if errTwo != nil {
  8406. return errTwo
  8407. }
  8408. } else if errcode == nil {
  8409. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8410. service.CreateAutoReduceRecord(&details)
  8411. }
  8412. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8413. //增加出库库存数量
  8414. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8415. if good_yc.Count == 0 {
  8416. return nil
  8417. } else {
  8418. return errors.New("退库和出库数据不匹配")
  8419. }
  8420. }
  8421. func (this *DialysisAPIController) SavePatientSign() {
  8422. adminUserInfo := this.GetMobileAdminUserInfo()
  8423. patient_id, _ := this.GetInt64("patient_id")
  8424. dialysis_date, _ := this.GetInt64("dialysis_date")
  8425. orgid := adminUserInfo.Org.Id
  8426. var esdata models.DialysisOrder
  8427. var err error
  8428. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8430. return
  8431. }
  8432. esdata.Hash = esdata.Hash
  8433. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8434. order := models.DialysisOrder{
  8435. Hash: esdata.Hash,
  8436. Url: esdata.Url,
  8437. }
  8438. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8439. redis := service.RedisClient()
  8440. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8441. redis.Set(key, "", time.Second)
  8442. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8443. //清空key 值
  8444. redis.Set(keyOne, "", time.Second)
  8445. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8446. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8447. //redis.Set(keyTwo, "", time.Second)
  8448. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8449. redis.Set(keyThree, "", time.Second)
  8450. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8451. redis.Set(keyFour, "", time.Second)
  8452. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8453. redis.Set(keyFive, "", time.Second)
  8454. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8455. redis.Set(keySix, "", time.Second)
  8456. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8457. redis.Set(keySeven, "", time.Second)
  8458. if err != nil {
  8459. fmt.Println(err)
  8460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8461. return
  8462. }
  8463. this.ServeSuccessJSON(map[string]interface{}{
  8464. "electronic_signature": esdata,
  8465. })
  8466. }
  8467. func (this *DialysisAPIController) GetPatientSign() {
  8468. patient_id, _ := this.GetInt64("patient_id")
  8469. dialysis_date, _ := this.GetInt64("dialysis_date")
  8470. adminUserInfo := this.GetMobileAdminUserInfo()
  8471. orgId := adminUserInfo.Org.Id
  8472. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8473. if err != nil {
  8474. fmt.Println(err)
  8475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8476. return
  8477. }
  8478. this.ServeSuccessJSON(map[string]interface{}{
  8479. "dialysisOrder": dialysisOrder,
  8480. })
  8481. }
  8482. func (this *DialysisAPIController) GetScheduleByPatient() {
  8483. patient_id, _ := this.GetInt64("patient_id")
  8484. schedule_date, _ := this.GetInt64("schedule_date")
  8485. orgid := this.GetMobileAdminUserInfo().Org.Id
  8486. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8487. this.ServeSuccessJSON(map[string]interface{}{
  8488. "schedule": schedule,
  8489. })
  8490. }
  8491. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8492. org_id := this.GetMobileAdminUserInfo().Org.Id
  8493. patient_id, _ := this.GetInt64("patient_id")
  8494. schedule_date, _ := this.GetInt64("schedule_date")
  8495. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8496. this.ServeSuccessJSON(map[string]interface{}{
  8497. "order": order,
  8498. })
  8499. }
  8500. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8501. org_id := this.GetMobileAdminUserInfo().Org.Id
  8502. schedule_date := this.GetString("schedule_date")
  8503. schedule_type, _ := this.GetInt64("schedule_type")
  8504. timeLayout := "2006-01-02"
  8505. loc, _ := time.LoadLocation("Local")
  8506. var startdateunix int64
  8507. if len(schedule_date) > 0 {
  8508. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8509. if err != nil {
  8510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8511. return
  8512. }
  8513. startdateunix = theTime.Unix()
  8514. }
  8515. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8516. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8517. devices, _ := service.GetAllDevicetByListSix(org_id)
  8518. for key, item := range scheduals {
  8519. // 床位信息
  8520. for _, device := range devices {
  8521. if item.BedId == device.ID {
  8522. scheduals[key].DeviceNumber = device
  8523. break
  8524. }
  8525. }
  8526. }
  8527. this.ServeSuccessJSON(map[string]interface{}{
  8528. "list": list,
  8529. "scheduals": scheduals,
  8530. })
  8531. }
  8532. func (this *DialysisAPIController) SavePatientPicture() {
  8533. patient_id, _ := this.GetInt64("patient_id")
  8534. dialysis_date, _ := this.GetInt64("schedule_date")
  8535. avatar := this.GetString("avatar")
  8536. fmt.Println("patient_id", patient_id)
  8537. orgId := this.GetMobileAdminUserInfo().Org.Id
  8538. order := models.DialysisOrder{
  8539. Url: avatar,
  8540. }
  8541. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8542. redis := service.RedisClient()
  8543. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8544. redis.Set(key, "", time.Second)
  8545. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8546. //清空key 值
  8547. redis.Set(keyOne, "", time.Second)
  8548. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8549. redis.Set(keyThree, "", time.Second)
  8550. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8551. redis.Set(keyFour, "", time.Second)
  8552. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8553. redis.Set(keyFive, "", time.Second)
  8554. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8555. redis.Set(keySix, "", time.Second)
  8556. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8557. redis.Set(keySeven, "", time.Second)
  8558. if err != nil {
  8559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8560. return
  8561. }
  8562. this.ServeSuccessJSON(map[string]interface{}{
  8563. "order": order,
  8564. })
  8565. }
  8566. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8567. ids := this.GetString("ids")
  8568. idSplit := strings.Split(ids, ",")
  8569. orgId := this.GetMobileAdminUserInfo().Org.Id
  8570. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8571. execution_time := this.GetString("exce_time")
  8572. timeLayout2 := "2006-01-02 15:04:05"
  8573. loc, _ := time.LoadLocation("Local")
  8574. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8575. if errs != nil {
  8576. utils.ErrorLog(errs.Error())
  8577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8578. return
  8579. }
  8580. //his客户
  8581. if config.IsOpen == 1 {
  8582. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8583. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8584. for _, item := range list {
  8585. for _, it := range adviceList {
  8586. if item.DrugId == it.DrugId {
  8587. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8588. }
  8589. }
  8590. }
  8591. for _, item := range list {
  8592. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8593. var sum_out_count int64
  8594. for _, itemThree := range item.ChildDoctorAdvice {
  8595. var prescribing_number int64
  8596. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8597. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8598. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8599. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8600. }
  8601. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8602. prescribing_number = parseIntPrescribingNumber
  8603. }
  8604. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8605. prescribing_number = parseIntPrescribingNumber
  8606. }
  8607. sum_out_count += prescribing_number
  8608. }
  8609. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8610. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8611. //库存不足
  8612. if sum_out_count > drugStockOut.FlushCount {
  8613. this.ServeSuccessJSON(map[string]interface{}{
  8614. "msg": "2",
  8615. "drug": medical,
  8616. "ids": ids,
  8617. })
  8618. return
  8619. }
  8620. }
  8621. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8622. //执行医嘱
  8623. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8624. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8625. for _, item := range advices {
  8626. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8627. redis := service.RedisClient()
  8628. //清空key 值
  8629. redis.Set(key, "", time.Second)
  8630. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8631. redis.Set(keyTwo, "", time.Second)
  8632. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8633. redis.Set(keyThree, "", time.Second)
  8634. recordDate := theTime.Format("2006-01-02")
  8635. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8636. redis.Set(keyFour, "", time.Second)
  8637. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8638. redis.Set(keyFive, "", time.Second)
  8639. defer redis.Close()
  8640. }
  8641. if errs == nil {
  8642. //药品管理信息
  8643. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8644. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8645. if drugStockConfig.IsOpen == 1 {
  8646. for _, item := range advices {
  8647. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8648. config, _ := service.GetDrugOpenConfigOne(orgId)
  8649. if config.IsOpen != 1 {
  8650. //查询该药品是否有库存
  8651. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8652. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8653. if medical.IsUse == 2 {
  8654. if config.IsOpen != 1 {
  8655. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8656. service.HisDrugsDelivery(orgId, creater, &advice)
  8657. if orgId == 3877 || orgId == 10265 {
  8658. //查询该药品是否有出库记录
  8659. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8660. if len(flowMap) == 0 {
  8661. errs := service.UpdateHisAdviceById(advice.ID)
  8662. if errs != nil {
  8663. drugError := models.XtDrugError{
  8664. UserOrgId: orgId,
  8665. DrugId: item.DrugId,
  8666. RecordDate: item.AdviceDate,
  8667. PatientId: item.PatientId,
  8668. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8669. Status: 1,
  8670. Ctime: time.Now().Unix(),
  8671. Mtime: 0,
  8672. SumCount: 0,
  8673. Prescribingnumber: advice.PrescribingNumber,
  8674. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8675. }
  8676. service.CreateDrugError(drugError)
  8677. }
  8678. this.ServeSuccessJSON(map[string]interface{}{
  8679. "msg": "2",
  8680. "drug": medical,
  8681. "ids": ids,
  8682. })
  8683. return
  8684. }
  8685. }
  8686. }
  8687. if pharmacyConfig.IsOpen != 1 {
  8688. service.HisDrugsDelivery(orgId, creater, &advice)
  8689. if orgId == 3877 || orgId == 10265 {
  8690. //查询该药品是否有出库记录
  8691. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8692. if len(flowMap) == 0 {
  8693. errs := service.UpdateHisAdviceById(advice.ID)
  8694. if errs != nil {
  8695. drugError := models.XtDrugError{
  8696. UserOrgId: orgId,
  8697. DrugId: item.DrugId,
  8698. RecordDate: item.AdviceDate,
  8699. PatientId: item.PatientId,
  8700. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8701. Status: 1,
  8702. Ctime: time.Now().Unix(),
  8703. Mtime: 0,
  8704. SumCount: 0,
  8705. Prescribingnumber: advice.PrescribingNumber,
  8706. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8707. }
  8708. service.CreateDrugError(drugError)
  8709. }
  8710. this.ServeSuccessJSON(map[string]interface{}{
  8711. "msg": "2",
  8712. "drug": medical,
  8713. "ids": ids,
  8714. })
  8715. return
  8716. }
  8717. }
  8718. }
  8719. //更新字典里面的库存
  8720. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8721. var sum_count int64
  8722. for _, its := range stockInfo {
  8723. if its.MaxUnit == medical.MaxUnit {
  8724. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8725. }
  8726. sum_count += its.StockMaxNumber + its.StockMinNumber
  8727. }
  8728. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8729. //剩余库存
  8730. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8731. }
  8732. }
  8733. }
  8734. }
  8735. }
  8736. this.ServeSuccessJSON(map[string]interface{}{
  8737. "msg": "1",
  8738. "ids": ids,
  8739. })
  8740. return
  8741. } else {
  8742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8743. }
  8744. }
  8745. //血透客户
  8746. if config.IsOpen == 2 || config.IsOpen == 0 {
  8747. //药品管理信息
  8748. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8749. if drugStockConfig.IsOpen == 1 {
  8750. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8751. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8752. for _, item := range list {
  8753. for _, it := range adviceList {
  8754. if item.DrugId == it.DrugId {
  8755. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8756. }
  8757. }
  8758. }
  8759. for _, item := range list {
  8760. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8761. var sum_out_count int64
  8762. for _, itemThree := range item.ChildDoctorAdvice {
  8763. var prescribing_number int64
  8764. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8765. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8766. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8767. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8768. }
  8769. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8770. prescribing_number = parseIntPrescribingNumber
  8771. }
  8772. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8773. prescribing_number = parseIntPrescribingNumber
  8774. }
  8775. sum_out_count += prescribing_number
  8776. }
  8777. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8778. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8779. //库存不足
  8780. if sum_out_count > drugStockOut.FlushCount {
  8781. this.ServeSuccessJSON(map[string]interface{}{
  8782. "msg": "2",
  8783. "drug": medical,
  8784. "ids": ids,
  8785. })
  8786. return
  8787. }
  8788. }
  8789. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8790. //执行医嘱
  8791. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8792. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8793. for _, item := range advices {
  8794. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8795. redis := service.RedisClient()
  8796. //清空key 值
  8797. redis.Set(key, "", time.Second)
  8798. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8799. redis.Set(keyTwo, "", time.Second)
  8800. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8801. redis.Set(keyThree, "", time.Second)
  8802. recordDate := theTime.Format("2006-01-02")
  8803. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8804. redis.Set(keyFour, "", time.Second)
  8805. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8806. redis.Set(keyFive, "", time.Second)
  8807. defer redis.Close()
  8808. }
  8809. if errs == nil {
  8810. for _, item := range advices {
  8811. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8812. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8813. //查询是否出库按钮开启
  8814. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8815. if adviceSetting.IsAdviceOpen == 1 {
  8816. //查询是否出库按钮开启
  8817. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8818. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8819. if prescriptionConfig.IsOpen == 1 {
  8820. if medical.IsUse == 2 {
  8821. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8822. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8823. }
  8824. if pharmacyConfig.IsOpen != 1 {
  8825. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8826. }
  8827. //更新字典里面的库存
  8828. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8829. var sum_count int64
  8830. for _, its := range stockInfo {
  8831. if its.MaxUnit == medical.MaxUnit {
  8832. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8833. }
  8834. sum_count += its.StockMaxNumber + its.StockMinNumber
  8835. }
  8836. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8837. //剩余库存
  8838. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8839. }
  8840. }
  8841. } else {
  8842. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8843. if medical.IsUse == 2 {
  8844. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8845. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8846. }
  8847. if pharmacyConfig.IsOpen != 1 {
  8848. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8849. }
  8850. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8851. var sum_count int64
  8852. for _, its := range stockInfo {
  8853. if its.MaxUnit == medical.MaxUnit {
  8854. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8855. }
  8856. sum_count += its.StockMaxNumber + its.StockMinNumber
  8857. }
  8858. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8859. //剩余库存
  8860. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8861. }
  8862. }
  8863. }
  8864. }
  8865. this.ServeSuccessJSON(map[string]interface{}{
  8866. "msg": "1",
  8867. "ids": ids,
  8868. })
  8869. return
  8870. } else {
  8871. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8872. //执行医嘱
  8873. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8874. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8875. for _, item := range advices {
  8876. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8877. redis := service.RedisClient()
  8878. //清空key 值
  8879. redis.Set(key, "", time.Second)
  8880. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8881. redis.Set(keyTwo, "", time.Second)
  8882. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8883. redis.Set(keyThree, "", time.Second)
  8884. recordDate := theTime.Format("2006-01-02")
  8885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8886. redis.Set(keyFour, "", time.Second)
  8887. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8888. redis.Set(keyFive, "", time.Second)
  8889. defer redis.Close()
  8890. }
  8891. this.ServeSuccessJSON(map[string]interface{}{
  8892. "msg": "1",
  8893. "ids": ids,
  8894. })
  8895. return
  8896. }
  8897. }
  8898. }
  8899. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8900. ids := this.GetString("ids")
  8901. idSplit := strings.Split(ids, ",")
  8902. orgId := this.GetMobileAdminUserInfo().Org.Id
  8903. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8904. if config.IsOpen == 1 {
  8905. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8906. this.ServeSuccessJSON(map[string]interface{}{
  8907. "msg": "1",
  8908. "ids": ids,
  8909. })
  8910. return
  8911. }
  8912. if config.IsOpen == 0 || config.IsOpen == 2 {
  8913. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8914. this.ServeSuccessJSON(map[string]interface{}{
  8915. "msg": "1",
  8916. "ids": ids,
  8917. })
  8918. return
  8919. }
  8920. }
  8921. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8922. ids := this.GetString("ids")
  8923. idSplit := strings.Split(ids, ",")
  8924. orgId := this.GetMobileAdminUserInfo().Org.Id
  8925. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8926. //his
  8927. if config.IsOpen == 1 {
  8928. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8929. theTime := time.Now()
  8930. advices := models.HisDoctorAdviceThirty{
  8931. CheckTime: theTime.Unix(),
  8932. Checker: checker,
  8933. UpdatedTime: time.Now().Unix(),
  8934. }
  8935. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8936. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8937. for _, item := range list {
  8938. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8939. redis := service.RedisClient()
  8940. //清空key 值
  8941. redis.Set(key, "", time.Second)
  8942. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8943. redis.Set(keyTwo, "", time.Second)
  8944. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8945. redis.Set(keyThree, "", time.Second)
  8946. recordDate := theTime.Format("2006-01-02")
  8947. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8948. redis.Set(keyFour, "", time.Second)
  8949. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8950. redis.Set(keyFive, "", time.Second)
  8951. defer redis.Close()
  8952. }
  8953. this.ServeSuccessJSON(map[string]interface{}{
  8954. "msg": "1",
  8955. "ids": ids,
  8956. })
  8957. return
  8958. }
  8959. //血透
  8960. if config.IsOpen == 0 || config.IsOpen == 2 {
  8961. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8962. theTime := time.Now()
  8963. advices := models.DoctorAdvice{
  8964. CheckTime: theTime.Unix(),
  8965. Checker: checker,
  8966. UpdatedTime: time.Now().Unix(),
  8967. }
  8968. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8969. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8970. for _, item := range list {
  8971. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8972. redis := service.RedisClient()
  8973. //清空key 值
  8974. redis.Set(key, "", time.Second)
  8975. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8976. redis.Set(keyTwo, "", time.Second)
  8977. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8978. redis.Set(keyThree, "", time.Second)
  8979. recordDate := theTime.Format("2006-01-02")
  8980. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8981. redis.Set(keyFour, "", time.Second)
  8982. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8983. redis.Set(keyFive, "", time.Second)
  8984. defer redis.Close()
  8985. }
  8986. this.ServeSuccessJSON(map[string]interface{}{
  8987. "msg": "1",
  8988. "ids": ids,
  8989. })
  8990. return
  8991. }
  8992. }
  8993. func (this *DialysisAPIController) CheckSchedule() {
  8994. patientID, _ := this.GetInt64("patient_id")
  8995. recordDateStr := this.GetString("record_date")
  8996. nurseID, _ := this.GetInt64("start_nurse")
  8997. schedual_type, _ := this.GetInt64("schedual_type")
  8998. bedID, _ := this.GetInt64("bed")
  8999. start_time := this.GetString("start_time")
  9000. fmt.Println("patientID", patientID)
  9001. fmt.Println("recordDateStr", recordDateStr)
  9002. fmt.Println("nurseID", nurseID)
  9003. fmt.Println("schedual_type------", schedual_type)
  9004. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9006. return
  9007. }
  9008. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9009. if parseStartDateErr != nil {
  9010. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9012. return
  9013. }
  9014. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9015. if parseErr != nil {
  9016. this.ErrorLog("时间解析失败:%v", parseErr)
  9017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9018. return
  9019. }
  9020. adminUserInfo := this.GetMobileAdminUserInfo()
  9021. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9022. if getPatientErr != nil {
  9023. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9025. return
  9026. } else if patient == nil {
  9027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9028. return
  9029. }
  9030. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9031. if getNurseErr != nil {
  9032. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9034. return
  9035. } else if nurse == nil {
  9036. this.ErrorLog("护士不存在")
  9037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9038. return
  9039. }
  9040. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9041. if getDeviceNumberErr != nil {
  9042. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9044. return
  9045. } else if deviceNumber == nil {
  9046. this.ErrorLog("床位号不存在")
  9047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9048. return
  9049. }
  9050. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9051. if getRecordErr != nil {
  9052. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9054. return
  9055. } else if dialysisRecord != nil {
  9056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9057. return
  9058. }
  9059. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9060. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9061. timeLayout := "2006-01-02 15:04:05"
  9062. loc, _ := time.LoadLocation("Local")
  9063. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9064. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9065. schedulestartTime := theStartTime.Unix()
  9066. scheduleendTime := theEndTime.Unix()
  9067. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9068. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9069. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9070. //查询该床位是否有人用了
  9071. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9072. if err == nil {
  9073. if schedule.ID == 0 {
  9074. this.ServeSuccessJSON(map[string]interface{}{
  9075. "status": 0,
  9076. "msg": "请求失败",
  9077. })
  9078. } else {
  9079. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9080. if order.ID > 0 { //该机位被其他人占用了
  9081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9082. return
  9083. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9084. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9085. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9086. this.ServeSuccessJSON(map[string]interface{}{
  9087. "status": 1,
  9088. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9089. })
  9090. return
  9091. } else {
  9092. this.ServeSuccessJSON(map[string]interface{}{
  9093. "status": 0,
  9094. "msg": "",
  9095. })
  9096. }
  9097. }
  9098. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9099. this.ServeSuccessJSON(map[string]interface{}{
  9100. "status": 2,
  9101. "msg": "当前机位已有患者在使用,请重新选择!",
  9102. })
  9103. }
  9104. }
  9105. } else {
  9106. this.ServeSuccessJSON(map[string]interface{}{
  9107. "status": 0,
  9108. "msg": "",
  9109. })
  9110. }
  9111. }
  9112. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9113. orgId := this.GetMobileAdminUserInfo().Org.Id
  9114. schedule_type, _ := this.GetInt64("schedule_type")
  9115. partion_type, _ := this.GetInt64("partion_type")
  9116. start_time := this.GetString("start_time")
  9117. timeLayout := "2006-01-02"
  9118. loc, _ := time.LoadLocation("Local")
  9119. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9120. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9121. _, config := service.FindXTHisRecordByOrgId(orgId)
  9122. appId := this.GetMobileAdminUserInfo().App.Id
  9123. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9124. if err == nil {
  9125. this.ServeSuccessJSON(map[string]interface{}{
  9126. "list": list,
  9127. "config": config,
  9128. "doctorList": doctorList,
  9129. })
  9130. return
  9131. } else {
  9132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9133. return
  9134. }
  9135. }
  9136. func (this *DialysisAPIController) SaveMobileInformation() {
  9137. patient_id, _ := this.GetInt64("patient_id")
  9138. record_date, _ := this.GetInt64("record_date")
  9139. startTime := this.GetString("start_time")
  9140. module, _ := this.GetInt64("module")
  9141. remark := this.GetString("remark")
  9142. timeLayout := "2006-01-02 15:04"
  9143. loc, _ := time.LoadLocation("Local")
  9144. if len(startTime) == 0 {
  9145. utils.ErrorLog("len(start_time) == 0")
  9146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9147. return
  9148. }
  9149. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9150. if err != nil {
  9151. utils.ErrorLog(err.Error())
  9152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9153. return
  9154. }
  9155. StartTime := theTime.Unix()
  9156. fmt.Println("startime-------------", StartTime)
  9157. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9158. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9159. information := models.XtDialysisInformation{
  9160. Module: module,
  9161. PatientId: patient_id,
  9162. RecordDate: record_date,
  9163. ApplicationDate: StartTime,
  9164. Creater: creater,
  9165. ApplicationStatus: 2,
  9166. Checker: 0,
  9167. CheckTime: 0,
  9168. Remark: remark,
  9169. UserOrgId: user_org_id,
  9170. Ctime: time.Now().Unix(),
  9171. Status: 1,
  9172. Mtime: 0,
  9173. }
  9174. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9175. if infor.ID == 0 {
  9176. service.SaveDialysisInformation(information)
  9177. }
  9178. if infor.ID > 0 {
  9179. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9180. }
  9181. this.ServeSuccessJSON(map[string]interface{}{
  9182. "information": information,
  9183. })
  9184. return
  9185. }
  9186. func (this *DialysisAPIController) GetMobileInformation() {
  9187. limit, _ := this.GetInt64("limit")
  9188. page, _ := this.GetInt64("page")
  9189. orgid := this.GetMobileAdminUserInfo().Org.Id
  9190. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9191. appid := this.GetMobileAdminUserInfo().App.Id
  9192. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9193. patients, _ := service.GetAllpatientThirty(orgid)
  9194. this.ServeSuccessJSON(map[string]interface{}{
  9195. "information": information,
  9196. "total": total,
  9197. "doclist": doclist,
  9198. "patients": patients,
  9199. })
  9200. return
  9201. }
  9202. func (this *DialysisAPIController) GetMobileInformationOne() {
  9203. limit, _ := this.GetInt64("limit")
  9204. page, _ := this.GetInt64("page")
  9205. orgid := this.GetMobileAdminUserInfo().Org.Id
  9206. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9207. appid := this.GetMobileAdminUserInfo().App.Id
  9208. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9209. patients, _ := service.GetAllpatientThirty(orgid)
  9210. this.ServeSuccessJSON(map[string]interface{}{
  9211. "information": information,
  9212. "total": total,
  9213. "doclist": doclist,
  9214. "patients": patients,
  9215. })
  9216. return
  9217. }
  9218. func (this *DialysisAPIController) CheckMobileInformation() {
  9219. id, _ := this.GetInt64("id")
  9220. application_status, _ := this.GetInt64("application_status")
  9221. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9222. checktime := time.Now().Unix()
  9223. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9224. if err == nil {
  9225. this.ServeSuccessJSON(map[string]interface{}{
  9226. "msg": "ok",
  9227. })
  9228. return
  9229. }
  9230. }
  9231. func (c *DialysisAPIController) GetControlMonitorList() {
  9232. partition, _ := c.GetInt64("partition")
  9233. monitorDate := c.GetString("date")
  9234. patient_id, _ := c.GetInt64("patient_id")
  9235. pat_type, _ := c.GetInt64("pat_type")
  9236. timeLayout := "2006-01-02"
  9237. loc, _ := time.LoadLocation("Local")
  9238. var theStartTime int64
  9239. if len(monitorDate) > 0 {
  9240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9241. if err != nil {
  9242. theStartTime = 0
  9243. }
  9244. theStartTime = theTime.Unix()
  9245. }
  9246. adminInfo := c.GetMobileAdminUserInfo()
  9247. orgID := adminInfo.Org.Id
  9248. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9249. if err != nil {
  9250. c.ErrorLog("获取排班信息失败:%v", err)
  9251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9252. } else {
  9253. if len(monitor) > 0 {
  9254. //获取所有床位
  9255. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9256. //获取所有分区
  9257. zoneList, _ := service.GetAllZoneByList(orgID)
  9258. //获取透析处方
  9259. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9260. //获取透前评估
  9261. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9262. //获取上机
  9263. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9264. //获取透后
  9265. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9266. //获取透后监测
  9267. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9268. //获取所有的患者
  9269. patients, _ := service.GetAllPatientListByListOne(orgID)
  9270. //获取所有透析模式
  9271. treatments, _ := service.GetAllTreatModeByList(orgID)
  9272. //获取所有医嘱
  9273. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9274. //获取双人核对
  9275. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9276. //治疗小结
  9277. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9278. //待消毒
  9279. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9280. for key, item := range monitor {
  9281. // 获取床位信息
  9282. for _, it := range numberList {
  9283. if item.BedId == it.ID {
  9284. monitor[key].DeviceNumber = it
  9285. break
  9286. }
  9287. }
  9288. //获取分区信息
  9289. for _, it := range zoneList {
  9290. if item.PartitionId == it.ID {
  9291. monitor[key].DeviceZone = it
  9292. }
  9293. }
  9294. for _, prescription := range prescriptions {
  9295. if item.PatientId == prescription.PatientId {
  9296. monitor[key].Prescription = prescription
  9297. break
  9298. }
  9299. }
  9300. for _, it := range checkList {
  9301. if item.PatientId == it.PatientId {
  9302. monitor[key].DoubleCheck = it
  9303. break
  9304. }
  9305. }
  9306. for _, it := range summaryList {
  9307. if item.PatientId == it.PatientId {
  9308. monitor[key].TreatmentSummaryForList = it
  9309. break
  9310. }
  9311. }
  9312. // 透前评估
  9313. for _, assessmentBefore := range assessmentBefores {
  9314. if item.PatientId == assessmentBefore.PatientId {
  9315. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9316. break
  9317. }
  9318. }
  9319. // 透析上下机
  9320. for _, dialysisOrder := range dialysisOrders {
  9321. if item.PatientId == dialysisOrder.PatientId {
  9322. monitor[key].DialysisOrder = dialysisOrder
  9323. break
  9324. }
  9325. }
  9326. // 治疗小节
  9327. for _, afterDislysis := range AssessmentAfterDislysis {
  9328. if item.PatientId == afterDislysis.PatientId {
  9329. monitor[key].AssessmentAfterDislysis = afterDislysis
  9330. break
  9331. }
  9332. }
  9333. for _, it := range monitorlist {
  9334. if item.PatientId == it.PatientId {
  9335. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9336. }
  9337. }
  9338. for _, it := range adviceList {
  9339. if item.PatientId == it.PatientId {
  9340. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9341. }
  9342. }
  9343. for _, patient := range patients {
  9344. if item.PatientId == patient.ID {
  9345. monitor[key].MonitorPatients = patient
  9346. break
  9347. }
  9348. }
  9349. for _, treatment := range treatments {
  9350. if item.ModeId == treatment.ID {
  9351. monitor[key].TreatmentMode = treatment
  9352. break
  9353. }
  9354. }
  9355. for _, infor := range informationList {
  9356. if item.PatientId == infor.PatientId {
  9357. monitor[key].NewDeviceInformation = infor
  9358. break
  9359. }
  9360. }
  9361. }
  9362. }
  9363. }
  9364. patients, err := service.GetAllpatientFourty(orgID)
  9365. var mds []*models.NewMonitorDialysisScheduleList
  9366. if pat_type == 0 {
  9367. for _, item := range monitor {
  9368. mds = append(mds, item)
  9369. }
  9370. }
  9371. //待医嘱核对
  9372. if pat_type == 1 {
  9373. for _, item := range monitor {
  9374. if len(item.AdviceList) > 0 {
  9375. mds = append(mds, item)
  9376. }
  9377. }
  9378. }
  9379. //待开小结
  9380. if pat_type == 2 {
  9381. for _, item := range monitor {
  9382. if item.TreatmentSummaryForList == nil {
  9383. mds = append(mds, item)
  9384. }
  9385. }
  9386. }
  9387. //待下机
  9388. if pat_type == 3 {
  9389. for _, item := range monitor {
  9390. if item.DialysisOrder != nil {
  9391. if item.DialysisOrder.ID > 0 {
  9392. mds = append(mds, item)
  9393. }
  9394. }
  9395. }
  9396. }
  9397. //待消毒
  9398. if pat_type == 4 {
  9399. for _, item := range monitor {
  9400. if item.NewDeviceInformation == nil {
  9401. mds = append(mds, item)
  9402. }
  9403. }
  9404. }
  9405. //待双人核对
  9406. if pat_type == 5 {
  9407. for _, item := range monitor {
  9408. if item.DoubleCheck == nil {
  9409. mds = append(mds, item)
  9410. }
  9411. }
  9412. }
  9413. //医嘱未执行
  9414. if pat_type == 6 {
  9415. for _, item := range monitor {
  9416. if len(item.AdviceList) > 0 {
  9417. mds = append(mds, item)
  9418. }
  9419. }
  9420. }
  9421. //患者未签名
  9422. if pat_type == 7 {
  9423. for _, item := range monitor {
  9424. if item.DialysisOrder != nil {
  9425. if item.DialysisOrder.ID > 0 {
  9426. mds = append(mds, item)
  9427. }
  9428. }
  9429. }
  9430. }
  9431. //目标超滤于实际超滤不同
  9432. if pat_type == 8 {
  9433. for _, item := range monitor {
  9434. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9435. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9436. mds = append(mds, item)
  9437. }
  9438. }
  9439. }
  9440. }
  9441. //血压少于5次
  9442. if pat_type == 9 {
  9443. for _, item := range monitor {
  9444. if len(item.MonitoringRecord) < 5 {
  9445. mds = append(mds, item)
  9446. }
  9447. }
  9448. }
  9449. if pat_type == 10 {
  9450. for _, item := range monitor {
  9451. if len(item.MonitoringRecord) == 0 {
  9452. mds = append(mds, item)
  9453. }
  9454. }
  9455. }
  9456. if pat_type == 11 {
  9457. for _, item := range monitor {
  9458. if len(item.MonitoringRecord) > 0 {
  9459. mds = append(mds, item)
  9460. }
  9461. }
  9462. }
  9463. if pat_type == 12 {
  9464. for _, item := range monitor {
  9465. if len(item.MonitoringRecord) > 0 {
  9466. mds = append(mds, item)
  9467. }
  9468. }
  9469. }
  9470. if err == nil {
  9471. c.ServeSuccessJSON(map[string]interface{}{
  9472. "monitor": mds,
  9473. "patients": patients,
  9474. })
  9475. } else {
  9476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9477. }
  9478. }
  9479. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9480. admin_user_id, _ := c.GetInt64("admin_user_id")
  9481. timeStr := time.Now().Format("2006-01-02")
  9482. timeLayout := "2006-01-02 15:04:05"
  9483. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9484. timenow := timeStringToTime.Unix()
  9485. orgId := c.GetMobileAdminUserInfo().Org.Id
  9486. //查询当前护士的患者
  9487. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9488. var patientIds []int64
  9489. for _, item := range orderList {
  9490. patientIds = append(patientIds, item.PatientId)
  9491. }
  9492. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9493. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9494. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9495. //药品管理信息
  9496. _, drugStockConfig := service.FindHisConfig(orgId)
  9497. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9498. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9499. c.ServeSuccessJSON(map[string]interface{}{
  9500. "adviceList": adviceList,
  9501. "hisAdviceList": hisAdviceList,
  9502. "projectList": projectList,
  9503. "drugStockConfig": drugStockConfig,
  9504. "patientList": patientList,
  9505. "projectConfig": projectConfig,
  9506. })
  9507. }
  9508. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9509. patient_id, _ := c.GetInt64("patient_id")
  9510. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9511. c.ServeSuccessJSON(map[string]interface{}{
  9512. "recrods": recrods,
  9513. })
  9514. }
  9515. func (c *DialysisAPIController) ExMobileChangeSch() {
  9516. id_one, _ := c.GetInt64("id_one")
  9517. id_two, _ := c.GetInt64("id_two")
  9518. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9519. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9520. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9521. //if order2.ID > 0 {
  9522. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9523. // return
  9524. //}
  9525. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9526. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9527. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9528. if count > 0 {
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9530. return
  9531. }
  9532. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9533. if count1 > 0 {
  9534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9535. return
  9536. }
  9537. }
  9538. err := service.UpdateScheduleThree(sch, sch_two)
  9539. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9540. if order.ID > 0 {
  9541. //查询该患者的排班机位
  9542. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9543. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9544. redis := service.RedisClient()
  9545. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9546. redis.Set(key, "", time.Second)
  9547. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9548. //清空key 值
  9549. redis.Set(keyOne, "", time.Second)
  9550. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9551. //return
  9552. }
  9553. if err == nil {
  9554. //去除当天患者排班中重复数据,保留最后一条数据
  9555. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9556. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9557. c.ServeSuccessJSON(map[string]interface{}{
  9558. "msg": "交换成功",
  9559. })
  9560. } else {
  9561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9562. return
  9563. }
  9564. }
  9565. func (c *DialysisAPIController) MobileCoverSch() {
  9566. id_one, _ := c.GetInt64("id_one")
  9567. id_two, _ := c.GetInt64("id_two")
  9568. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9569. //针对凤凰医院
  9570. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9571. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9572. if len(advice) > 0 {
  9573. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9574. }
  9575. }
  9576. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9577. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9578. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9579. if len(hisAdvice) > 0 {
  9580. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9581. }
  9582. if len(project) > 0 {
  9583. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9584. }
  9585. }
  9586. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9587. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9588. if order.ID > 0 {
  9589. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9590. redis := service.RedisClient()
  9591. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9592. redis.Set(key, "", time.Second)
  9593. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9594. //清空key 值
  9595. redis.Set(keyOne, "", time.Second)
  9596. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9597. //return
  9598. }
  9599. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9600. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9601. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9602. if count > 0 {
  9603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9604. return
  9605. }
  9606. }
  9607. var new_sch models.Schedule
  9608. new_sch = sch
  9609. new_sch.BedId = sch_two.BedId
  9610. new_sch.ScheduleDate = sch_two.ScheduleDate
  9611. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9612. new_sch.PartitionId = sch_two.PartitionId
  9613. new_sch.ScheduleType = sch_two.ScheduleType
  9614. new_sch.ID = 0
  9615. //删除原来的排班
  9616. err := service.SaveSchTwo(sch, sch_two)
  9617. //生成新的排班
  9618. if err == nil {
  9619. err2 := service.SaveSch(&new_sch)
  9620. if err2 == nil {
  9621. //去除当天患者排班中重复数据,保留最后一条数据
  9622. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9623. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9624. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9625. c.ServeSuccessJSON(map[string]interface{}{
  9626. "msg": "覆盖成功",
  9627. "new_sch": new_sch,
  9628. })
  9629. } else {
  9630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9631. return
  9632. }
  9633. } else {
  9634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9635. return
  9636. }
  9637. }
  9638. func (c *DialysisAPIController) BatchCheckAdvice() {
  9639. patient_id, _ := c.GetInt64("patient_id")
  9640. advice_date, _ := c.GetInt64("advice_date")
  9641. org_id := c.GetMobileAdminUserInfo().Org.Id
  9642. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9643. //查询是his系统还是血透系统
  9644. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9645. //his客户
  9646. if configs.IsOpen == 1 {
  9647. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9648. for _, item := range adviceList {
  9649. service.BatchCheckHisAdvice(item.ID, creater)
  9650. }
  9651. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9652. for _, item := range projectList {
  9653. service.BatchCheckProject(item.ID, creater)
  9654. }
  9655. c.ServeSuccessJSON(map[string]interface{}{
  9656. "adviceList": adviceList,
  9657. "projectList": projectList,
  9658. })
  9659. }
  9660. if configs.IsOpen != 1 {
  9661. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9662. for _, item := range adviceList {
  9663. service.BatchAdviceList(item.ID, creater)
  9664. }
  9665. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9666. for _, item := range projectList {
  9667. service.BatchCheckProject(item.ID, creater)
  9668. }
  9669. c.ServeSuccessJSON(map[string]interface{}{
  9670. "adviceList": adviceList,
  9671. "projectList": projectList,
  9672. })
  9673. }
  9674. return
  9675. }
  9676. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9677. org_id := c.GetMobileAdminUserInfo().Org.Id
  9678. drugList, _ := service.GetAllDrugList(org_id)
  9679. c.ServeSuccessJSON(map[string]interface{}{
  9680. "drugList": drugList,
  9681. })
  9682. }
  9683. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9684. org_id := c.GetMobileAdminUserInfo().Org.Id
  9685. dataBody := make(map[string]interface{}, 0)
  9686. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9687. if err != nil {
  9688. utils.ErrorLog(err.Error())
  9689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9690. return
  9691. }
  9692. timeLayout := "2006-01-02"
  9693. loc, _ := time.LoadLocation("Local")
  9694. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9695. utils.ErrorLog("advice_type")
  9696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9697. return
  9698. }
  9699. adviceType := int64(dataBody["advice_type"].(float64))
  9700. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9701. utils.ErrorLog("start_time")
  9702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9703. return
  9704. }
  9705. startTime2, _ := dataBody["start_time"].(string)
  9706. time_arr := strings.Split(startTime2, " ")
  9707. if len(time_arr) > 0 {
  9708. startTime2 = time_arr[0]
  9709. }
  9710. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9711. utils.ErrorLog("advice_date")
  9712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9713. return
  9714. }
  9715. advice_date, _ := dataBody["advice_date"].(string)
  9716. var advicedateunix int64
  9717. if len(advice_date) > 0 {
  9718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9719. if err != nil {
  9720. fmt.Println(err)
  9721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9722. return
  9723. }
  9724. advicedateunix = theTime.Unix()
  9725. }
  9726. adviceDate := startTime2
  9727. if len(adviceDate) == 0 {
  9728. utils.ErrorLog("len(adviceDate) == 0")
  9729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9730. return
  9731. }
  9732. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9733. if err != nil {
  9734. utils.ErrorLog(err.Error())
  9735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9736. return
  9737. }
  9738. AdviceDate := advicedateunix
  9739. RecordDate := advicedateunix
  9740. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9741. utils.ErrorLog("start_time")
  9742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9743. return
  9744. }
  9745. startTime, _ := dataBody["start_time"].(string)
  9746. if len(startTime) == 0 {
  9747. utils.ErrorLog("len(start_time) == 0")
  9748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9749. return
  9750. }
  9751. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9752. if err != nil {
  9753. utils.ErrorLog(err.Error())
  9754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9755. return
  9756. }
  9757. StartTime := theTime.Unix()
  9758. advice_name, _ := dataBody["advice_name"].(string)
  9759. advice_desc, _ := dataBody["advice_desc"].(string)
  9760. delivery_way, _ := dataBody["delivery_way"].(string)
  9761. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9762. frequency_type := int64(dataBody["frequency_type"].(float64))
  9763. frequency_week, _ := dataBody["frequency_week"].(string)
  9764. prescribing_number := dataBody["prescribing_number"].(float64)
  9765. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9766. remark := dataBody["remark"].(string)
  9767. single_dose := dataBody["single_dose"].(float64)
  9768. single_dose_unit := dataBody["single_dose_unit"].(string)
  9769. patient_id := int64(dataBody["patient_id"].(float64))
  9770. day_count := int64(dataBody["day_count"].(float64))
  9771. groupNo := int64(dataBody["group_no"].(float64))
  9772. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9773. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9774. if groupNo <= 0 {
  9775. group := service.GetMaxAdviceGroupID(org_id)
  9776. groupNo = group + 1
  9777. }
  9778. var template_id = ""
  9779. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9780. template_id = "M" + adviceLastId
  9781. advice := models.DoctorAdvice{
  9782. UserOrgId: org_id,
  9783. PatientId: patient_id,
  9784. AdviceType: adviceType,
  9785. AdviceDate: AdviceDate,
  9786. StartTime: StartTime,
  9787. AdviceName: advice_name,
  9788. AdviceDesc: advice_desc,
  9789. ReminderDate: 0,
  9790. SingleDose: single_dose,
  9791. SingleDoseUnit: single_dose_unit,
  9792. DrugSpec: 0,
  9793. DrugSpecUnit: "",
  9794. PrescribingNumber: prescribing_number,
  9795. PrescribingNumberUnit: prescribing_number_unit,
  9796. DeliveryWay: delivery_way,
  9797. ExecutionFrequency: execution_frequency,
  9798. AdviceDoctor: advice_doctor,
  9799. Status: 1,
  9800. CreatedTime: time.Now().Unix(),
  9801. UpdatedTime: 0,
  9802. AdviceAffirm: "",
  9803. Remark: remark,
  9804. StopTime: 0,
  9805. StopReason: "",
  9806. StopDoctor: 0,
  9807. StopState: 0,
  9808. ParentId: 0,
  9809. ExecutionTime: 0,
  9810. ExecutionStaff: 0,
  9811. ExecutionState: 0,
  9812. Checker: 0,
  9813. RecordDate: RecordDate,
  9814. DialysisOrderId: 0,
  9815. CheckTime: 0,
  9816. CheckState: 0,
  9817. AdviceId: 0,
  9818. RemindType: 0,
  9819. FrequencyType: frequency_type,
  9820. DayCount: day_count,
  9821. WeekDay: frequency_week,
  9822. ChildDoctorAdvice: nil,
  9823. TemplateId: template_id,
  9824. Modifier: 0,
  9825. IsCheck: 0,
  9826. Way: 0,
  9827. DrugId: 0,
  9828. DrugNameId: 0,
  9829. IsMedicine: 0,
  9830. PushStartTime: 0,
  9831. IsSettle: 0,
  9832. IsPrescription: 0,
  9833. GroupNo: groupNo,
  9834. }
  9835. service.CreateMobileAdivce(advice)
  9836. c.ServeSuccessJSON(map[string]interface{}{
  9837. "msg": "保存成功!",
  9838. })
  9839. }
  9840. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9841. patient_id, _ := c.GetInt64("patient_id")
  9842. org_id := c.GetMobileAdminUserInfo().Org.Id
  9843. app_id := c.GetMobileAdminUserInfo().App.Id
  9844. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9845. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9846. c.ServeSuccessJSON(map[string]interface{}{
  9847. "adviceList": adviceList,
  9848. "adminRoles": adminRoles,
  9849. })
  9850. }
  9851. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9852. org_id := c.GetMobileAdminUserInfo().Org.Id
  9853. dataBody := make(map[string]interface{}, 0)
  9854. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9855. if err != nil {
  9856. utils.ErrorLog(err.Error())
  9857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9858. return
  9859. }
  9860. timeLayout := "2006-01-02"
  9861. loc, _ := time.LoadLocation("Local")
  9862. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9863. utils.ErrorLog("start_time")
  9864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9865. return
  9866. }
  9867. startTime2, _ := dataBody["start_time"].(string)
  9868. time_arr := strings.Split(startTime2, " ")
  9869. if len(time_arr) > 0 {
  9870. startTime2 = time_arr[0]
  9871. }
  9872. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9873. utils.ErrorLog("advice_date")
  9874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9875. return
  9876. }
  9877. advice_date, _ := dataBody["advice_date"].(string)
  9878. var advicedateunix int64
  9879. if len(advice_date) > 0 {
  9880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9881. if err != nil {
  9882. fmt.Println(err)
  9883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9884. return
  9885. }
  9886. advicedateunix = theTime.Unix()
  9887. }
  9888. adviceDate := startTime2
  9889. if len(adviceDate) == 0 {
  9890. utils.ErrorLog("len(adviceDate) == 0")
  9891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9892. return
  9893. }
  9894. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9895. if err != nil {
  9896. utils.ErrorLog(err.Error())
  9897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9898. return
  9899. }
  9900. AdviceDate := advicedateunix
  9901. RecordDate := advicedateunix
  9902. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9903. utils.ErrorLog("start_time")
  9904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9905. return
  9906. }
  9907. startTime, _ := dataBody["start_time"].(string)
  9908. if len(startTime) == 0 {
  9909. utils.ErrorLog("len(start_time) == 0")
  9910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9911. return
  9912. }
  9913. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9914. if err != nil {
  9915. utils.ErrorLog(err.Error())
  9916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9917. return
  9918. }
  9919. StartTime := theTime.Unix()
  9920. advice_name, _ := dataBody["advice_name"].(string)
  9921. advice_desc, _ := dataBody["advice_desc"].(string)
  9922. delivery_way, _ := dataBody["delivery_way"].(string)
  9923. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9924. prescribing_number := dataBody["prescribing_number"].(float64)
  9925. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9926. remark := dataBody["remark"].(string)
  9927. single_dose := dataBody["single_dose"].(float64)
  9928. single_dose_unit := dataBody["single_dose_unit"].(string)
  9929. patient_id := int64(dataBody["patient_id"].(float64))
  9930. groupNo := int64(dataBody["group_no"].(float64))
  9931. parent_id := int64(dataBody["parent_id"].(float64))
  9932. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9933. advice := models.XtDoctorAdviceOne{
  9934. UserOrgId: org_id,
  9935. PatientId: patient_id,
  9936. AdviceType: 1,
  9937. AdviceDate: AdviceDate,
  9938. StartTime: StartTime,
  9939. AdviceName: advice_name,
  9940. AdviceDesc: advice_desc,
  9941. ReminderDate: 0,
  9942. SingleDose: single_dose,
  9943. SingleDoseUnit: single_dose_unit,
  9944. PrescribingNumber: prescribing_number,
  9945. PrescribingNumberUnit: prescribing_number_unit,
  9946. DeliveryWay: delivery_way,
  9947. ExecutionFrequency: execution_frequency,
  9948. AdviceDoctor: advice_doctor,
  9949. Status: 1,
  9950. CreatedTime: time.Now().Unix(),
  9951. UpdatedTime: time.Now().Unix(),
  9952. AdviceAffirm: "",
  9953. Remark: remark,
  9954. StopTime: 0,
  9955. StopReason: "",
  9956. StopDoctor: 0,
  9957. StopState: 0,
  9958. ParentId: parent_id,
  9959. ExecutionTime: 0,
  9960. ExecutionStaff: 0,
  9961. ExecutionState: 0,
  9962. Checker: 0,
  9963. RecordDate: RecordDate,
  9964. DialysisOrderId: 0,
  9965. CheckTime: 0,
  9966. CheckState: 0,
  9967. DrugSpec: 0,
  9968. DrugSpecUnit: "",
  9969. Groupno: groupNo,
  9970. RemindType: 0,
  9971. FrequencyType: 0,
  9972. DayCount: 0,
  9973. WeekDay: "",
  9974. TemplateId: "",
  9975. Modifier: 0,
  9976. }
  9977. service.CreateMobileAdivceOne(advice)
  9978. c.ServeSuccessJSON(map[string]interface{}{
  9979. "msg": "保存成功!",
  9980. })
  9981. }
  9982. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9983. id, _ := c.GetInt64("id")
  9984. service.DeleteSelfAdviceSubAdvice(id)
  9985. c.ServeSuccessJSON(map[string]interface{}{
  9986. "msg": "保存成功!",
  9987. })
  9988. }
  9989. func (c *DialysisAPIController) GetEditAdviceAction() {
  9990. id, _ := c.GetInt64("id")
  9991. org_id := c.GetMobileAdminUserInfo().Org.Id
  9992. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9993. drugList, _ := service.GetAllDrugList(org_id)
  9994. c.ServeSuccessJSON(map[string]interface{}{
  9995. "advice": advice,
  9996. "drugList": drugList,
  9997. })
  9998. }
  9999. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10000. dataBody := make(map[string]interface{}, 0)
  10001. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10002. if err != nil {
  10003. utils.ErrorLog(err.Error())
  10004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10005. return
  10006. }
  10007. timeLayout := "2006-01-02"
  10008. loc, _ := time.LoadLocation("Local")
  10009. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10010. utils.ErrorLog("start_time")
  10011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10012. return
  10013. }
  10014. startTime2, _ := dataBody["start_time"].(string)
  10015. time_arr := strings.Split(startTime2, " ")
  10016. if len(time_arr) > 0 {
  10017. startTime2 = time_arr[0]
  10018. }
  10019. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10020. utils.ErrorLog("advice_date")
  10021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10022. return
  10023. }
  10024. advice_date, _ := dataBody["advice_date"].(string)
  10025. var advicedateunix int64
  10026. if len(advice_date) > 0 {
  10027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10028. if err != nil {
  10029. fmt.Println(err)
  10030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10031. return
  10032. }
  10033. advicedateunix = theTime.Unix()
  10034. }
  10035. adviceDate := startTime2
  10036. if len(adviceDate) == 0 {
  10037. utils.ErrorLog("len(adviceDate) == 0")
  10038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10039. return
  10040. }
  10041. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10042. if err != nil {
  10043. utils.ErrorLog(err.Error())
  10044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10045. return
  10046. }
  10047. AdviceDate := advicedateunix
  10048. RecordDate := advicedateunix
  10049. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10050. utils.ErrorLog("start_time")
  10051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10052. return
  10053. }
  10054. startTime, _ := dataBody["start_time"].(string)
  10055. if len(startTime) == 0 {
  10056. utils.ErrorLog("len(start_time) == 0")
  10057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10058. return
  10059. }
  10060. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10061. if err != nil {
  10062. utils.ErrorLog(err.Error())
  10063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10064. return
  10065. }
  10066. StartTime := theTime.Unix()
  10067. advice_name, _ := dataBody["advice_name"].(string)
  10068. advice_desc, _ := dataBody["advice_desc"].(string)
  10069. delivery_way, _ := dataBody["delivery_way"].(string)
  10070. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10071. prescribing_number := dataBody["prescribing_number"].(float64)
  10072. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10073. remark := dataBody["remark"].(string)
  10074. single_dose := dataBody["single_dose"].(float64)
  10075. single_dose_unit := dataBody["single_dose_unit"].(string)
  10076. id := int64(dataBody["id"].(float64))
  10077. frequency_type := int64(dataBody["frequency_type"].(float64))
  10078. frequency_week, _ := dataBody["frequency_week"].(string)
  10079. day_count := int64(dataBody["day_count"].(float64))
  10080. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10081. advice := models.XtDoctorAdviceOne{
  10082. AdviceDate: AdviceDate,
  10083. StartTime: StartTime,
  10084. AdviceName: advice_name,
  10085. AdviceDesc: advice_desc,
  10086. SingleDose: single_dose,
  10087. SingleDoseUnit: single_dose_unit,
  10088. PrescribingNumber: prescribing_number,
  10089. PrescribingNumberUnit: prescribing_number_unit,
  10090. DeliveryWay: delivery_way,
  10091. ExecutionFrequency: execution_frequency,
  10092. AdviceDoctor: advice_doctor,
  10093. Remark: remark,
  10094. RecordDate: RecordDate,
  10095. FrequencyType: frequency_type,
  10096. DayCount: day_count,
  10097. WeekDay: frequency_week,
  10098. }
  10099. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10100. c.ServeSuccessJSON(map[string]interface{}{
  10101. "advice": advice,
  10102. })
  10103. }
  10104. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10105. dataBody := make(map[string]interface{}, 0)
  10106. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10107. if err != nil {
  10108. utils.ErrorLog(err.Error())
  10109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10110. return
  10111. }
  10112. timeLayout := "2006-01-02"
  10113. loc, _ := time.LoadLocation("Local")
  10114. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10115. utils.ErrorLog("start_time")
  10116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10117. return
  10118. }
  10119. startTime2, _ := dataBody["start_time"].(string)
  10120. time_arr := strings.Split(startTime2, " ")
  10121. if len(time_arr) > 0 {
  10122. startTime2 = time_arr[0]
  10123. }
  10124. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10125. utils.ErrorLog("advice_date")
  10126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10127. return
  10128. }
  10129. advice_date, _ := dataBody["advice_date"].(string)
  10130. var advicedateunix int64
  10131. if len(advice_date) > 0 {
  10132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10133. if err != nil {
  10134. fmt.Println(err)
  10135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10136. return
  10137. }
  10138. advicedateunix = theTime.Unix()
  10139. }
  10140. adviceDate := startTime2
  10141. if len(adviceDate) == 0 {
  10142. utils.ErrorLog("len(adviceDate) == 0")
  10143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10144. return
  10145. }
  10146. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10147. if err != nil {
  10148. utils.ErrorLog(err.Error())
  10149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10150. return
  10151. }
  10152. AdviceDate := advicedateunix
  10153. RecordDate := advicedateunix
  10154. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10155. utils.ErrorLog("start_time")
  10156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10157. return
  10158. }
  10159. startTime, _ := dataBody["start_time"].(string)
  10160. if len(startTime) == 0 {
  10161. utils.ErrorLog("len(start_time) == 0")
  10162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10163. return
  10164. }
  10165. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10166. if err != nil {
  10167. utils.ErrorLog(err.Error())
  10168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10169. return
  10170. }
  10171. StartTime := theTime.Unix()
  10172. advice_name, _ := dataBody["advice_name"].(string)
  10173. advice_desc, _ := dataBody["advice_desc"].(string)
  10174. delivery_way, _ := dataBody["delivery_way"].(string)
  10175. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10176. prescribing_number := dataBody["prescribing_number"].(float64)
  10177. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10178. remark := dataBody["remark"].(string)
  10179. single_dose := dataBody["single_dose"].(float64)
  10180. single_dose_unit := dataBody["single_dose_unit"].(string)
  10181. id := int64(dataBody["id"].(float64))
  10182. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10183. advice := models.XtDoctorAdviceOne{
  10184. AdviceDate: AdviceDate,
  10185. StartTime: StartTime,
  10186. AdviceName: advice_name,
  10187. AdviceDesc: advice_desc,
  10188. SingleDose: single_dose,
  10189. SingleDoseUnit: single_dose_unit,
  10190. PrescribingNumber: prescribing_number,
  10191. PrescribingNumberUnit: prescribing_number_unit,
  10192. DeliveryWay: delivery_way,
  10193. ExecutionFrequency: execution_frequency,
  10194. AdviceDoctor: advice_doctor,
  10195. Remark: remark,
  10196. RecordDate: RecordDate,
  10197. }
  10198. service.UpdateMobileDoctorAdviceById(id, advice)
  10199. c.ServeSuccessJSON(map[string]interface{}{
  10200. "advice": advice,
  10201. })
  10202. }
  10203. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10204. dataBody := make(map[string]interface{}, 0)
  10205. timeLayout := "2006-01-02"
  10206. loc, _ := time.LoadLocation("Local")
  10207. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10208. if err != nil {
  10209. utils.ErrorLog(err.Error())
  10210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10211. return
  10212. }
  10213. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10214. utils.ErrorLog("start_time")
  10215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10216. return
  10217. }
  10218. startTime2, _ := dataBody["start_time"].(string)
  10219. time_arr := strings.Split(startTime2, " ")
  10220. if len(time_arr) > 0 {
  10221. startTime2 = time_arr[0]
  10222. }
  10223. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10224. utils.ErrorLog("advice_date")
  10225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10226. return
  10227. }
  10228. advice_date, _ := dataBody["advice_date"].(string)
  10229. var advicedateunix int64
  10230. if len(advice_date) > 0 {
  10231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10232. if err != nil {
  10233. fmt.Println(err)
  10234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10235. return
  10236. }
  10237. advicedateunix = theTime.Unix()
  10238. }
  10239. adviceDate := startTime2
  10240. if len(adviceDate) == 0 {
  10241. utils.ErrorLog("len(adviceDate) == 0")
  10242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10243. return
  10244. }
  10245. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10246. if err != nil {
  10247. utils.ErrorLog(err.Error())
  10248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10249. return
  10250. }
  10251. RecordDate := advicedateunix
  10252. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10253. utils.ErrorLog("start_time")
  10254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10255. return
  10256. }
  10257. startTime, _ := dataBody["start_time"].(string)
  10258. if len(startTime) == 0 {
  10259. utils.ErrorLog("len(start_time) == 0")
  10260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10261. return
  10262. }
  10263. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10264. if err != nil {
  10265. utils.ErrorLog(err.Error())
  10266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10267. return
  10268. }
  10269. StartTime := theTime.Unix()
  10270. patient_id := int64(dataBody["patient_id"].(float64))
  10271. group_no := int64(dataBody["group_no"].(float64))
  10272. org_id := c.GetMobileAdminUserInfo().Org.Id
  10273. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10274. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10275. utils.ErrorLog("advices")
  10276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10277. return
  10278. }
  10279. adviceNames := dataBody["advices"].([]interface{})
  10280. var advices []*models.GroupAdvice
  10281. for _, adviceNameMap := range adviceNames {
  10282. var advice models.GroupAdvice
  10283. adviceNameM := adviceNameMap.(map[string]interface{})
  10284. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10285. utils.ErrorLog("advice_name")
  10286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10287. return
  10288. }
  10289. adviceName, _ := adviceNameM["advice_name"].(string)
  10290. if len(adviceName) == 0 {
  10291. utils.ErrorLog("len(advice_name) == 0")
  10292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10293. return
  10294. }
  10295. advice.AdviceName = adviceName
  10296. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10297. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10298. advice.DrugSpec = drugSpec
  10299. }
  10300. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10301. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10302. advice.AdviceDesc = adviceDesc
  10303. }
  10304. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10305. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10306. advice.DrugSpecUnit = drugSpecUnit
  10307. }
  10308. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10309. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10310. advice.SingleDose = singleDose
  10311. }
  10312. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10313. singleDose := adviceNameM["single_dose"].(float64)
  10314. advice.SingleDose = singleDose
  10315. }
  10316. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10317. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10318. advice.SingleDoseUnit = singleDoseUnit
  10319. }
  10320. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10321. tmp := adviceNameM["single_dose_unit"].(float64)
  10322. singleDoseUnit := service.TypeConversion(tmp)
  10323. advice.SingleDoseUnit = singleDoseUnit
  10324. }
  10325. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10326. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10327. advice.PrescribingNumber = prescribingNumber
  10328. }
  10329. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10330. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10331. advice.PrescribingNumber = prescribingNumber
  10332. }
  10333. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10334. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10335. advice.PrescribingNumberUnit = prescribingNumberUnit
  10336. }
  10337. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10338. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10339. advice.DeliveryWay = deliveryWay
  10340. }
  10341. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10342. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10343. advice.ExecutionFrequency = executionFrequency
  10344. }
  10345. remark, _ := adviceNameM["remark"].(string)
  10346. advice.Remark = remark
  10347. advice.AdviceType = 1
  10348. advice.StartTime = StartTime
  10349. advice.RecordDate = RecordDate
  10350. advice.PatientId = patient_id
  10351. advice.UserOrgId = org_id
  10352. advice.AdviceDoctor = advice_doctor
  10353. advices = append(advices, &advice)
  10354. }
  10355. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10356. c.ServeSuccessJSON(map[string]interface{}{
  10357. "advice": newAdvices,
  10358. })
  10359. }