dialysis_api_controller.go 428KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036
  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. fmt.Print("projectOne------------------------", projectsOne)
  468. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  469. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  470. var team_projects []*models.HisPrescriptionProject
  471. //var index int64 = 0
  472. for _, item := range temp_team_projects {
  473. //组套里面非检验项目的
  474. if item.HisProject.CostClassify != 3 {
  475. projects = append(projects, item)
  476. }
  477. //组套里面检验项目的
  478. if item.HisProject.CostClassify == 3 {
  479. team_projects = append(team_projects, item)
  480. }
  481. }
  482. //针对茂名舒和
  483. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  484. if len(projects) > 0 {
  485. for _, item := range projects {
  486. if item.Type == 2 {
  487. if item.HisProject.IsShow == 1 {
  488. projectsOne = append(projectsOne, item)
  489. }
  490. }
  491. if item.Type == 3 {
  492. if item.GoodInfo.IsShow == 1 {
  493. projectsOne = append(projectsOne, item)
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. for _, item := range projects {
  500. projectsOne = append(projectsOne, item)
  501. }
  502. }
  503. team_projects = RemoveRepeatedCheckRecod(team_projects)
  504. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  505. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  506. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  507. var his_advices []*models.HisDoctorAdviceInfo
  508. var his_advices_one []*models.HisDoctorAdviceInfo
  509. if is_open_config.IsOpen == 1 {
  510. // 先走redis,没有走数据库
  511. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  512. }
  513. //针对茂名舒和
  514. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  515. if len(his_advices) > 0 {
  516. for _, item := range his_advices {
  517. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  518. if drug.IsShow == 1 {
  519. his_advices_one = append(his_advices_one, item)
  520. }
  521. }
  522. }
  523. } else {
  524. if len(his_advices) > 0 {
  525. for _, item := range his_advices {
  526. his_advices_one = append(his_advices_one, item)
  527. }
  528. }
  529. }
  530. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  531. if is_advice_open.IsAdviceOpen == 1 {
  532. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  533. }
  534. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  535. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  536. var remind_lists []models.XtCheckRemind
  537. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  538. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  539. }
  540. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  541. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  542. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  543. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  544. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  545. returnData := map[string]interface{}{
  546. "patient": patient,
  547. "schedual": schedual,
  548. "prescription": dialysisPrescribe,
  549. "solution": dialysisSolution,
  550. "last_prescription": lastDialysisPrescribe,
  551. "receiver_treatment_access": receiverTreatmentAccess,
  552. "predialysis_evaluation": predialysisEvaluation,
  553. "doctor_advices": doctorAdvices,
  554. "double_check": doubleCheck,
  555. "assessment_after_dislysis": assessmentAfterDislysis,
  556. "treatment_summary": treatmentSummary,
  557. "monitor_records": monitorRecords,
  558. "dialysis_order": dialysisOrder,
  559. "operators": operators,
  560. "last_predialysis_evaluation": lastPredialysisEvaluation,
  561. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  562. "last_monitor_record": lastMonitorRecord,
  563. "config": gobalConfig,
  564. "dry_weight": lastDryWeightDislysis,
  565. "system_prescription": systemDialysisPrescribe,
  566. "his_advices": his_advices_one,
  567. "is_open_config": is_open_config,
  568. "stockType": stockType,
  569. "prepare": prepare,
  570. "lastAssessment": lastAssessment,
  571. "prescribeOne": prescribeOne,
  572. "is_project_open_config": is_project_open_config,
  573. "project": projectsOne,
  574. "team_projects": team_projects,
  575. "is_advice_open": is_advice_open,
  576. "prescription_open": prescriptionConfig.IsOpen,
  577. "lastOrder": lastOrder,
  578. "remind_lists": remind_lists,
  579. "lastDialysisPrescription": lastDialysisPrescription,
  580. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  581. "dryWeightList": dryWeightList,
  582. "firstMonitor": firstMonitor,
  583. "lastMonitor": lastMonitor,
  584. }
  585. this.ServeSuccessJSON(returnData)
  586. }
  587. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  588. adminInfo := c.GetMobileAdminUserInfo()
  589. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  590. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  591. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  592. returnData := map[string]interface{}{
  593. "admin_users": adminUsers,
  594. "devices": devices,
  595. "device_numbers": device_numbers,
  596. }
  597. c.ServeSuccessJSON(returnData)
  598. }
  599. func (c *DialysisAPIController) PostAtreatmentInfo() {
  600. id, _ := c.GetInt64("patient", 0)
  601. recordDateStr := c.GetString("record_date")
  602. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  603. summaryContent := c.GetString("summaryContent")
  604. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  605. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  606. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  607. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  608. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  609. nursingRecord := c.GetString("nursing_record")
  610. fmt.Println("护理记录", nursingRecord)
  611. specialRecord := c.GetString("special_record")
  612. fmt.Println("特殊记录", specialRecord)
  613. adminUserInfo := c.GetMobileAdminUserInfo()
  614. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  615. checkStaffId = adminUserInfo.AdminUser.Id
  616. deboardNurseId = adminUserInfo.AdminUser.Id
  617. treatDoctor = adminUserInfo.AdminUser.Id
  618. if id <= 0 {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  623. if patient.ID == 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  625. return
  626. }
  627. if len(recordDateStr) == 0 {
  628. recordDateStr = time.Now().Format("2006-01-02")
  629. }
  630. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  631. if parseDateErr != nil {
  632. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. summary := models.TreatmentSummary{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. PatientId: id,
  639. AssessmentDate: recordDate.Unix(),
  640. Mission: propagandaAndEducationContent,
  641. DialysisSummary: summaryContent,
  642. SjNurse: changeMedicalNurseId,
  643. ZlNurse: treatNurseId,
  644. HdNurse: checkStaffId,
  645. XjNurse: deboardNurseId,
  646. ZlDoctor: treatDoctor,
  647. CreatedTime: time.Now().Unix(),
  648. Status: 1,
  649. NursingRecord: nursingRecord,
  650. SpecialRecord: specialRecord,
  651. }
  652. // 查询信息规挡的设置天数
  653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  654. if infor.ID > 0 && infor.WeekDay > 0 {
  655. var cha_time int64
  656. timeNowStr := time.Now().Format("2006-01-02")
  657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  658. //今日的日期减去设置的日期
  659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  660. if cha_time >= recordDate.Unix() {
  661. //查询审核是否允许
  662. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  663. //申请状态不允许的情况 拒绝修改
  664. if infor.ApplicationStatus != 1 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  666. return
  667. }
  668. }
  669. }
  670. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  671. if treatmentSummary.ID == 0 { //新增
  672. summary.Creater = adminUserInfo.AdminUser.Id
  673. service.AddSigleSummaryRecord(&summary)
  674. finish := models.XtDialysisFinish{
  675. IsFinish: 1,
  676. UserOrgId: adminUserInfo.Org.Id,
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. Module: 10,
  681. RecordDate: recordDate.Unix(),
  682. Sourse: 1,
  683. PatientId: id,
  684. }
  685. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  686. if dialysisFinish.ID == 0 {
  687. service.CreateDialysisFinish(finish)
  688. }
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  694. redis.Set(keyOne, "", time.Second)
  695. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  696. redis.Set(keyThree, "", time.Second)
  697. defer redis.Close()
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "summary": summary,
  700. })
  701. } else { //修改
  702. summary.Creater = treatmentSummary.Creater
  703. summary.CreatedTime = treatmentSummary.CreatedTime
  704. summary.Modifier = adminUserInfo.AdminUser.Id
  705. summary.ID = treatmentSummary.ID
  706. service.UpdateSummeRecord(&summary)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  708. redis := service.RedisClient()
  709. //清空key 值
  710. redis.Set(key, "", time.Second)
  711. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  712. redis.Set(keyOne, "", time.Second)
  713. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  714. redis.Set(keyThree, "", time.Second)
  715. defer redis.Close()
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "summary": summary,
  718. })
  719. }
  720. }
  721. func (c *DialysisAPIController) PostDoubleCheck() {
  722. id, _ := c.GetInt64("patient", 0)
  723. recordDateStr := c.GetString("record_date")
  724. checkTimeStr := c.GetString("check_time")
  725. firstCheckTimeStr := c.GetString("first_check_time")
  726. creater, _ := c.GetInt64("creater", 0)
  727. modifier, _ := c.GetInt64("modifier", 0)
  728. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  729. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  730. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  731. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  732. dialysis_item_desc := c.GetString("dialysis_item_desc")
  733. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  734. vascular_access_desc := c.GetString("vascular_access_desc")
  735. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  736. collator, _ := c.GetInt64("collator", 0)
  737. employee_number := c.GetString("employee_number")
  738. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  739. needle_batch_number := c.GetString("needle_batch_number")
  740. if id <= 0 {
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := c.GetMobileAdminUserInfo()
  745. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  746. if patient.ID == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. if len(recordDateStr) == 0 {
  751. recordDateStr = time.Now().Format("2006-01-02")
  752. }
  753. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  754. if parseDateErr != nil {
  755. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. var checkDate int64
  760. if len(checkTimeStr) == 0 {
  761. checkDate = 0
  762. } else {
  763. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  764. checkDate = checkDateUnix.Unix()
  765. }
  766. var firstCheckDate int64
  767. if len(firstCheckTimeStr) == 0 {
  768. firstCheckDate = 0
  769. } else {
  770. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  771. firstCheckDate = firstCheckDateUnix.Unix()
  772. }
  773. if adminUserInfo.Org.Id == 10644 {
  774. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  775. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  776. if check.ID == 0 {
  777. if employee_number != list.JobNumber {
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "doubleCheck": check,
  780. "msg": "2",
  781. })
  782. return
  783. }
  784. }
  785. if check.ID > 0 {
  786. if employee_number != list.JobNumber {
  787. c.ServeSuccessJSON(map[string]interface{}{
  788. "doubleCheck": check,
  789. "msg": "2",
  790. })
  791. return
  792. }
  793. }
  794. }
  795. doubleCheck := models.DoubleCheck{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. DialysisItemCheck: dialysis_item_check,
  799. DialysisParameterCheck: dialysis_parameter_check,
  800. VascularAccessVerification: vascular_access_verification,
  801. PipelineConnectionCheck: pipeline_connection_check,
  802. DialysisItemDesc: dialysis_item_desc,
  803. DialysisParameterDesc: dialysis_parameter_desc,
  804. VascularAccessDesc: vascular_access_desc,
  805. PipelineConnectionDesc: pipeline_connection_desc,
  806. Collator: collator,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. CheckDate: recordDate.Unix(),
  810. UpdatedTime: time.Now().Unix(),
  811. EmployeeNumber: employee_number,
  812. DialyzerBatchNumber: dialyzer_batch_number,
  813. NeedleBatchNumber: needle_batch_number,
  814. }
  815. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. if check.ID == 0 { //新增
  817. doubleCheck.FirstCheckTime = firstCheckDate
  818. doubleCheck.CheckTime = checkDate
  819. doubleCheck.Creater = creater
  820. doubleCheck.Modifier = modifier
  821. if adminUserInfo.Org.Id == 10340 {
  822. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  823. doubleCheck.Creater = order.StartNurse
  824. }
  825. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  826. //查询未核对的医嘱
  827. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  828. for _, advice := range doctorList {
  829. if advice.ExecutionStaff == modifier {
  830. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  832. return
  833. }
  834. }
  835. }
  836. // 查询信息规挡的设置天数
  837. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  838. if infor.ID > 0 && infor.WeekDay > 0 {
  839. var cha_time int64
  840. timeNowStr := time.Now().Format("2006-01-02")
  841. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  842. //今日的日期减去设置的日期
  843. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  844. if cha_time >= recordDate.Unix() {
  845. //查询审核是否允许
  846. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  847. //申请状态不允许的情况 拒绝修改
  848. if infor.ApplicationStatus != 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  850. return
  851. }
  852. }
  853. }
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. finish := models.XtDialysisFinish{
  856. IsFinish: 1,
  857. UserOrgId: adminUserInfo.Org.Id,
  858. Status: 1,
  859. Ctime: time.Now().Unix(),
  860. Mtime: 0,
  861. Module: 5,
  862. RecordDate: recordDate.Unix(),
  863. Sourse: 1,
  864. PatientId: id,
  865. }
  866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  867. if dialysisFinish.ID == 0 {
  868. service.CreateDialysisFinish(finish)
  869. }
  870. //针对长沙南雅
  871. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  872. //查询未核对的医嘱
  873. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  874. if len(doctorList) > 0 && modifier > 0 {
  875. for _, advice := range doctorList {
  876. service.UpdateDoctorAdviceList(advice.ID, modifier)
  877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  878. redis := service.RedisClient()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. theTime := time.Now()
  884. recordDate := theTime.Format("2006-01-02")
  885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  886. redis.Set(keyFour, "", time.Second)
  887. defer redis.Close()
  888. }
  889. }
  890. }
  891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. redis := service.RedisClient()
  893. //清空key 值
  894. redis.Set(key, "", time.Second)
  895. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  896. redis.Set(keyOne, "", time.Second)
  897. defer redis.Close()
  898. if err == nil {
  899. c.ServeSuccessJSON(map[string]interface{}{
  900. "doubleCheck": &doubleCheck,
  901. })
  902. }
  903. } else { //修改
  904. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  905. if infor.ID > 0 {
  906. var cha_time int64
  907. timeNowStr := time.Now().Format("2006-01-02")
  908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  909. //今日的日期减去设置的日期
  910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  911. if cha_time >= recordDate.Unix() {
  912. //查询审核是否允许
  913. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  914. //申请状态不允许的情况 拒绝修改
  915. if infor.ApplicationStatus != 1 {
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  917. return
  918. }
  919. }
  920. }
  921. doubleCheck.FirstCheckTime = firstCheckDate
  922. doubleCheck.CheckTime = checkDate
  923. doubleCheck.Creater = creater
  924. doubleCheck.Modifier = modifier
  925. doubleCheck.CreatedTime = check.CreatedTime
  926. doubleCheck.ID = check.ID
  927. doubleCheck.EmployeeNumber = employee_number
  928. doubleCheck.NeedleBatchNumber = needle_batch_number
  929. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  930. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  931. //查询未核对的医嘱
  932. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  933. for _, advice := range doctorList {
  934. if advice.ExecutionStaff == modifier {
  935. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  936. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  937. return
  938. }
  939. }
  940. }
  941. err := service.UpdateDoubleCheck(&doubleCheck)
  942. //针对长沙南雅
  943. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  944. //查询未核对的医嘱
  945. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  946. if len(doctorList) > 0 && modifier > 0 {
  947. for _, advice := range doctorList {
  948. service.UpdateDoctorAdviceList(advice.ID, modifier)
  949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  950. redis := service.RedisClient()
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  954. redis.Set(keyTwo, "", time.Second)
  955. theTime := time.Now()
  956. recordDate := theTime.Format("2006-01-02")
  957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  958. redis.Set(keyFour, "", time.Second)
  959. defer redis.Close()
  960. }
  961. }
  962. }
  963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  964. redis := service.RedisClient()
  965. //清空key 值
  966. redis.Set(key, "", time.Second)
  967. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  968. redis.Set(keyOne, "", time.Second)
  969. defer redis.Close()
  970. if err == nil {
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "doubleCheck": &doubleCheck,
  973. "msg": "1",
  974. })
  975. }
  976. }
  977. }
  978. func (c *DialysisAPIController) PostAcceptsAssessment() {
  979. id, _ := c.GetInt64("patient", 0)
  980. recordDateStr := c.GetString("record_date")
  981. way, _ := c.GetInt64("way", 0)
  982. consciousness, _ := c.GetInt64("consciousness", 0)
  983. appetite, _ := c.GetInt64("appetite", 0)
  984. condition, _ := c.GetInt64("condition", 0)
  985. posture, _ := c.GetInt64("posture")
  986. sick_condition, _ := c.GetInt64("sick_condition", 0)
  987. danger_level, _ := c.GetInt64("danger_level", 0)
  988. intake, _ := c.GetInt64("intake", 0)
  989. nutrition, _ := c.GetInt64("nutrition", 0)
  990. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  991. psychological_assessment_other := c.GetString("psychological_assessment_other")
  992. score := c.GetString("score")
  993. sick_condition_other := c.GetString("sick_condition_other")
  994. //precaution, _ := c.GetInt64("precaution", 0)
  995. precaution := c.GetString("precaution")
  996. precaution_other := c.GetString("precaution_other")
  997. psychological_other := c.GetString("psychological_other")
  998. admission_number := c.GetString("admission_number")
  999. tumble, _ := c.GetInt64("tumble")
  1000. diacrisis := c.GetString("diacrisis")
  1001. his_department := c.GetString("his_department")
  1002. his_bed := c.GetString("his_bed")
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. //now := time.Now()
  1014. //year, month, day := now.Date()
  1015. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1016. //todayTimeStamp := today_time.Unix()
  1017. if len(recordDateStr) == 0 {
  1018. recordDateStr = time.Now().Format("2006-01-02")
  1019. }
  1020. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1021. if parseDateErr != nil {
  1022. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. // 查询信息规挡的设置天数
  1027. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1028. if infor.ID > 0 && infor.WeekDay > 0 {
  1029. var cha_time int64
  1030. timeNowStr := time.Now().Format("2006-01-02")
  1031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1032. //今日的日期减去设置的日期
  1033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1034. if cha_time >= recordDate.Unix() {
  1035. //查询审核是否允许
  1036. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1037. //申请状态不允许的情况 拒绝修改
  1038. if infor.ApplicationStatus != 1 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1040. return
  1041. }
  1042. }
  1043. }
  1044. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1045. if adminUserInfo.Org.Id == 10340 {
  1046. if condition == 1 {
  1047. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1048. if admission_number == "" {
  1049. admission_number = lastAcceptTreatment.AdmissionNumber
  1050. }
  1051. }
  1052. }
  1053. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1054. UserOrgId: adminUserInfo.Org.Id,
  1055. PatientId: id,
  1056. RecordDate: recordDate.Unix(),
  1057. Way: way,
  1058. Consciousness: consciousness,
  1059. Appetite: appetite,
  1060. Condition: condition,
  1061. SickCondition: sick_condition,
  1062. DangerLevel: danger_level,
  1063. Intake: intake,
  1064. Nutrition: nutrition,
  1065. PsychologicalAssessment: psychological_assessment,
  1066. PsychologicalAssessmentOther: psychological_assessment_other,
  1067. SickConditionOther: sick_condition_other,
  1068. Posture: posture,
  1069. CreatedTime: time.Now().Unix(),
  1070. UpdateTime: time.Now().Unix(),
  1071. Status: 1,
  1072. Score: score,
  1073. Precaution: precaution,
  1074. PrecautionOther: precaution_other,
  1075. PsychologicalOther: psychological_other,
  1076. AdmissionNumber: admission_number,
  1077. Tumble: tumble,
  1078. Diacrisis: diacrisis,
  1079. HisBed: his_bed,
  1080. HisDepartment: his_department,
  1081. }
  1082. if receiveTreatment.ID == 0 { //新增
  1083. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1084. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1085. finish := models.XtDialysisFinish{
  1086. IsFinish: 1,
  1087. UserOrgId: adminUserInfo.Org.Id,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: 0,
  1091. Module: 2,
  1092. RecordDate: recordDate.Unix(),
  1093. Sourse: 1,
  1094. PatientId: id,
  1095. }
  1096. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1097. if dialysisFinish.ID == 0 {
  1098. service.CreateDialysisFinish(finish)
  1099. }
  1100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1101. redis := service.RedisClient()
  1102. defer redis.Close()
  1103. //清空key 值
  1104. redis.Set(key, "", time.Second)
  1105. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1106. redis.Set(keyOne, "", time.Second)
  1107. if err == nil {
  1108. c.ServeSuccessJSON(map[string]interface{}{
  1109. "receiveTreatmentAsses": receiveTreatmentAsses,
  1110. })
  1111. }
  1112. } else { //修改
  1113. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. //}
  1123. // 查询信息规挡的设置天数
  1124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1125. if infor.ID > 0 && infor.WeekDay > 0 {
  1126. var cha_time int64
  1127. timeNowStr := time.Now().Format("2006-01-02")
  1128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1129. //今日的日期减去设置的日期
  1130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1131. if cha_time >= recordDate.Unix() {
  1132. //查询审核是否允许
  1133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1134. //申请状态不允许的情况 拒绝修改
  1135. if infor.ApplicationStatus != 1 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1137. return
  1138. }
  1139. }
  1140. }
  1141. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1142. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1143. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1144. receiveTreatmentAsses.ID = receiveTreatment.ID
  1145. if adminUserInfo.Org.Id == 10340 {
  1146. if condition == 1 {
  1147. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1148. if receiveTreatmentAsses.AdmissionNumber == "" {
  1149. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1150. }
  1151. }
  1152. }
  1153. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1155. redis := service.RedisClient()
  1156. defer redis.Close()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1160. redis.Set(keyOne, "", time.Second)
  1161. if err == nil {
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "receiveTreatmentAsses": receiveTreatmentAsses,
  1164. })
  1165. }
  1166. }
  1167. }
  1168. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1169. id, _ := c.GetInt64("patient", 0)
  1170. recordDateStr := c.GetString("record_date")
  1171. weightAfter, _ := c.GetFloat("weight_after", 0)
  1172. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1173. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1174. fmt.Println("weight_loss", weightReduce)
  1175. temperature, _ := c.GetFloat("temperature", 0)
  1176. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1177. breathing_rate := c.GetString("breathing_rate")
  1178. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1179. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1180. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1181. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1182. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1183. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1184. cruor := c.GetString("cruor")
  1185. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1186. internalFistula := c.GetString("internal_fistula")
  1187. catheter := c.GetString("catheter")
  1188. complications := c.GetString("complication")
  1189. remark := c.GetString("remark")
  1190. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1191. dialysis_intakes := c.GetString("dialysis_intakes")
  1192. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1193. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1194. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1195. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1196. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1197. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1198. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1199. patientGose, _ := c.GetInt64("patient_gose", 0)
  1200. inpatientDepartment := c.GetString("inpatient_department")
  1201. observationContent := c.GetString("observation_content")
  1202. observationContentOther := c.GetString("observation_content_other")
  1203. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1204. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1205. in_advance_reason := c.GetString("in_advance_reason")
  1206. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1207. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1208. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1209. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1210. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1211. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1212. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1213. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1214. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1215. is_eat, _ := c.GetInt64("is_eat", 0)
  1216. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1217. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1218. channels, _ := c.GetInt64("channel", 0)
  1219. return_blood, _ := c.GetInt64("return_blood", 0)
  1220. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1221. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1222. dialysis_during, _ := c.GetFloat("dialysis_during")
  1223. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1224. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1225. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1226. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1227. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1228. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1229. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1230. setting_pressure := c.GetString("setting_pressure")
  1231. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1232. diastolic_pressure := c.GetString("diastolic_pressure")
  1233. other_complication := c.GetString("other_complication")
  1234. ktv := c.GetString("ktv")
  1235. urr := c.GetString("urr")
  1236. hypertenison, _ := c.GetInt64("hypertenison")
  1237. hypopiesia, _ := c.GetInt64("hypopiesia")
  1238. leave_office_method, _ := c.GetInt64("leave_office_method")
  1239. lapse, _ := c.GetInt64("lapse")
  1240. consciousness, _ := c.GetInt64("consciousness")
  1241. fallrisk, _ := c.GetInt64("fallrisk")
  1242. machine_run := c.GetString("machine_run")
  1243. after_urea := c.GetString("after_urea")
  1244. pip_coagulation := c.GetString("pip_coagulation")
  1245. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1246. transfusion_volume := c.GetString("transfusion_volume")
  1247. last_after_weight := c.GetString("last_after_weight")
  1248. displace_liqui_value := c.GetString("displace_liqui_value")
  1249. if id <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetMobileAdminUserInfo()
  1254. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1255. if patient.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. if len(recordDateStr) == 0 {
  1260. recordDateStr = time.Now().Format("2006-01-02")
  1261. }
  1262. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1263. fmt.Println("parseDateErr", parseDateErr)
  1264. if parseDateErr != nil {
  1265. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. //now := time.Now()
  1270. //year, month, day := now.Date()
  1271. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1272. //todayTimeStamp := today_time.Unix()
  1273. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1274. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. AssessmentDate: recordDate.Unix(),
  1278. Temperature: temperature,
  1279. PulseFrequency: pulse_frequency,
  1280. BreathingRate: breathing_rate,
  1281. SystolicBloodPressure: systolic_blood_pressure,
  1282. DiastolicBloodPressure: diastolic_blood_pressure,
  1283. ActualUltrafiltration: actual_ultrafiltration,
  1284. ActualDisplacement: actual_displacement,
  1285. ActualTreatmentHour: actualtreatHour,
  1286. ActualTreatmentMinute: actualtreatmin,
  1287. WeightAfter: weightAfter,
  1288. AdditionalWeight: additionalWeight,
  1289. WeightLoss: weightReduce,
  1290. Cruor: cruor,
  1291. SymptomAfterDialysis: symptomsAfterDialysi,
  1292. InternalFistula: internalFistula,
  1293. Catheter: catheter,
  1294. Complication: complications,
  1295. DialysisIntakes: dialysateVolume,
  1296. CreatedTime: time.Now().Unix(),
  1297. UpdatedTime: time.Now().Unix(),
  1298. Status: 1,
  1299. Remark: remark,
  1300. BloodAccessPartId: blood_access_part_id,
  1301. BloodAccessPartOperaId: blood_access_part_opera_id,
  1302. DialysisIntakesUnit: dialysis_intakes_unit,
  1303. PuncturePointOozingBlood: puncturePointOozingBlood,
  1304. PuncturePointHaematoma: puncturePointHaematoma,
  1305. InternalFistulaTremorAc: internalFistulaTremorAc,
  1306. PatientGose: patientGose,
  1307. InpatientDepartment: inpatientDepartment,
  1308. ObservationContent: observationContent,
  1309. ObservationContentOther: observationContentOther,
  1310. DialysisProcess: dialysis_process,
  1311. InAdvanceMinute: in_advance_minute,
  1312. InAdvanceReason: in_advance_reason,
  1313. HemostasisMinute: hemostasis_minute,
  1314. HemostasisOpera: hemostasis_opera,
  1315. TremorNoise: tremor_noise,
  1316. DisequilibriumSyndrome: disequilibrium_syndrome,
  1317. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1318. ArterialTube: arterial_tube,
  1319. IntravenousTube: intravenous_tube,
  1320. Dialyzer: dialyzer,
  1321. InAdvanceReasonOther: in_advance_reason_other,
  1322. IsEat: is_eat,
  1323. CvcA: cvc_a,
  1324. CvcV: cvc_v,
  1325. Channel: channels,
  1326. ReturnBlood: return_blood,
  1327. RehydrationVolume: rehydration_volume,
  1328. DialysisDuring: dialysis_during,
  1329. StrokeVolume: stroke_volume,
  1330. BloodFlow: blood_flow,
  1331. SealingFluidDispose: sealing_fluid_dispose,
  1332. SealingFluidSpecial: sealing_fluid_special,
  1333. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1334. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1335. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1336. SettingPressure: setting_pressure,
  1337. DiastolicPressure: diastolic_pressure,
  1338. OtherComplication: other_complication,
  1339. Ktv: ktv,
  1340. Urr: urr,
  1341. Hypopiesia: hypopiesia,
  1342. Hypertenison: hypertenison,
  1343. Lapse: lapse,
  1344. LeaveOfficeMethod: leave_office_method,
  1345. Consciousness: consciousness,
  1346. Fallrisk: fallrisk,
  1347. MachineRun: machine_run,
  1348. AfterUrea: after_urea,
  1349. PipCoagulation: pip_coagulation,
  1350. AccumulatedBloodVolume: accumulated_blood_volume,
  1351. TransfusionVolume: transfusion_volume,
  1352. LastAfterWeight: last_after_weight,
  1353. DisplaceLiquiValue: displace_liqui_value,
  1354. }
  1355. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1356. // 查询信息规挡的设置天数
  1357. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1358. if infor.ID > 0 && infor.WeekDay > 0 {
  1359. var cha_time int64
  1360. timeNowStr := time.Now().Format("2006-01-02")
  1361. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1362. //今日的日期减去设置的日期
  1363. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1364. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1365. if cha_time >= recordDate.Unix() {
  1366. //查询审核是否允许
  1367. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1368. //申请状态不允许的情况 拒绝修改
  1369. if infor.ApplicationStatus != 1 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1371. return
  1372. }
  1373. }
  1374. }
  1375. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1376. if assessmentAfter.ID == 0 { //新增
  1377. if appRole.UserType == 2 || appRole.UserType == 1 {
  1378. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1379. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1380. } else {
  1381. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1382. }
  1383. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1384. if assessmentAfterDislysis.UserOrgId != 10340 {
  1385. if assessmentAfterDislysis.WeightAfter == 0 {
  1386. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1387. }
  1388. }
  1389. if adminUserInfo.Org.Id == 10693 {
  1390. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1393. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1394. }
  1395. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1398. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1399. }
  1400. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1401. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1402. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1403. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1404. }
  1405. if assessmentAfterDislysis.PulseFrequency == 0 {
  1406. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1407. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1408. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1409. }
  1410. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1411. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1412. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1413. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1414. }
  1415. }
  1416. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1417. //记录日志
  1418. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1419. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1420. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1421. PatientId: assessmentAfterDislysis.PatientId,
  1422. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1423. Status: 1,
  1424. ErrLog: string(byterequest),
  1425. AdminUserId: adminUserInfo.AdminUser.Id,
  1426. Ctime: 0,
  1427. Mtime: 0,
  1428. Source: "手机端保存透后评估",
  1429. }
  1430. service.CreateAfterDialysisLog(afterDialysisLog)
  1431. finish := models.XtDialysisFinish{
  1432. IsFinish: 1,
  1433. UserOrgId: adminUserInfo.Org.Id,
  1434. Status: 1,
  1435. Ctime: time.Now().Unix(),
  1436. Mtime: 0,
  1437. Module: 9,
  1438. RecordDate: recordDate.Unix(),
  1439. Sourse: 1,
  1440. PatientId: id,
  1441. }
  1442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1443. if dialysisFinish.ID == 0 {
  1444. service.CreateDialysisFinish(finish)
  1445. }
  1446. redis := service.RedisClient()
  1447. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1448. redis.Set(keyTwo, "", time.Second)
  1449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1450. //清空key 值
  1451. redis.Set(key, "", time.Second)
  1452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1453. redis.Set(keyOne, "", time.Second)
  1454. defer redis.Close()
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "assessmentAfterDislysis": assessmentAfterDislysis,
  1458. })
  1459. }
  1460. return
  1461. } else { //修改
  1462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1463. if infor.ID > 0 && infor.WeekDay > 0 {
  1464. var cha_time int64
  1465. timeNowStr := time.Now().Format("2006-01-02")
  1466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1467. //今日的日期减去设置的日期
  1468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1469. if cha_time >= recordDate.Unix() {
  1470. //查询审核是否允许
  1471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1472. //申请状态不允许的情况 拒绝修改
  1473. if infor.ApplicationStatus != 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1475. return
  1476. }
  1477. }
  1478. }
  1479. if appRole.UserType == 2 || appRole.UserType == 1 {
  1480. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1481. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1482. } else {
  1483. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1484. if assessmentAfterDislysis.Creater == 0 {
  1485. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1486. }
  1487. }
  1488. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1489. assessmentAfterDislysis.ID = assessmentAfter.ID
  1490. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1491. if assessmentAfterDislysis.UserOrgId != 10340 {
  1492. if assessmentAfterDislysis.WeightAfter == 0 {
  1493. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1494. }
  1495. }
  1496. if adminUserInfo.Org.Id == 10693 {
  1497. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1498. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1499. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1500. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1501. }
  1502. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1503. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1504. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1505. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1506. }
  1507. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1508. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1509. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1510. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1511. }
  1512. if assessmentAfterDislysis.PulseFrequency == 0 {
  1513. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1514. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1515. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1516. }
  1517. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1518. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1519. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1520. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1521. }
  1522. }
  1523. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1526. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1527. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1528. PatientId: assessmentAfterDislysis.PatientId,
  1529. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1530. Status: 1,
  1531. ErrLog: string(byterequest),
  1532. AdminUserId: adminUserInfo.AdminUser.Id,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "手机端修改保存透后评估",
  1536. }
  1537. service.CreateAfterDialysisLog(afterDialysisLog)
  1538. redis := service.RedisClient()
  1539. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1540. redis.Set(keyTwo, "", time.Second)
  1541. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err == nil {
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "assessmentAfterDislysis": assessmentAfterDislysis,
  1549. })
  1550. return
  1551. }
  1552. }
  1553. return
  1554. }
  1555. func (c *DialysisAPIController) PostDialysisPrescription() {
  1556. id, _ := c.GetInt64("patient", 0)
  1557. recordDateStr := c.GetString("record_date")
  1558. if id <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetMobileAdminUserInfo()
  1563. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1564. if patient.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. if len(recordDateStr) == 0 {
  1569. recordDateStr = time.Now().Format("2006-01-02")
  1570. }
  1571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1572. if parseDateErr != nil {
  1573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. mode_id, _ := c.GetInt64("mode_id", 0)
  1578. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1579. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1580. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1581. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1582. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1583. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1584. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1585. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1586. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1587. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1588. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1589. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1590. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1591. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1592. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1593. kalium, _ := c.GetFloat("kalium", 0)
  1594. sodium, _ := c.GetFloat("sodium", 0)
  1595. calcium, _ := c.GetFloat("calcium", 0)
  1596. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1597. glucose, _ := c.GetFloat("glucose", 0)
  1598. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1599. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1600. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1601. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1602. conductivity, _ := c.GetFloat("conductivity", 0)
  1603. remark := c.GetString("remark")
  1604. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1605. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1606. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1607. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1608. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1609. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1610. special_medicine_other := c.GetString("special_medicine_other")
  1611. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1612. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1613. blood_access, _ := c.GetInt64("blood_access", 0)
  1614. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1615. body_fluid_other := c.GetString("body_fluid_other")
  1616. niprocart, _ := c.GetInt64("niprocart", 0)
  1617. jms, _ := c.GetInt64("jms", 0)
  1618. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1619. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1620. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1621. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1622. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1623. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1624. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1625. injector, _ := c.GetInt64("injector", 0)
  1626. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1627. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1628. safe_package, _ := c.GetInt64("package", 0)
  1629. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1630. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1631. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1632. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1633. blood := c.GetString("blood")
  1634. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1635. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1636. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1637. displace_speed := c.GetString("displace_speed")
  1638. illness, _ := c.GetInt64("illness")
  1639. amylaceum := c.GetString("amylaceum")
  1640. single_time := c.GetString("single_time")
  1641. single_water := c.GetString("single_water")
  1642. replacement_flow := c.GetString("replacement_flow")
  1643. plasma_separator := c.GetString("plasma_separator")
  1644. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1645. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1646. oxygen_flow := c.GetString("oxygen_flow")
  1647. oxygen_time := c.GetString("oxygen_time")
  1648. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1649. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1650. puncture_needle := c.GetString("puncture_needle")
  1651. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1652. epo := c.GetString("epo")
  1653. epo_count, _ := c.GetFloat("epo_count", 0)
  1654. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1655. admin_user_id, _ := c.GetInt64("admin_user_id")
  1656. is_water := c.GetString("is_water")
  1657. var is_war int64
  1658. if is_water == "是" {
  1659. is_war = 1
  1660. }
  1661. if is_water == "否" {
  1662. is_war = 2
  1663. }
  1664. if is_water == "请选择" {
  1665. is_war = 0
  1666. }
  1667. drhy_water := c.GetString("drhy_water")
  1668. dry_water_hour := c.GetString("dry_water_hour")
  1669. water_machine := c.GetString("water_machine")
  1670. add_amount, _ := c.GetFloat("add_amount")
  1671. reduce_amount, _ := c.GetFloat("reduce_amount")
  1672. dialysis_remark := c.GetString("dialysis_remark")
  1673. prescribing_number, _ := c.GetFloat("prescribing_number")
  1674. prescription_sodium := c.GetString("prescription_sodium")
  1675. start_sodium := c.GetString("start_sodium")
  1676. sodium_curve := c.GetString("sodium_curve")
  1677. treatment_remark := c.GetString("treatment_remark")
  1678. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1679. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1680. prescription_water, _ := c.GetFloat("prescription_water")
  1681. dialysis_strainer := c.GetString("dialysis_strainer")
  1682. chaptalization := c.GetString("chaptalization")
  1683. washing_time := c.GetString("washing_time")
  1684. warsh_count := c.GetString("warsh_count")
  1685. blood_access_part_id := c.GetString("blood_access_part_id")
  1686. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1687. dialyzate := c.GetString("dialyzate")
  1688. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1690. //
  1691. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1692. // if appRole.UserType == 3 {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. // }
  1702. //}
  1703. // 查询信息规挡的设置天数
  1704. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1705. if infor.ID > 0 && infor.WeekDay > 0 {
  1706. var cha_time int64
  1707. timeNowStr := time.Now().Format("2006-01-02")
  1708. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1709. //今日的日期减去设置的日期
  1710. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1711. if cha_time >= recordDate.Unix() {
  1712. //查询审核是否允许
  1713. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1714. //申请状态不允许的情况 拒绝修改
  1715. if infor.ApplicationStatus != 1 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1717. return
  1718. }
  1719. }
  1720. }
  1721. if mode_id > 0 {
  1722. var str string
  1723. //查找该机构用的是什么透析器
  1724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1725. if filedConfig.ID > 0 {
  1726. str = dialyzerPerfusionApparatus
  1727. } else {
  1728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1729. }
  1730. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1731. }
  1732. //TODO 需要根据角色去判断
  1733. prescription := models.DialysisPrescription{
  1734. UserOrgId: adminUserInfo.Org.Id,
  1735. PatientId: id,
  1736. RecordDate: recordDate.Unix(),
  1737. ModeId: mode_id,
  1738. DialysisDuration: dialysis_duration,
  1739. Dialyzer: dialyzer,
  1740. PerfusionApparatus: perfusion_apparatus,
  1741. BloodFlowVolume: blood_flow_volume,
  1742. DewaterAmount: dewater_amount,
  1743. DisplaceLiqui: displace_liqui,
  1744. ReplacementWay: replacement_way,
  1745. Anticoagulant: anticoagulant,
  1746. AnticoagulantShouji: anticoagulant_shouji,
  1747. AnticoagulantWeichi: anticoagulant_weichi,
  1748. AnticoagulantZongliang: anticoagulant_zongliang,
  1749. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1750. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1751. Kalium: kalium,
  1752. Sodium: sodium,
  1753. Calcium: calcium,
  1754. Bicarbonate: bicarbonate,
  1755. Glucose: glucose,
  1756. // DryWeight: dry_weight,
  1757. DialysateFlow: dialysate_flow,
  1758. DialysateTemperature: dialysate_temperature,
  1759. // PrescriptionDoctor: prescription_doctor,
  1760. ReplacementTotal: replacement_total,
  1761. Conductivity: conductivity,
  1762. Remark: remark,
  1763. Status: 1,
  1764. CreatedTime: time.Now().Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. DialysisDurationMinute: dialysisDurationMinute,
  1767. DialysisDurationHour: dialysisDurationHour,
  1768. TargetUltrafiltration: targetUltrafiltration,
  1769. DialysateFormulation: dialysateFormulation,
  1770. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1771. BodyFluid: body_fluid,
  1772. SpecialMedicine: special_medicine,
  1773. SpecialMedicineOther: special_medicine_other,
  1774. DisplaceLiquiPart: displace_liqui_part,
  1775. DisplaceLiquiValue: displace_liqui_value,
  1776. BloodAccess: blood_access,
  1777. Ultrafiltration: ultrafiltration,
  1778. BodyFluidOther: body_fluid_other,
  1779. Niprocart: niprocart,
  1780. Jms: jms,
  1781. FistulaNeedleSet: fistula_needle_set,
  1782. FistulaNeedleSet16: fistula_needle_set_16,
  1783. Hemoperfusion: hemoperfusion,
  1784. DialyserSterilised: dialyser_sterilised,
  1785. Filtryzer: filtryzer,
  1786. Dialyzers: dialyzers,
  1787. Injector: injector,
  1788. Bloodlines: bloodlines,
  1789. TubingHemodialysis: tubing_hemodialysis,
  1790. Package: safe_package,
  1791. ALiquid: a_liquid,
  1792. TargetKtv: target_ktv,
  1793. PreImpulse: pre_impulse,
  1794. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1795. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1796. Blood: blood,
  1797. DialysisDialyszers: dialysis_dialyszers,
  1798. DialysisIrrigation: dialysis_irrigation,
  1799. AntioxidantCommodityName: antioxidant_commodity_name,
  1800. DisplaceSpeed: displace_speed,
  1801. Illness: illness,
  1802. Amylaceum: amylaceum,
  1803. SingleTime: single_time,
  1804. SingleWater: single_water,
  1805. ReplacementFlow: replacement_flow,
  1806. PlasmaSeparator: plasma_separator,
  1807. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1808. OxygenUptake: oxygen_uptake,
  1809. OxygenFlow: oxygen_flow,
  1810. OxygenTime: oxygen_time,
  1811. HemodialysisPipelines: hemodialysis_pipelines,
  1812. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1813. PunctureNeedle: puncture_needle,
  1814. PunctureNeedleCount: puncture_needle_count,
  1815. Epo: epo,
  1816. EpoCount: epo_count,
  1817. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1818. AdminUserId: admin_user_id,
  1819. IsWater: is_war,
  1820. DrhyWater: drhy_water,
  1821. DryWaterHour: dry_water_hour,
  1822. WaterMachine: water_machine,
  1823. AddAmount: add_amount,
  1824. ReduceAmount: reduce_amount,
  1825. DialysisRemark: dialysis_remark,
  1826. PrescribingNumber: prescribing_number,
  1827. StartSodium: start_sodium,
  1828. SodiumCurve: sodium_curve,
  1829. TreatmentRemark: treatment_remark,
  1830. PrescriptionSodium: prescription_sodium,
  1831. DialysisFluidFlow: dialysis_fluid_flow,
  1832. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1833. PrescriptionWater: prescription_water,
  1834. DialysisStrainer: dialysis_strainer,
  1835. Chaptalization: chaptalization,
  1836. WashingTime: washing_time,
  1837. WarshCount: warsh_count,
  1838. BloodAccessPartId: blood_access_part_id,
  1839. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1840. Dialyzate: dialyzate,
  1841. }
  1842. //查询最近透析准备表里是否存在 透析器 灌流器
  1843. //
  1844. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1845. //
  1846. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1847. //
  1848. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1849. //if len(mation)>0{
  1850. // for _, item := range splitStr {
  1851. // for _,it := range mation{
  1852. // if(item == it.SpecificationName){
  1853. //
  1854. // //查询最近一次的透析器
  1855. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1856. //
  1857. // if errcode == gorm.ErrRecordNotFound{
  1858. // //插入数据
  1859. // prepare := models.DialysisBeforePrepare{
  1860. // UserOrgId: adminUserInfo.Org.Id,
  1861. // PatientId: id,
  1862. // RecordDate: recordDate.Unix(),
  1863. // GoodTypeId: it.GoodTypeId,
  1864. // GoodId: it.ID,
  1865. // Count: 1,
  1866. // Ctime: time.Now().Unix(),
  1867. // Creater: adminUserInfo.AdminUser.Id,
  1868. // Status:1,
  1869. //
  1870. // }
  1871. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1872. // fmt.Println("",errcode)
  1873. // }
  1874. // }
  1875. // }
  1876. //
  1877. // }
  1878. //
  1879. // for _, item := range splitIrrigation {
  1880. // for _,it := range mation{
  1881. // if(item == it.SpecificationName){
  1882. // //查询最近一次的透析器
  1883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1884. // if errcode == gorm.ErrRecordNotFound{
  1885. // //插入数据
  1886. // prepare := models.DialysisBeforePrepare{
  1887. // UserOrgId: adminUserInfo.Org.Id,
  1888. // PatientId: id,
  1889. // RecordDate: recordDate.Unix(),
  1890. // GoodTypeId: it.GoodTypeId,
  1891. // GoodId: it.ID,
  1892. // Count: 1,
  1893. // Ctime: time.Now().Unix(),
  1894. // Creater: adminUserInfo.AdminUser.Id,
  1895. // Status:1,
  1896. //
  1897. // }
  1898. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1899. // fmt.Println(errcode)
  1900. // }
  1901. // }
  1902. // }
  1903. // }
  1904. //}
  1905. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1906. if dialysisPrescription.ID == 0 { //新增
  1907. if appRole.UserType == 2 || appRole.UserType == 1 {
  1908. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1909. }
  1910. prescription.Creater = adminUserInfo.AdminUser.Id
  1911. //针对河间咸得
  1912. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1913. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1914. prescription.DisplaceLiquiPart = 0
  1915. prescription.DisplaceLiquiValue = 0
  1916. }
  1917. }
  1918. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1919. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1920. }
  1921. err := service.AddSigleRecord(&prescription)
  1922. //记录日志
  1923. byterequest, _ := json.Marshal(prescription)
  1924. prescriptionLog := models.XtDialysisPrescriptionLog{
  1925. UserOrgId: prescription.UserOrgId,
  1926. Ctime: time.Now().Unix(),
  1927. Mtime: 0,
  1928. ErrLog: string(byterequest),
  1929. AdminUserId: adminUserInfo.AdminUser.Id,
  1930. RecordDate: prescription.RecordDate,
  1931. PatientId: prescription.PatientId,
  1932. Source: "手机端新增保存处方",
  1933. Status: 1,
  1934. }
  1935. service.CreatePrescriptionLog(prescriptionLog)
  1936. finish := models.XtDialysisFinish{
  1937. IsFinish: 1,
  1938. UserOrgId: adminUserInfo.Org.Id,
  1939. Status: 1,
  1940. Ctime: time.Now().Unix(),
  1941. Mtime: 0,
  1942. Module: 1,
  1943. RecordDate: recordDate.Unix(),
  1944. Sourse: 1,
  1945. PatientId: id,
  1946. }
  1947. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1948. if dialysisFinish.ID == 0 {
  1949. service.CreateDialysisFinish(finish)
  1950. }
  1951. //长沙南雅医院,自动生成抗凝剂的临时处方
  1952. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1953. if prescribing_number == 0 {
  1954. prescribing_number = 1
  1955. }
  1956. if prescribing_number == 0 && id == 14682 {
  1957. prescribing_number = 2
  1958. }
  1959. if prescribing_number == 0 && id == 18560 {
  1960. prescribing_number = 2
  1961. }
  1962. advice := models.DoctorAdvice{
  1963. UserOrgId: adminUserInfo.Org.Id,
  1964. PatientId: id,
  1965. GroupNo: 0,
  1966. AdviceType: 2,
  1967. RecordDate: recordDate.Unix(),
  1968. AdviceDate: recordDate.Unix(),
  1969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1971. AdviceDesc: "",
  1972. ReminderDate: 0,
  1973. SingleDose: anticoagulant_zongliang,
  1974. SingleDoseUnit: "iu",
  1975. DrugSpec: 0,
  1976. DrugSpecUnit: "",
  1977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1978. PrescribingNumberUnit: "支",
  1979. DeliveryWay: "静脉注射",
  1980. ExecutionFrequency: "上机前",
  1981. AdviceDoctor: 0,
  1982. Status: 1,
  1983. CreatedTime: time.Now().Unix(),
  1984. UpdatedTime: time.Now().Unix(),
  1985. IsPrescription: 1,
  1986. ExecutionState: 2,
  1987. StopState: 2,
  1988. IsSettle: 2,
  1989. }
  1990. // 查询排班信息
  1991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. if schedulePatient.ID > 0 {
  1993. if schedulePatient.ScheduleType == 1 {
  1994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1995. }
  1996. if schedulePatient.ScheduleType == 2 {
  1997. advice.StartTime = recordDate.Unix() + 9*60*60
  1998. }
  1999. }
  2000. // 抗凝剂名称
  2001. switch anticoagulant {
  2002. case 1:
  2003. advice.AdviceName = "无肝素"
  2004. break
  2005. case 2:
  2006. advice.AdviceName = "普通肝素"
  2007. break
  2008. case 3:
  2009. advice.AdviceName = "低分子肝素"
  2010. break
  2011. case 4:
  2012. advice.AdviceName = "阿加曲班"
  2013. break
  2014. case 5:
  2015. advice.AdviceName = "枸橼酸钠"
  2016. break
  2017. case 6:
  2018. advice.AdviceName = "低分子肝素钙"
  2019. break
  2020. case 7:
  2021. advice.AdviceName = "低分子肝素钠"
  2022. break
  2023. case 8:
  2024. advice.AdviceName = "依诺肝素"
  2025. break
  2026. case 9:
  2027. advice.AdviceName = "达肝素"
  2028. break
  2029. case 10:
  2030. advice.AdviceName = "体外抗凝"
  2031. break
  2032. case 11:
  2033. advice.AdviceName = "那曲肝素"
  2034. break
  2035. case 12:
  2036. advice.AdviceName = "无抗凝剂"
  2037. break
  2038. }
  2039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2041. advice.AdviceDoctor = appRole.AdminUserId
  2042. }
  2043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2046. advice.AdviceName = "低分子肝素钠注射液"
  2047. // 修改患者临时医嘱里的抗凝剂医嘱
  2048. advice.ID = advicePrescription.ID
  2049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. } else {
  2051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2052. advice.AdviceName = "低分子肝素钠注射液"
  2053. // 新增患者临时医嘱里的抗凝剂医嘱
  2054. service.CreateDoctorAdvice(&advice)
  2055. }
  2056. }
  2057. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2058. redis := service.RedisClient()
  2059. defer redis.Close()
  2060. //清空key 值
  2061. redis.Set(key, "", time.Second)
  2062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2063. redis.Set(keyOne, "", time.Second)
  2064. }
  2065. //获取key,清空redis
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2067. redis := service.RedisClient()
  2068. //清空key 值
  2069. redis.Set(key, "", time.Second)
  2070. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2071. //清空key 值
  2072. redis.Set(keyOne, "", time.Second)
  2073. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2074. //清空key 值
  2075. redis.Set(keyTwo, "", time.Second)
  2076. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2077. redis.Set(keySix, "", time.Second)
  2078. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2079. redis.Set(keySeven, "", time.Second)
  2080. if err == nil {
  2081. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2082. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2083. //清空key 值
  2084. redis.Set(keyThree, "", time.Second)
  2085. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2086. //清空key 值
  2087. redis.Set(keyFour, "", time.Second)
  2088. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2089. redis.Set(keyFive, "", time.Second)
  2090. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2091. redis.Set(keySix, "", time.Second)
  2092. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2093. redis.Set(keySeven, "", time.Second)
  2094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. if updateErr != nil {
  2098. utils.ErrorLog("%v", updateErr)
  2099. }
  2100. defer redis.Close()
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "prescription": prescription,
  2103. })
  2104. }
  2105. } else { //修改
  2106. //if mode_id > 0 {
  2107. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2108. //}
  2109. //if template.TemplateId == 1 {
  2110. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. // }
  2120. //}
  2121. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2122. prescription.Modifier = adminUserInfo.AdminUser.Id
  2123. if appRole.UserType == 2 || appRole.UserType == 1 {
  2124. prescription_doctor := adminUserInfo.AdminUser.Id
  2125. prescription.PrescriptionDoctor = prescription_doctor
  2126. } else {
  2127. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2128. }
  2129. if dialysisPrescription.Creater == 0 { //体重称
  2130. prescription.Creater = adminUserInfo.AdminUser.Id
  2131. } else {
  2132. prescription.Creater = dialysisPrescription.Creater
  2133. if adminUserInfo.Org.Id == 9882 {
  2134. if appRole.UserType == 2 || appRole.UserType == 1 {
  2135. prescription_doctor := adminUserInfo.AdminUser.Id
  2136. prescription.PrescriptionDoctor = prescription_doctor
  2137. prescription.Creater = prescription_doctor
  2138. }
  2139. }
  2140. }
  2141. prescription.ID = dialysisPrescription.ID
  2142. service.UpDateDialysisPrescription(&prescription)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(prescription)
  2145. prescriptionLog := models.XtDialysisPrescriptionLog{
  2146. UserOrgId: prescription.UserOrgId,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. ErrLog: string(byterequest),
  2150. AdminUserId: adminUserInfo.AdminUser.Id,
  2151. RecordDate: prescription.RecordDate,
  2152. PatientId: prescription.PatientId,
  2153. Source: "手机端修改处方",
  2154. Status: 1,
  2155. }
  2156. service.CreatePrescriptionLog(prescriptionLog)
  2157. finish := models.XtDialysisFinish{
  2158. IsFinish: 1,
  2159. UserOrgId: adminUserInfo.Org.Id,
  2160. Status: 1,
  2161. Ctime: time.Now().Unix(),
  2162. Mtime: 0,
  2163. Module: 1,
  2164. RecordDate: recordDate.Unix(),
  2165. Sourse: 1,
  2166. PatientId: id,
  2167. }
  2168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2169. if dialysisFinish.ID == 0 {
  2170. service.CreateDialysisFinish(finish)
  2171. }
  2172. //修改处方
  2173. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2174. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2175. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. if advicePrescription.ID > 0 {
  2177. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2179. redis := service.RedisClient()
  2180. defer redis.Close()
  2181. //清空key 值
  2182. redis.Set(key, "", time.Second)
  2183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2184. redis.Set(keyOne, "", time.Second)
  2185. }
  2186. }
  2187. //获取key,清空redis
  2188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis := service.RedisClient()
  2190. //清空key 值
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2193. //清空key 值
  2194. redis.Set(keyOne, "", time.Second)
  2195. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2196. redis.Set(keySix, "", time.Second)
  2197. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2198. redis.Set(keySeven, "", time.Second)
  2199. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2200. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyTwoOne, "", time.Second)
  2203. defer redis.Close()
  2204. if updateErr != nil {
  2205. utils.ErrorLog("%v", updateErr)
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "prescription": prescription,
  2209. })
  2210. }
  2211. }
  2212. func (c *DialysisAPIController) Finish() {
  2213. id, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. nurseID, _ := c.GetInt64("nurse")
  2216. end_time := c.GetString("end_time")
  2217. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2218. internal_fistula := c.GetString("blood_access_internal_fistula")
  2219. catheter := c.GetString("catheter")
  2220. cruor := c.GetString("cruor")
  2221. mission := c.GetString("mission")
  2222. condenser := c.GetString("condenser")
  2223. if id <= 0 || nurseID <= 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adminUserInfo := c.GetMobileAdminUserInfo()
  2228. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2229. if patient.ID == 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2231. return
  2232. }
  2233. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2234. if getNurseErr != nil {
  2235. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. } else if nurse == nil {
  2239. c.ErrorLog("护士不存在")
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2241. return
  2242. }
  2243. if len(recordDateStr) == 0 {
  2244. recordDateStr = time.Now().Format("2006-01-02")
  2245. }
  2246. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2247. if parseDateErr != nil {
  2248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2253. if parseEndDateErr != nil {
  2254. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. // 查询信息规挡的设置天数
  2259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2260. if infor.ID > 0 && infor.WeekDay > 0 {
  2261. var cha_time int64
  2262. timeNowStr := time.Now().Format("2006-01-02")
  2263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2264. //今日的日期减去设置的日期
  2265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2266. if cha_time >= recordDate.Unix() {
  2267. //查询审核是否允许
  2268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2269. //申请状态不允许的情况 拒绝修改
  2270. if infor.ApplicationStatus != 1 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2272. return
  2273. }
  2274. }
  2275. }
  2276. //now := time.Now()
  2277. //year, month, day := now.Date()
  2278. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2279. //todayTimeStamp := today_time.Unix()
  2280. // 获取当天的第一条透析纪录
  2281. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2282. if getMonitorRecordsErr != nil {
  2283. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2285. return
  2286. }
  2287. // 获取当前的最后一条透析纪录
  2288. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. if getMonitorRecordsErr != nil {
  2290. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2292. return
  2293. }
  2294. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2295. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2296. if getAADErr != nil {
  2297. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2304. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2305. if assessmentAfterDislysis != nil {
  2306. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2307. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2308. } else {
  2309. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2310. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2311. tempassessmentAfterDislysis.Status = 1
  2312. tempassessmentAfterDislysis.PatientId = id
  2313. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2314. }
  2315. //长沙南雅
  2316. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2317. //获取最后一条透析处方数据
  2318. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2320. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2321. }
  2322. if dialysisOrder.Stage == 1 {
  2323. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2324. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2325. fmt.Println(value)
  2326. a, b := math.Modf(value)
  2327. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2328. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2329. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2330. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2331. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2332. }
  2333. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2334. //var num1 int64
  2335. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2336. //fmt.Println(num1)
  2337. //sub := float64(num1 / 3600)
  2338. //fmt.Println(sub)
  2339. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2340. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2341. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. if adminUserInfo.Org.Id != 10375 {
  2346. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2347. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2348. }
  2349. if adminUserInfo.Org.Id != 10445 {
  2350. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2351. }
  2352. //北方营口医院
  2353. if adminUserInfo.Org.Id == 10445 {
  2354. //获取最后一条透析处方数据
  2355. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2356. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2357. } else {
  2358. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2359. }
  2360. //新化博翔
  2361. if adminUserInfo.Org.Id == 10447 {
  2362. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2363. }
  2364. //阳春
  2365. if adminUserInfo.Org.Id == 10485 {
  2366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2367. }
  2368. if adminUserInfo.Org.Id == 10551 {
  2369. //获取最后一条透析处方数据
  2370. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2371. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2372. }
  2373. if adminUserInfo.Org.Id == 10580 {
  2374. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2375. }
  2376. if adminUserInfo.Org.Id == 10612 {
  2377. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2378. }
  2379. //孝康
  2380. if adminUserInfo.Org.Id == 10693 {
  2381. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2382. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2383. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2384. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2385. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2386. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2387. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2388. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2389. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2390. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2391. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2392. }
  2393. if adminUserInfo.Org.Id == 10697 {
  2394. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2395. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2396. lastWeightAfter.LastAfterWeight = floatAfeter
  2397. }
  2398. }
  2399. 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 {
  2400. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2401. if evaluation.SystolicBloodPressure == 0 {
  2402. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2403. if adminUserInfo.Org.Id == 10693 {
  2404. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2405. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2406. }
  2407. pre := models.PredialysisEvaluation{
  2408. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2409. }
  2410. fmt.Println("prew", pre)
  2411. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2412. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2414. redis := service.RedisClient()
  2415. redis.Set(key, "", time.Second)
  2416. redis.Set(keyOne, "", time.Second)
  2417. defer redis.Close()
  2418. fmt.Println(getNurseErr)
  2419. }
  2420. if evaluation.DiastolicBloodPressure == 0 {
  2421. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2422. if adminUserInfo.Org.Id == 10693 {
  2423. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2424. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2425. }
  2426. pres := models.PredialysisEvaluation{
  2427. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2428. }
  2429. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2431. redis := service.RedisClient()
  2432. redis.Set(key, "", time.Second)
  2433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2434. redis.Set(keyOne, "", time.Second)
  2435. defer redis.Close()
  2436. fmt.Println(getNurseErr)
  2437. }
  2438. if evaluation.PulseFrequency == 0 {
  2439. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2440. if adminUserInfo.Org.Id == 10693 {
  2441. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2442. evaluation.PulseFrequency = pulseFrequency
  2443. }
  2444. press := models.PredialysisEvaluation{
  2445. PulseFrequency: evaluation.PulseFrequency,
  2446. }
  2447. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2449. redis := service.RedisClient()
  2450. redis.Set(key, "", time.Second)
  2451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2452. redis.Set(keyOne, "", time.Second)
  2453. defer redis.Close()
  2454. fmt.Println(getNurseErr)
  2455. }
  2456. if evaluation.Temperature == 0 {
  2457. evaluation.Temperature = fmonitorRecords.Temperature
  2458. press := models.PredialysisEvaluation{
  2459. Temperature: evaluation.Temperature,
  2460. }
  2461. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2463. redis := service.RedisClient()
  2464. redis.Set(key, "", time.Second)
  2465. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2466. redis.Set(keyOne, "", time.Second)
  2467. defer redis.Close()
  2468. fmt.Println(getNurseErr)
  2469. }
  2470. }
  2471. if adminUserInfo.Org.Id == 9583 {
  2472. //获取透析处方的最后一条数据
  2473. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2474. if diaerr != nil {
  2475. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2481. }
  2482. }
  2483. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2496. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2497. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2498. }
  2499. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2500. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2501. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2502. }
  2503. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2504. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2505. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2506. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2507. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2508. }
  2509. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2510. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2511. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2512. }
  2513. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2514. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2515. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2516. }
  2517. if lastAssessmentAfterDislysis != nil {
  2518. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2519. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2520. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2521. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2522. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2523. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2524. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2525. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2526. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2527. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2528. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2529. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2530. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2531. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2532. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2533. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2534. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2535. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2536. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2537. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2538. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2539. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2540. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2541. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2542. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2543. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2544. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2545. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2546. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2547. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2548. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2549. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2550. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2551. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2552. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2553. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2554. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2555. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2556. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2557. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2558. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2559. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2560. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2561. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2562. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2563. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2564. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2565. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2566. if tempassessmentAfterDislysis.PatientId == 18695 {
  2567. tempassessmentAfterDislysis.ActualDisplacement = 0
  2568. }
  2569. if adminUserInfo.Org.Id != 10375 {
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2571. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2572. }
  2573. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2574. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2576. }
  2577. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2578. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2579. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2580. }
  2581. }
  2582. finish := models.XtDialysisFinish{
  2583. IsFinish: 1,
  2584. UserOrgId: adminUserInfo.Org.Id,
  2585. Status: 1,
  2586. Ctime: time.Now().Unix(),
  2587. Mtime: 0,
  2588. Module: 9,
  2589. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2590. Sourse: 1,
  2591. PatientId: tempassessmentAfterDislysis.PatientId,
  2592. }
  2593. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2594. if dialysisFinish.ID == 0 {
  2595. service.CreateDialysisFinish(finish)
  2596. }
  2597. //孝康
  2598. if adminUserInfo.Org.Id == 10693 {
  2599. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2600. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2601. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2603. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2604. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2605. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2606. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2607. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2608. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2609. }
  2610. if adminUserInfo.Org.Id == 10697 {
  2611. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2612. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2613. lastWeightAfter.LastAfterWeight = floatAfeter
  2614. }
  2615. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2616. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2617. redis := service.RedisClient()
  2618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2619. redis.Set(keyOne, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. defer redis.Close()
  2623. //清空key 值
  2624. redis.Set(key, "", time.Second)
  2625. if err != nil {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. return
  2628. }
  2629. if dialysisOrder == nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2631. return
  2632. }
  2633. if dialysisOrder.Stage == 2 {
  2634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2635. return
  2636. }
  2637. if dialysisOrder.Stage == 1 {
  2638. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2639. finish := models.XtDialysisFinish{
  2640. IsFinish: 1,
  2641. UserOrgId: adminUserInfo.Org.Id,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Module: 8,
  2646. RecordDate: recordDate.Unix(),
  2647. Sourse: 1,
  2648. PatientId: id,
  2649. }
  2650. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2651. if dialysisFinish.ID == 0 {
  2652. service.CreateDialysisFinish(finish)
  2653. }
  2654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2655. redis := service.RedisClient()
  2656. defer redis.Close()
  2657. //清空key 值
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2660. redis.Set(keyOne, "", time.Second)
  2661. //结束时候透析次数加1
  2662. service.UpdateSolutionByPatientId(id)
  2663. //下机完自动消毒,针对长沙南雅
  2664. if dialysisOrder.Stage == 1 {
  2665. 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 {
  2666. //根据床位号获取设备型号
  2667. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2668. //查询使用消毒最后一条消毒记录
  2669. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2670. fmt.Println("err", err)
  2671. if err == gorm.ErrRecordNotFound {
  2672. //查找排班
  2673. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2674. //查询改设备是否有消毒计划
  2675. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2676. //根据床位号获取设备id
  2677. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2678. //查询病人信息
  2679. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2680. var con = ""
  2681. if patients.IsInfectious == 0 {
  2682. con = ""
  2683. }
  2684. if patients.IsInfectious == 1 {
  2685. con = "无"
  2686. }
  2687. if patients.IsInfectious == 2 {
  2688. con = "有"
  2689. }
  2690. if errcode == nil {
  2691. var end_time int64
  2692. end_time = endDate.Unix() + plan.DisinfecTime*60
  2693. //新增消毒
  2694. information := models.DeviceInformation{
  2695. Date: dialysisOrder.DialysisDate,
  2696. Zone: dialysisOrder.ZoneId,
  2697. Class: dialysisOrder.SchedualType,
  2698. BedNumber: dialysisOrder.BedID,
  2699. PatientId: dialysisOrder.PatientId,
  2700. DialysisMode: scheduleByPatient.ModeId,
  2701. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2702. Disinfection: 1,
  2703. DialysisConcentration: 1,
  2704. DisinfectionStatus: 1,
  2705. Move: 1,
  2706. UserOrgId: dialysisOrder.UserOrgId,
  2707. DisinfectType: plan.Way,
  2708. DisinfectantType: plan.MachineDisinfectant,
  2709. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2710. Disinfectant: plan.Disinfectant,
  2711. Ctime: time.Now().Unix(),
  2712. Status: 1,
  2713. SignName: nurseID,
  2714. EquimentId: addmacher.ID,
  2715. DisinfectionResidue: 2,
  2716. Bed: addmacher.BedNumber,
  2717. StartTime: dialysisOrder.StartTime,
  2718. EndTime: dialysisOrder.EndTime,
  2719. Contagion: con,
  2720. WeightLoss: 0,
  2721. Hyperfiltratio: 0,
  2722. DialysisHour: "",
  2723. MachineRun: 1,
  2724. DisinfecStartime: endDate.Unix(),
  2725. DisinfecEndtime: end_time,
  2726. }
  2727. err := service.CreateInformationTwo(&information)
  2728. fmt.Println("报错", err)
  2729. }
  2730. }
  2731. }
  2732. }
  2733. dialysisOrder.Stage = 2
  2734. dialysisOrder.FinishNurse = nurseID
  2735. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2736. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2737. dialysisOrder.EndTime = endDate.Unix()
  2738. // 长沙南雅需求
  2739. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2740. //获取最后1条监测的数据
  2741. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2742. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2743. var accumulatedBloodVolume float64
  2744. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2745. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2746. fmt.Println(err)
  2747. // 查询未执行的医嘱
  2748. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2749. for _, item := range doctorAdvice {
  2750. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2752. redis := service.RedisClient()
  2753. //清空key 值
  2754. redis.Set(key, "", time.Second)
  2755. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2756. redis.Set(keyTwo, "", time.Second)
  2757. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2758. redis.Set(keyThree, "", time.Second)
  2759. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2760. theTime := toTime.Format("2006-01-02")
  2761. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2762. redis.Set(keyFour, "", time.Second)
  2763. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2764. redis.Set(keyFive, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. }
  2768. go func() {
  2769. ssoDomain := beego.AppConfig.String("call_domain")
  2770. api := ssoDomain + "/index/downpatient"
  2771. values := make(url.Values)
  2772. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2773. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2774. values.Set("patient_id", strconv.FormatInt(id, 10))
  2775. http.PostForm(api, values)
  2776. }()
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "dialysisOrder": dialysisOrder,
  2780. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisAPIController) GetAllZone() {
  2788. adminUserInfo := c.GetMobileAdminUserInfo()
  2789. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2790. if err == nil {
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "zone": zone,
  2793. })
  2794. }
  2795. }
  2796. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2797. adminUserInfo := c.GetMobileAdminUserInfo()
  2798. page, _ := c.GetInt64("page", 1)
  2799. limit, _ := c.GetInt64("limit", 10)
  2800. schedulType, _ := c.GetInt64("schedul_type", 0)
  2801. startTime, _ := c.GetInt64("schedul_time", 0)
  2802. partitionType, _ := c.GetInt64("partition_type", 0)
  2803. keywords := c.GetString("keywords")
  2804. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2805. if err == nil {
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "schedule": dialysisSchedule,
  2808. })
  2809. }
  2810. return
  2811. }
  2812. // /m/api/dialysis/start [post]
  2813. // @param patient_id:int
  2814. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2815. // @param nurse:int 上机护士
  2816. // @param bed:int 床位号
  2817. func (this *DialysisAPIController) StartDialysis() {
  2818. patientID, _ := this.GetInt64("patient_id")
  2819. recordDateStr := this.GetString("record_date")
  2820. nurseID, _ := this.GetInt64("start_nurse")
  2821. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2822. blood_drawing, _ := this.GetInt64("blood_drawing")
  2823. schedual_type, _ := this.GetInt64("schedual_type")
  2824. bedID, _ := this.GetInt64("bed")
  2825. start_time := this.GetString("start_time")
  2826. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2827. change_nurse, _ := this.GetInt64("change_nurse")
  2828. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2829. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2830. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2831. puncture_needle := this.GetString("puncture_needle")
  2832. puncture_way := this.GetString("puncture_way")
  2833. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2834. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2835. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2836. zone_id, _ := this.GetInt64("zone_id")
  2837. elecsign := this.GetString("url")
  2838. nuclein_date_str := this.GetString("nuclein_date_str")
  2839. schedule_remark := this.GetString("schedule_remark")
  2840. order_remark := this.GetString("order_remark")
  2841. catheter_operation := this.GetString("catheter_operation")
  2842. blood_flow_volume := this.GetString("blood_flow_volume")
  2843. dialysis_strainer := this.GetString("dialysis_strainer")
  2844. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2849. if parseStartDateErr != nil {
  2850. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2855. if parseErr != nil {
  2856. this.ErrorLog("时间解析失败:%v", parseErr)
  2857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. adminUserInfo := this.GetMobileAdminUserInfo()
  2861. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2862. if getPatientErr != nil {
  2863. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. } else if patient == nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2868. return
  2869. }
  2870. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2871. if getNurseErr != nil {
  2872. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2874. return
  2875. } else if nurse == nil {
  2876. this.ErrorLog("护士不存在")
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2881. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2882. if getDeviceNumberErr != nil {
  2883. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. } else if deviceNumber == nil {
  2887. this.ErrorLog("床位号不存在")
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2892. if getRecordErr != nil {
  2893. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2895. return
  2896. } else if dialysisRecord != nil {
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2898. return
  2899. }
  2900. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2901. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2902. timeLayout := "2006-01-02 15:04:05"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2905. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2906. schedulestartTime := theStartTime.Unix()
  2907. scheduleendTime := theEndTime.Unix()
  2908. var theNucleinDate int64
  2909. timeLayoutOne := "2006-01-02"
  2910. if len(nuclein_date_str) > 0 {
  2911. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. }
  2915. theNucleinDate = theTime.Unix()
  2916. }
  2917. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2918. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2919. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2921. //查询该床位是否有人用了
  2922. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2923. if err == gorm.ErrRecordNotFound { //空床位
  2924. // 修改了床位逻辑
  2925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2926. if daySchedule.ID > 0 {
  2927. daySchedule.PartitionId = deviceNumber.ZoneID
  2928. daySchedule.BedId = bedID
  2929. daySchedule.ScheduleType = schedual_type
  2930. daySchedule.UpdatedTime = time.Now().Unix()
  2931. xtSchedule := models.Schedule{
  2932. PartitionId: deviceNumber.ZoneID,
  2933. BedId: bedID,
  2934. ScheduleType: schedual_type,
  2935. UpdatedTime: time.Now().Unix(),
  2936. }
  2937. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2938. if err != nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2940. return
  2941. }
  2942. }
  2943. } else if err == nil {
  2944. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2945. if order.ID > 0 { //该机位被其他人占用了
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2949. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2950. if daySchedule.ID > 0 {
  2951. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2952. if err != nil {
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. return
  2955. }
  2956. }
  2957. }
  2958. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2960. return
  2961. }
  2962. //else if order.ID == 0 { //该床位没被占用
  2963. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2964. // if daySchedule.ID > 0 {
  2965. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2966. // //daySchedule.BedId = bedID
  2967. // //daySchedule.ScheduleType = schedual_type
  2968. // //daySchedule.UpdatedTime = time.Now().Unix()
  2969. // //err := service.UpdateSchedule(&daySchedule)
  2970. // xtSchedule := models.Schedule{
  2971. // PartitionId: deviceNumber.ZoneID,
  2972. // BedId: bedID,
  2973. // ScheduleType: schedual_type,
  2974. // UpdatedTime: time.Now().Unix(),
  2975. // }
  2976. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2977. // if err != nil {
  2978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // }
  2981. // }
  2982. //}
  2983. //}
  2984. } else if err != nil {
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. }
  2988. // 查询信息规挡的设置天数
  2989. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2990. if infor.ID > 0 && infor.WeekDay > 0 {
  2991. var cha_time int64
  2992. timeNowStr := time.Now().Format("2006-01-02")
  2993. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2994. //今日的日期减去设置的日期
  2995. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2996. if cha_time >= recordDate.Unix() {
  2997. //查询审核是否允许
  2998. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2999. //申请状态不允许的情况 拒绝修改
  3000. if infor.ApplicationStatus != 1 {
  3001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3002. return
  3003. }
  3004. }
  3005. }
  3006. dialysisRecord = &models.DialysisOrder{
  3007. DialysisDate: recordDate.Unix(),
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. Stage: 1,
  3011. BedID: bedID,
  3012. StartNurse: nurseID,
  3013. Status: 1,
  3014. StartTime: startDate.Unix(),
  3015. CreatedTime: time.Now().Unix(),
  3016. UpdatedTime: time.Now().Unix(),
  3017. PunctureNurse: puncture_nurse,
  3018. Creator: adminUserInfo.AdminUser.Id,
  3019. Modifier: adminUserInfo.AdminUser.Id,
  3020. SchedualType: schedual_type,
  3021. WashpipeNurse: washpipe_nurse,
  3022. ChangeNurse: change_nurse,
  3023. DifficultPunctureNurse: difficult_puncture_nurse,
  3024. NewFistulaNurse: new_fistula_nurse,
  3025. ZoneId: zone_id,
  3026. QualityNurseId: quality_nurse_id,
  3027. PunctureNeedle: puncture_needle,
  3028. PunctureWay: puncture_way,
  3029. DialysisIrrigation: dialysis_irrigation,
  3030. DialysisDialyszers: dialysis_dialyszers,
  3031. BloodAccessId: blood_access_id,
  3032. Url: elecsign,
  3033. NucleinDate: theNucleinDate,
  3034. ScheduleRemark: schedule_remark,
  3035. OrderRemark: order_remark,
  3036. CatheterOperation: catheter_operation,
  3037. BloodFlowVolume: blood_flow_volume,
  3038. BloodDrawing: blood_drawing,
  3039. DialysisStrainer: dialysis_strainer,
  3040. }
  3041. //查询该床位是否有人用了
  3042. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3043. if errorscode == gorm.ErrRecordNotFound {
  3044. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 6,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3061. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3062. //统计该患者总次数
  3063. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3064. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3065. }
  3066. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3067. //统计该患者总次数
  3068. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3069. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3070. }
  3071. redis := service.RedisClient()
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3073. redis.Set(key, "", time.Second)
  3074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3075. //清空key 值
  3076. redis.Set(keyOne, "", time.Second)
  3077. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3078. //清空key 值
  3079. redis.Set(keyTwo, "", time.Second)
  3080. if createErr != nil {
  3081. this.ErrorLog("上机失败:%v", createErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. }
  3086. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3087. var tempdispose string
  3088. // 只针对中能建
  3089. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3090. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3091. }
  3092. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3093. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3094. }
  3095. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3096. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3097. //}
  3098. var ultrafiltration_rate float64
  3099. var ultrafiltration_rate_one string
  3100. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3101. //后期预增脱水量
  3102. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3103. if prescription.ID > 0 {
  3104. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3105. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3106. 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
  3107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3108. }
  3109. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3110. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3111. }
  3112. //针对医师汇
  3113. if adminUserInfo.Org.Id == 10121 {
  3114. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3115. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3116. }
  3117. //针对通道
  3118. if adminUserInfo.Org.Id == 10234 {
  3119. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3120. }
  3121. //针对监利大垸医院
  3122. if template.TemplateId == 41 {
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3124. }
  3125. //针对肇庆三鹤血液透析中心
  3126. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3127. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3128. }
  3129. if adminUserInfo.Org.Id == 10469 {
  3130. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3131. }
  3132. if adminUserInfo.Org.Id == 10667 {
  3133. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3134. }
  3135. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3137. }
  3138. // 只针对方济医院
  3139. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3140. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3141. ultrafiltration_rate = value
  3142. }
  3143. //针对
  3144. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3146. ultrafiltration_rate = ultrafiltration_rate / 1000
  3147. }
  3148. if adminUserInfo.Org.Id == 10551 {
  3149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3150. ultrafiltration_rate = ultrafiltration_rate / 1000
  3151. }
  3152. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10580 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10629 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10644 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10667 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10693 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate
  3175. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3176. }
  3177. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3178. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3179. ultrafiltration_rate = ultrafiltration_rate
  3180. }
  3181. if adminUserInfo.Org.Id == 10702 {
  3182. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3183. ultrafiltration_rate = ultrafiltration_rate / 1000
  3184. }
  3185. if adminUserInfo.Org.Id == 10723 {
  3186. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate / 1000
  3188. }
  3189. if adminUserInfo.Org.Id == 10721 {
  3190. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3191. ultrafiltration_rate = ultrafiltration_rate / 1000
  3192. }
  3193. }
  3194. }
  3195. record := models.MonitoringRecord{
  3196. UserOrgId: adminUserInfo.Org.Id,
  3197. PatientId: patientID,
  3198. DialysisOrderId: dialysisRecord.ID,
  3199. MonitoringDate: schedulestartTime,
  3200. OperateTime: startDate.Unix(),
  3201. // MonitoringTime: recordTime,
  3202. MonitoringNurse: nurseID,
  3203. Dispose: tempdispose,
  3204. UltrafiltrationRate: ultrafiltration_rate,
  3205. UltrafiltrationVolume: 0,
  3206. Status: 1,
  3207. CreatedTime: time.Now().Unix(),
  3208. UpdatedTime: time.Now().Unix(),
  3209. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3210. }
  3211. //只针对广慈医院
  3212. 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 {
  3213. // 查询病人是否有透前评估数据
  3214. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3215. //如果有数据就插入
  3216. if errcode == nil {
  3217. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3218. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3219. record.BreathingRate = befor.BreathingRate
  3220. record.PulseFrequency = befor.PulseFrequency
  3221. record.Temperature = befor.Temperature
  3222. }
  3223. }
  3224. //孝昌
  3225. if adminUserInfo.Org.Id == 10693 {
  3226. // 查询病人是否有透前评估数据
  3227. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3228. //如果有数据就插入
  3229. if errcode == nil {
  3230. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3231. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3232. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3233. record.BreathingRate = befor.BreathingRate
  3234. }
  3235. }
  3236. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3237. if newdialysisRecord.ID > 0 {
  3238. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3239. record.Temperature = 36.5
  3240. record.ArterialPressure = -100
  3241. record.DialysateTemperature = 36.5
  3242. record.Conductivity = 14
  3243. record.BreathingRate = "20"
  3244. record.VenousPressure = 80
  3245. record.TransmembranePressure = 60
  3246. record.Dispose = catheter_operation
  3247. }
  3248. //针对新化博翔
  3249. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3250. record.BloodOxygenSaturation = "99"
  3251. record.Conductivity = 14
  3252. record.DialysateTemperature = 36.5
  3253. record.BreathingRate = "20"
  3254. }
  3255. //针对兰溪人民医院的需求
  3256. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3257. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3258. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3259. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3260. record.Temperature = befor.Temperature
  3261. record.PulseFrequency = befor.PulseFrequency
  3262. record.BreathingRate = befor.BreathingRate
  3263. }
  3264. //针对乐山友谊医院的需求
  3265. if adminUserInfo.Org.Id == 10677 {
  3266. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3267. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3268. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3269. record.Temperature = befor.Temperature
  3270. record.PulseFrequency = befor.PulseFrequency
  3271. record.BreathingRate = befor.BreathingRate
  3272. }
  3273. //新化博翔
  3274. if adminUserInfo.Org.Id == 10447 {
  3275. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3276. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3277. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3278. record.BreathingRate = befor.BreathingRate
  3279. }
  3280. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3281. record.PulseFrequency = 80
  3282. record.Temperature = 36.5
  3283. }
  3284. //诊断灵山圣康
  3285. if adminUserInfo.Org.Id == 10375 {
  3286. record.Conductivity = 13.8
  3287. record.DialysateTemperature = 37
  3288. record.DialysateFlow = 500
  3289. record.BloodFlowVolume = 200
  3290. record.BreathingRate = "18"
  3291. record.SodiumConcentration = 140
  3292. }
  3293. //江成肾病医院
  3294. if adminUserInfo.Org.Id == 10517 {
  3295. record.SodiumConcentration = 138
  3296. record.DialysateTemperature = 36.5
  3297. }
  3298. if adminUserInfo.Org.Id != 10683 {
  3299. err = service.CreateMonitor(&record)
  3300. }
  3301. //记录日志
  3302. byterequest, _ := json.Marshal(record)
  3303. monitorRecordLog := models.XtMonitorRecordLog{
  3304. RecordDate: record.MonitoringDate,
  3305. PatientId: record.PatientId,
  3306. Module: 1,
  3307. AdminUserId: adminUserInfo.AdminUser.Id,
  3308. Ctime: time.Now().Unix(),
  3309. Mtime: 0,
  3310. Status: 1,
  3311. UserOrgId: record.UserOrgId,
  3312. ErrLog: string(byterequest),
  3313. Source: "执行上机时新增监测",
  3314. }
  3315. service.CreateMonitorRecordLog(monitorRecordLog)
  3316. finish := models.XtDialysisFinish{
  3317. IsFinish: 1,
  3318. UserOrgId: adminUserInfo.Org.Id,
  3319. Status: 1,
  3320. Ctime: time.Now().Unix(),
  3321. Mtime: 0,
  3322. Module: 7,
  3323. RecordDate: schedulestartTime,
  3324. Sourse: 1,
  3325. PatientId: patientID,
  3326. }
  3327. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3328. if dialysisFinish.ID == 0 {
  3329. service.CreateDialysisFinish(finish)
  3330. }
  3331. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3332. redis := service.RedisClient()
  3333. //清空key 值
  3334. redis.Set(key, "", time.Second)
  3335. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3336. redis.Set(keyOne, "", time.Second)
  3337. defer redis.Close()
  3338. if err != nil {
  3339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3340. return
  3341. }
  3342. }
  3343. go func() {
  3344. ssoDomain := beego.AppConfig.String("call_domain")
  3345. api := ssoDomain + "/index/uppatient"
  3346. values := make(url.Values)
  3347. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3348. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3349. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3350. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3351. http.PostForm(api, values)
  3352. }()
  3353. this.ServeSuccessJSON(map[string]interface{}{
  3354. "dialysis_order": newdialysisRecord,
  3355. "monitor": record,
  3356. })
  3357. return
  3358. }
  3359. func (c *DialysisAPIController) PostSolution() {
  3360. id, _ := c.GetInt64("patient", 0)
  3361. recordDateStr := c.GetString("record_date")
  3362. if id <= 0 {
  3363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3364. return
  3365. }
  3366. adminUserInfo := c.GetMobileAdminUserInfo()
  3367. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3368. if patient.ID == 0 {
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3370. return
  3371. }
  3372. if len(recordDateStr) == 0 {
  3373. recordDateStr = time.Now().Format("2006-01-02")
  3374. }
  3375. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3376. if parseDateErr != nil {
  3377. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3379. return
  3380. }
  3381. mode_id, _ := c.GetInt64("mode_id", 0)
  3382. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3383. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3384. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3385. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3386. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3387. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3388. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3389. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3390. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3391. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3392. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3393. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3394. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3395. kalium, _ := c.GetFloat("kalium", 0)
  3396. sodium, _ := c.GetFloat("sodium", 0)
  3397. calcium, _ := c.GetFloat("calcium", 0)
  3398. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3399. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3400. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3401. glucose, _ := c.GetFloat("glucose", 0)
  3402. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3403. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3404. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3405. conductivity, _ := c.GetFloat("conductivity", 0)
  3406. remark := c.GetString("remark")
  3407. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3408. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3409. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3410. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3411. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3412. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3413. special_medicine_other := c.GetString("special_medicine_other")
  3414. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3415. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3416. blood_access, _ := c.GetInt64("blood_access", 0)
  3417. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3418. body_fluid_other := c.GetString("body_fluid_other")
  3419. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3420. niprocart, _ := c.GetInt64("niprocart", 0)
  3421. jms, _ := c.GetInt64("jms", 0)
  3422. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3423. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3424. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3425. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3426. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3427. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3428. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3429. injector, _ := c.GetInt64("injector", 0)
  3430. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3431. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3432. safe_package, _ := c.GetInt64("package", 0)
  3433. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3434. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3435. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3436. blood := c.GetString("blood")
  3437. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3438. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3439. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3440. displace_speed := c.GetString("displace_speed")
  3441. illness, _ := c.GetInt64("illness")
  3442. amylaceum := c.GetString("amylaceum")
  3443. single_time := c.GetString("single_time")
  3444. single_water := c.GetString("single_water")
  3445. replacement_flow := c.GetString("replacement_flow")
  3446. plasma_separator := c.GetString("plasma_separator")
  3447. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3448. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3449. oxygen_flow := c.GetString("oxygen_flow")
  3450. oxygen_time := c.GetString("oxygen_time")
  3451. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3452. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3453. puncture_needle := c.GetString("puncture_needle")
  3454. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3455. epo := c.GetString("epo")
  3456. epo_count, _ := c.GetFloat("epo_count", 0)
  3457. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3458. pre_impulse := c.GetString("pre_impulse")
  3459. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3460. admin_user_id, _ := c.GetInt64("admin_user_id")
  3461. is_water := c.GetString("is_water")
  3462. add_amount, _ := c.GetFloat("add_amount")
  3463. reduce_amount, _ := c.GetFloat("reduce_amount")
  3464. prescribing_number, _ := c.GetFloat("prescribing_number")
  3465. treatment_remark := c.GetString("treatment_remark")
  3466. prescription_sodium := c.GetString("prescription_sodium")
  3467. start_sodium := c.GetString("start_sodium")
  3468. sodium_curve := c.GetString("sodium_curve")
  3469. var is_war int64
  3470. if is_water == "是" {
  3471. is_war = 1
  3472. }
  3473. if is_water == "否" {
  3474. is_war = 2
  3475. }
  3476. if is_water == "请选择" {
  3477. is_war = 0
  3478. }
  3479. drhy_water := c.GetString("drhy_water")
  3480. dry_water_hour := c.GetString("dry_water_hour")
  3481. water_machine := c.GetString("water_machine")
  3482. dialysis_remark := c.GetString("dialysis_remark")
  3483. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3484. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3485. prescription_water, _ := c.GetFloat("prescription_water")
  3486. dialysis_strainer := c.GetString("dialysis_strainer")
  3487. chaptalization := c.GetString("chaptalization")
  3488. washing_time := c.GetString("washing_time")
  3489. warsh_count := c.GetString("warsh_count")
  3490. blood_access_part_id := c.GetString("blood_access_part_id")
  3491. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3492. dialyzate := c.GetString("dialyzate")
  3493. if mode_id > 0 {
  3494. var str string
  3495. //查找该机构用的是什么透析器
  3496. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3497. if filedConfig.ID > 0 {
  3498. str = dialyzerPerfusionApparatus
  3499. } else {
  3500. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3501. }
  3502. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3503. }
  3504. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3505. //
  3506. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3507. // if appRole.UserType == 3 {
  3508. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3509. // if getPermissionErr != nil {
  3510. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3511. // return
  3512. // } else if headNursePermission == nil {
  3513. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3514. // return
  3515. // }
  3516. // }
  3517. //}
  3518. // 查询信息规挡的设置天数
  3519. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3520. if infor.ID > 0 && infor.WeekDay > 0 {
  3521. var cha_time int64
  3522. timeNowStr := time.Now().Format("2006-01-02")
  3523. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3524. //今日的日期减去设置的日期
  3525. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3526. if cha_time >= recordDate.Unix() {
  3527. //查询审核是否允许
  3528. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3529. //申请状态不允许的情况 拒绝修改
  3530. if infor.ApplicationStatus != 1 {
  3531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3532. return
  3533. }
  3534. }
  3535. }
  3536. prescription := models.DialysisPrescription{
  3537. UserOrgId: adminUserInfo.Org.Id,
  3538. PatientId: id,
  3539. RecordDate: recordDate.Unix(),
  3540. ModeId: mode_id,
  3541. DialysisDuration: dialysis_duration,
  3542. Dialyzer: dialyzer,
  3543. PerfusionApparatus: perfusion_apparatus,
  3544. BloodFlowVolume: blood_flow_volume,
  3545. DewaterAmount: dewater_amount,
  3546. DisplaceLiqui: displace_liqui,
  3547. ReplacementWay: replacement_way,
  3548. Anticoagulant: anticoagulant,
  3549. AnticoagulantShouji: anticoagulant_shouji,
  3550. AnticoagulantWeichi: anticoagulant_weichi,
  3551. AnticoagulantZongliang: anticoagulant_zongliang,
  3552. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3553. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3554. Kalium: kalium,
  3555. Sodium: sodium,
  3556. Calcium: calcium,
  3557. Bicarbonate: bicarbonate,
  3558. Glucose: glucose,
  3559. // DryWeight: dry_weight,
  3560. DialysateFlow: dialysate_flow,
  3561. DialysateTemperature: dialysate_temperature,
  3562. Conductivity: conductivity,
  3563. Remark: remark,
  3564. Status: 1,
  3565. CreatedTime: time.Now().Unix(),
  3566. UpdatedTime: time.Now().Unix(),
  3567. DialysisDurationMinute: dialysisDurationMinute,
  3568. DialysisDurationHour: dialysisDurationHour,
  3569. TargetUltrafiltration: targetUltrafiltration,
  3570. DialysateFormulation: dialysateFormulation,
  3571. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3572. BodyFluid: body_fluid,
  3573. SpecialMedicine: special_medicine,
  3574. SpecialMedicineOther: special_medicine_other,
  3575. DisplaceLiquiPart: displace_liqui_part,
  3576. DisplaceLiquiValue: displace_liqui_value,
  3577. BloodAccess: blood_access,
  3578. Ultrafiltration: ultrafiltration,
  3579. BodyFluidOther: body_fluid_other,
  3580. ReplacementTotal: replacement_total,
  3581. Niprocart: niprocart,
  3582. Jms: jms,
  3583. FistulaNeedleSet: fistula_needle_set,
  3584. FistulaNeedleSet16: fistula_needle_set_16,
  3585. Hemoperfusion: hemoperfusion,
  3586. DialyserSterilised: dialyser_sterilised,
  3587. Filtryzer: filtryzer,
  3588. TargetKtv: target_ktv,
  3589. Dialyzers: dialyzers,
  3590. Injector: injector,
  3591. Bloodlines: bloodlines,
  3592. TubingHemodialysis: tubing_hemodialysis,
  3593. Package: safe_package,
  3594. ALiquid: a_liquid,
  3595. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3596. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3597. Blood: blood,
  3598. DialysisDialyszers: dialysis_dialyszers,
  3599. DialysisIrrigation: dialysis_irrigation,
  3600. AntioxidantCommodityName: antioxidant_commodity_name,
  3601. DisplaceSpeed: displace_speed,
  3602. Illness: illness,
  3603. Amylaceum: amylaceum,
  3604. SingleWater: single_water,
  3605. SingleTime: single_time,
  3606. ReplacementFlow: replacement_flow,
  3607. PlasmaSeparator: plasma_separator,
  3608. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3609. OxygenUptake: oxygen_uptake,
  3610. OxygenTime: oxygen_time,
  3611. OxygenFlow: oxygen_flow,
  3612. HemodialysisPipelines: hemodialysis_pipelines,
  3613. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3614. PunctureNeedle: puncture_needle,
  3615. PunctureNeedleCount: puncture_needle_count,
  3616. Epo: epo,
  3617. EpoCount: epo_count,
  3618. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3619. PreImpulse: impulse,
  3620. AdminUserId: admin_user_id,
  3621. IsWater: is_war,
  3622. DrhyWater: drhy_water,
  3623. DryWaterHour: dry_water_hour,
  3624. WaterMachine: water_machine,
  3625. AddAmount: add_amount,
  3626. ReduceAmount: reduce_amount,
  3627. DialysisRemark: dialysis_remark,
  3628. PrescribingNumber: prescribing_number,
  3629. PrescriptionSodium: prescription_sodium,
  3630. StartSodium: start_sodium,
  3631. SodiumCurve: sodium_curve,
  3632. TreatmentRemark: treatment_remark,
  3633. DialysisFluidFlow: dialysis_fluid_flow,
  3634. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3635. PrescriptionWater: prescription_water,
  3636. DialysisStrainer: dialysis_strainer,
  3637. Chaptalization: chaptalization,
  3638. WashingTime: washing_time,
  3639. WarshCount: warsh_count,
  3640. BloodAccessPartId: blood_access_part_id,
  3641. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3642. Dialyzate: dialyzate,
  3643. }
  3644. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3645. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3646. //
  3647. if appRole.UserType == 2 || appRole.UserType == 1 {
  3648. prescription_doctor = adminUserInfo.AdminUser.Id
  3649. prescription.PrescriptionDoctor = prescription_doctor
  3650. }
  3651. if dialysisPrescription.ID == 0 { //新增
  3652. prescription.Creater = adminUserInfo.AdminUser.Id
  3653. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3654. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3655. }
  3656. } else { //修改
  3657. if dialysisPrescription.Creater == 0 {
  3658. prescription.Creater = adminUserInfo.AdminUser.Id
  3659. } else {
  3660. prescription.Creater = dialysisPrescription.Creater
  3661. if adminUserInfo.Org.Id == 9882 {
  3662. if appRole.UserType == 2 || appRole.UserType == 1 {
  3663. prescription.Creater = adminUserInfo.AdminUser.Id
  3664. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3665. }
  3666. }
  3667. }
  3668. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3669. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3670. }
  3671. //if/**/
  3672. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3673. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3674. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3675. // if getPermissionErr != nil {
  3676. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3677. // return
  3678. // } else if headNursePermission == nil {
  3679. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3680. // return
  3681. // }
  3682. //}
  3683. //prescription.Creater = dialysisPrescription.Creater
  3684. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3685. prescription.Modifier = adminUserInfo.AdminUser.Id
  3686. prescription.ID = dialysisPrescription.ID
  3687. }
  3688. solution := models.DialysisSolution{
  3689. RegistrarsId: adminUserInfo.AdminUser.Id,
  3690. UserOrgId: adminUserInfo.Org.Id,
  3691. Doctor: prescription_doctor,
  3692. PatientId: id,
  3693. ModeId: mode_id,
  3694. DialysisDuration: dialysis_duration,
  3695. PerfusionApparatus: perfusion_apparatus,
  3696. BloodFlowVolume: blood_flow_volume,
  3697. Dewater: dewater_amount,
  3698. DisplaceLiqui: displace_liqui,
  3699. ReplacementWay: replacement_way,
  3700. Anticoagulant: anticoagulant,
  3701. AnticoagulantShouji: anticoagulant_shouji,
  3702. AnticoagulantWeichi: anticoagulant_weichi,
  3703. AnticoagulantZongliang: anticoagulant_zongliang,
  3704. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3705. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3706. Kalium: kalium,
  3707. Sodium: sodium,
  3708. Calcium: calcium,
  3709. Bicarbonate: bicarbonate,
  3710. Glucose: glucose,
  3711. // DryWeight: dry_weight,
  3712. DialysateFlow: dialysate_flow,
  3713. DialysateTemperature: dialysate_temperature,
  3714. Conductivity: conductivity,
  3715. Remark: remark,
  3716. Status: 1,
  3717. CreatedTime: time.Now().Unix(),
  3718. UpdatedTime: time.Now().Unix(),
  3719. DialysisDurationMinute: dialysisDurationMinute,
  3720. DialysisDurationHour: dialysisDurationHour,
  3721. TargetUltrafiltration: targetUltrafiltration,
  3722. DialysateFormulation: dialysateFormulation,
  3723. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3724. BodyFluid: body_fluid,
  3725. SpecialMedicine: special_medicine,
  3726. SpecialMedicineOther: special_medicine_other,
  3727. DisplaceLiquiPart: displace_liqui_part,
  3728. DisplaceLiquiValue: displace_liqui_value,
  3729. BloodAccess: blood_access,
  3730. Ultrafiltration: ultrafiltration,
  3731. BodyFluidOther: body_fluid_other,
  3732. ReplacementTotal: replacement_total,
  3733. TargetKtv: target_ktv,
  3734. DialysisDialyszers: dialysis_dialyszers,
  3735. DialysisIrrigation: dialysis_irrigation,
  3736. HemodialysisPipelines: hemodialysis_pipelines,
  3737. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3738. PunctureNeedle: puncture_needle,
  3739. PunctureNeedleCount: puncture_needle_count,
  3740. Epo: epo,
  3741. EpoCount: epo_count,
  3742. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3743. PreImpulse: impulse,
  3744. SolutionStatus: 1,
  3745. DialysisRemark: dialysis_remark,
  3746. PrescribingNumber: prescribing_number,
  3747. PrescriptionSodium: prescription_sodium,
  3748. StartSodium: start_sodium,
  3749. SodiumCurve: sodium_curve,
  3750. TreatmentRemark: treatment_remark,
  3751. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3752. DialysisFluidFlow: dialysis_fluid_flow,
  3753. PrescriptionWater: prescription_water,
  3754. DialysisStrainer: dialysis_strainer,
  3755. Chaptalization: chaptalization,
  3756. WashingTime: washing_time,
  3757. WarshCount: warsh_count,
  3758. BloodAccessPartId: blood_access_part_id,
  3759. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3760. Dialyzate: dialyzate,
  3761. }
  3762. //针对河间咸的
  3763. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3764. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3765. solution.DisplaceLiquiPart = 0
  3766. solution.DisplaceLiquiValue = 0
  3767. }
  3768. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3769. prescription.DisplaceLiquiPart = 0
  3770. prescription.DisplaceLiquiValue = 0
  3771. }
  3772. }
  3773. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3774. if solution.PrescribingNumber == 0 {
  3775. solution.PrescribingNumber = 1
  3776. }
  3777. if prescription.PrescribingNumber == 0 {
  3778. prescription.PrescribingNumber = 1
  3779. }
  3780. if solution.PrescribingNumber == 0 && id == 14682 {
  3781. solution.PrescribingNumber = 2
  3782. }
  3783. if solution.PrescribingNumber == 0 && id == 18560 {
  3784. solution.PrescribingNumber = 2
  3785. }
  3786. if prescription.PrescribingNumber == 0 && id == 14682 {
  3787. prescription.PrescribingNumber = 2
  3788. }
  3789. if prescription.PrescribingNumber == 0 && id == 18560 {
  3790. prescription.PrescribingNumber = 2
  3791. }
  3792. }
  3793. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3794. //记录日志
  3795. byterequest, _ := json.Marshal(prescription)
  3796. prescriptionLog := models.XtDialysisPrescriptionLog{
  3797. UserOrgId: prescription.UserOrgId,
  3798. Ctime: time.Now().Unix(),
  3799. Mtime: 0,
  3800. ErrLog: string(byterequest),
  3801. AdminUserId: adminUserInfo.AdminUser.Id,
  3802. RecordDate: prescription.RecordDate,
  3803. PatientId: prescription.PatientId,
  3804. Source: "手机端新增长期处方",
  3805. Status: 1,
  3806. }
  3807. service.CreatePrescriptionLog(prescriptionLog)
  3808. finish := models.XtDialysisFinish{
  3809. IsFinish: 1,
  3810. UserOrgId: adminUserInfo.Org.Id,
  3811. Status: 1,
  3812. Ctime: time.Now().Unix(),
  3813. Mtime: 0,
  3814. Module: 1,
  3815. RecordDate: recordDate.Unix(),
  3816. Sourse: 1,
  3817. PatientId: id,
  3818. }
  3819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3820. if dialysisFinish.ID == 0 {
  3821. service.CreateDialysisFinish(finish)
  3822. }
  3823. //获取最新1条
  3824. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3825. //更新状态
  3826. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3827. //长沙南雅医院,自动生成抗凝剂的临时处方
  3828. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3829. if prescribing_number == 0 {
  3830. prescribing_number = 1
  3831. }
  3832. advice := models.DoctorAdvice{
  3833. UserOrgId: adminUserInfo.Org.Id,
  3834. PatientId: id,
  3835. GroupNo: 0,
  3836. AdviceType: 2,
  3837. RecordDate: recordDate.Unix(),
  3838. AdviceDate: recordDate.Unix(),
  3839. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3840. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3841. AdviceDesc: "",
  3842. ReminderDate: 0,
  3843. SingleDose: prescription.AnticoagulantZongliang,
  3844. SingleDoseUnit: "iu",
  3845. DrugSpec: 0,
  3846. DrugSpecUnit: "",
  3847. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3848. PrescribingNumberUnit: "支",
  3849. DeliveryWay: "静脉注射",
  3850. ExecutionFrequency: "上机前",
  3851. AdviceDoctor: 0,
  3852. Status: 1,
  3853. CreatedTime: time.Now().Unix(),
  3854. UpdatedTime: time.Now().Unix(),
  3855. IsPrescription: 1,
  3856. ExecutionState: 2,
  3857. StopState: 2,
  3858. IsSettle: 2,
  3859. }
  3860. // 查询排班信息
  3861. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3862. if schedulePatient.ID > 0 {
  3863. if schedulePatient.ScheduleType == 1 {
  3864. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3865. }
  3866. if schedulePatient.ScheduleType == 2 {
  3867. advice.StartTime = recordDate.Unix() + 9*60*60
  3868. }
  3869. }
  3870. // 抗凝剂名称
  3871. switch anticoagulant {
  3872. case 1:
  3873. advice.AdviceName = "无肝素"
  3874. break
  3875. case 2:
  3876. advice.AdviceName = "普通肝素"
  3877. break
  3878. case 3:
  3879. advice.AdviceName = "低分子肝素"
  3880. break
  3881. case 4:
  3882. advice.AdviceName = "阿加曲班"
  3883. break
  3884. case 5:
  3885. advice.AdviceName = "枸橼酸钠"
  3886. break
  3887. case 6:
  3888. advice.AdviceName = "低分子肝素钙"
  3889. break
  3890. case 7:
  3891. advice.AdviceName = "低分子肝素钠"
  3892. break
  3893. case 8:
  3894. advice.AdviceName = "依诺肝素"
  3895. break
  3896. case 9:
  3897. advice.AdviceName = "达肝素"
  3898. break
  3899. case 10:
  3900. advice.AdviceName = "体外抗凝"
  3901. break
  3902. case 11:
  3903. advice.AdviceName = "那曲肝素"
  3904. break
  3905. case 12:
  3906. advice.AdviceName = "无抗凝剂"
  3907. break
  3908. }
  3909. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3910. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3911. advice.AdviceDoctor = appRole.AdminUserId
  3912. }
  3913. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3914. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3915. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3916. advice.AdviceName = "低分子肝素钠注射液"
  3917. // 修改患者临时医嘱里的抗凝剂医嘱
  3918. advice.ID = advicePrescription.ID
  3919. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3920. } else {
  3921. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3922. advice.AdviceName = "低分子肝素钠注射液"
  3923. service.CreateDoctorAdvice(&advice)
  3924. }
  3925. }
  3926. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3927. redis := service.RedisClient()
  3928. defer redis.Close()
  3929. //清空key 值
  3930. redis.Set(key, "", time.Second)
  3931. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3932. redis.Set(keyOne, "", time.Second)
  3933. }
  3934. //获取key,清空redis
  3935. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3936. redis := service.RedisClient()
  3937. defer redis.Close()
  3938. //清空key 值
  3939. redis.Set(key, "", time.Second)
  3940. //清空长期医嘱的key
  3941. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3942. redis.Set(soulution_key, "", time.Second)
  3943. //查询最近透析准备表里是否存在 透析器 灌流器
  3944. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3945. redis.Set(keyOne, "", time.Second)
  3946. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3947. redis.Set(keyTwo, "", time.Second)
  3948. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3949. redis.Set(keyThree, "", time.Second)
  3950. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3951. redis.Set(keyFour, "", time.Second)
  3952. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3953. //
  3954. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3955. //
  3956. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3957. //if len(mation)>0{
  3958. // for _, item := range splitStr {
  3959. // for _,it := range mation{
  3960. // if(item == it.SpecificationName){
  3961. //
  3962. // //查询最近一次的透析器
  3963. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3964. //
  3965. // if errcode == gorm.ErrRecordNotFound{
  3966. // //插入数据
  3967. // prepare := models.DialysisBeforePrepare{
  3968. // UserOrgId: adminUserInfo.Org.Id,
  3969. // PatientId: id,
  3970. // RecordDate: recordDate.Unix(),
  3971. // GoodTypeId: it.GoodTypeId,
  3972. // GoodId: it.ID,
  3973. // Count: 1,
  3974. // Ctime: time.Now().Unix(),
  3975. // Creater: adminUserInfo.AdminUser.Id,
  3976. // Status:1,
  3977. //
  3978. // }
  3979. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3980. // fmt.Println("",errcode)
  3981. // }
  3982. // }
  3983. // }
  3984. //
  3985. // }
  3986. //
  3987. // for _, item := range splitIrrigation {
  3988. // for _,it := range mation{
  3989. // if(item == it.SpecificationName){
  3990. // //查询最近一次的透析器
  3991. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3992. // if errcode == gorm.ErrRecordNotFound{
  3993. // //插入数据
  3994. // prepare := models.DialysisBeforePrepare{
  3995. // UserOrgId: adminUserInfo.Org.Id,
  3996. // PatientId: id,
  3997. // RecordDate: recordDate.Unix(),
  3998. // GoodTypeId: it.GoodTypeId,
  3999. // GoodId: it.ID,
  4000. // Count: 1,
  4001. // Ctime: time.Now().Unix(),
  4002. // Creater: adminUserInfo.AdminUser.Id,
  4003. // Status:1,
  4004. //
  4005. // }
  4006. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4007. // fmt.Println(errcode)
  4008. // }
  4009. // }
  4010. // }
  4011. // }
  4012. //}
  4013. c.ServeSuccessJSON(map[string]interface{}{
  4014. "solution": &solution,
  4015. "prescription": &prescription,
  4016. })
  4017. }
  4018. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4019. patient, _ := c.GetInt64("patient", 0)
  4020. adminUserInfo := c.GetMobileAdminUserInfo()
  4021. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4022. c.ServeSuccessJSON(map[string]interface{}{
  4023. "receiveTreatmentAsses": receiveTreatmentAsses,
  4024. })
  4025. }
  4026. func (this *DialysisAPIController) PostSignInfo() {
  4027. patientID, _ := this.GetInt64("patient_id")
  4028. recordDateStr := this.GetString("date")
  4029. if patientID <= 0 {
  4030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4031. return
  4032. }
  4033. if len(recordDateStr) == 0 {
  4034. recordDateStr = time.Now().Format("2006-01-02")
  4035. }
  4036. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4037. if parseDateErr != nil {
  4038. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4040. return
  4041. }
  4042. adminInfo := this.GetMobileAdminUserInfo()
  4043. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4044. if err != nil {
  4045. this.ErrorLog("签名失败:%v", err)
  4046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4047. return
  4048. }
  4049. this.ServeSuccessJSON(map[string]interface{}{
  4050. "doctor_id": adminInfo.AdminUser.Id,
  4051. })
  4052. }
  4053. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4054. patientID, _ := this.GetInt64("patient_id")
  4055. adminInfo := this.GetMobileAdminUserInfo()
  4056. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4057. this.ServeSuccessJSON(map[string]interface{}{
  4058. "monitor": record,
  4059. })
  4060. }
  4061. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4062. thisTime := time.Now()
  4063. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4064. timeLayout := "2006-01-02 15:04:05"
  4065. loc, _ := time.LoadLocation("Local")
  4066. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4067. theAssessmentDateTime := theStartTime.Unix()
  4068. patientID, _ := this.GetInt64("patient_id")
  4069. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4070. adminInfo := this.GetMobileAdminUserInfo()
  4071. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4072. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4073. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4074. var ultrafiltration_rate float64
  4075. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4076. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4077. fmt.Println(evaluation)
  4078. fmt.Println("prescription.ID", prescription.ID)
  4079. if prescription.ID > 0 {
  4080. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4081. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4082. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4083. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4084. record.UltrafiltrationRate = ultrafiltration_rate
  4085. }
  4086. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4087. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4088. record.UltrafiltrationRate = ultrafiltration_rate
  4089. }
  4090. if adminInfo.Org.Id == 10510 {
  4091. record.UltrafiltrationRate = 0
  4092. }
  4093. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4094. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4095. record.UltrafiltrationRate = ultrafiltration_rate
  4096. }
  4097. if template.TemplateId == 20 || template.TemplateId == 22 {
  4098. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4099. record.UltrafiltrationRate = ultrafiltration_rate
  4100. }
  4101. // 只针对方济医院
  4102. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4103. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4104. ultrafiltration_rate = value
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if template.TemplateId == 41 || template.TemplateId == 47 {
  4108. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if template.TemplateId == 43 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. if template.TemplateId == 46 || template.TemplateId == 54 {
  4116. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. 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 {
  4120. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. if adminInfo.Org.Id == 10469 {
  4124. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate
  4126. }
  4127. if adminInfo.Org.Id == 10667 {
  4128. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate
  4130. }
  4131. if adminInfo.Org.Id == 10471 {
  4132. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4134. }
  4135. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4137. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4138. }
  4139. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4140. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4141. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4142. }
  4143. if adminInfo.Org.Id == 10721 {
  4144. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4145. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4146. }
  4147. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4148. record.UltrafiltrationRate = 0
  4149. }
  4150. //if template.TemplateId == 47 {
  4151. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4152. // record.UltrafiltrationRate = ultrafiltration_rate
  4153. //}
  4154. }
  4155. }
  4156. // record.UltrafiltrationRate = ultrafiltration_rate
  4157. record.UltrafiltrationVolume = 0
  4158. 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
  4159. if ultrafiltration_rate > 0 {
  4160. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4161. record.UltrafiltrationVolume = value
  4162. }
  4163. }
  4164. 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
  4165. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4166. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4167. record.UltrafiltrationVolume = ultrafiltration_volume
  4168. }
  4169. }
  4170. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4171. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4172. record.UltrafiltrationVolume = ultrafiltration_volume
  4173. }
  4174. //长沙南雅
  4175. 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 {
  4176. if ultrafiltration_rate > 0 {
  4177. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4178. record.UltrafiltrationVolume = ultrafiltration_volume
  4179. }
  4180. }
  4181. if adminInfo.Org.Id == 10471 {
  4182. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4183. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4184. }
  4185. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4186. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4187. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4188. }
  4189. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4190. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4191. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4192. }
  4193. //长沙南雅累计血容量自动计算
  4194. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4195. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4196. //}
  4197. if template.TemplateId == 47 || template.TemplateId == 54 {
  4198. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4199. }
  4200. if adminInfo.Org.Id == 10510 {
  4201. record.UltrafiltrationVolume = 0
  4202. }
  4203. if adminInfo.Org.Id == 10721 {
  4204. if ultrafiltration_rate > 0 {
  4205. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4206. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4207. }
  4208. }
  4209. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4210. this.ServeSuccessJSON(map[string]interface{}{
  4211. "monitor": record,
  4212. "lastMonitorRecordList": lastMonitorRecordList,
  4213. })
  4214. }
  4215. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4216. record_id, _ := this.GetInt64("id")
  4217. nurseID, _ := this.GetInt64("start_nurse")
  4218. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4219. bedID, _ := this.GetInt64("bed")
  4220. start_time := this.GetString("start_time")
  4221. schedual_type, _ := this.GetInt64("schedual_type")
  4222. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4223. change_nurse, _ := this.GetInt64("change_nurse")
  4224. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4225. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4226. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4227. patient_id, _ := this.GetInt64("patient_id")
  4228. record_date, _ := this.GetInt64("record_date")
  4229. puncture_needle := this.GetString("puncture_needle")
  4230. puncture_way := this.GetString("puncture_way")
  4231. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4232. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4233. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4234. nuclein_date_str := this.GetString("nuclein_date_str")
  4235. order_remark := this.GetString("order_remark")
  4236. schedule_remark := this.GetString("schedule_remark")
  4237. catheter_operation := this.GetString("catheter_operation")
  4238. blood_flow_volume := this.GetString("blood_flow_volume")
  4239. blood_drawing, _ := this.GetInt64("blood_drawing")
  4240. dialysis_strainer := this.GetString("dialysis_strainer")
  4241. if record_id == 0 {
  4242. this.ErrorLog("id:%v", record_id)
  4243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4244. return
  4245. }
  4246. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4247. if parseStartDateErr != nil {
  4248. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4250. return
  4251. }
  4252. adminUserInfo := this.GetMobileAdminUserInfo()
  4253. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4254. if getNurseErr != nil {
  4255. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4257. return
  4258. } else if nurse == nil {
  4259. this.ErrorLog("护士不存在")
  4260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4261. return
  4262. }
  4263. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4264. //if getNurseErr != nil {
  4265. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4266. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4267. // return
  4268. //} else if nurse == nil {
  4269. // this.ErrorLog("护士不存在")
  4270. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4271. // return
  4272. //}
  4273. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4274. if getDeviceNumberErr != nil {
  4275. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4277. return
  4278. } else if deviceNumber == nil {
  4279. this.ErrorLog("床位号不存在")
  4280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4281. return
  4282. }
  4283. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4284. //
  4285. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4286. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4287. // if getPermissionErr != nil {
  4288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4289. // return
  4290. // } else if headNursePermission == nil {
  4291. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4292. // return
  4293. // }
  4294. //}
  4295. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4296. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4297. timeLayout := "2006-01-02 15:04:05"
  4298. loc, _ := time.LoadLocation("Local")
  4299. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4300. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4301. schedulestartTime := theStartTime.Unix()
  4302. scheduleendTime := theEndTime.Unix()
  4303. var theNucleinDate int64
  4304. timeLayoutOne := "2006-01-02"
  4305. if len(nuclein_date_str) > 0 {
  4306. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4307. if err != nil {
  4308. utils.ErrorLog(err.Error())
  4309. }
  4310. theNucleinDate = theTime.Unix()
  4311. }
  4312. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4313. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4314. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4315. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4316. if err == gorm.ErrRecordNotFound { //空床位
  4317. // 修改了床位逻辑
  4318. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4319. if daySchedule.ID > 0 {
  4320. //daySchedule.BedId = bedID
  4321. //daySchedule.PartitionId = deviceNumber.ZoneID
  4322. //daySchedule.ScheduleType = schedual_type
  4323. //daySchedule.UpdatedTime = time.Now().Unix()
  4324. //err := service.UpdateSchedule(&daySchedule)
  4325. xtSchedule := models.Schedule{
  4326. PartitionId: deviceNumber.ZoneID,
  4327. BedId: bedID,
  4328. ScheduleType: schedual_type,
  4329. UpdatedTime: time.Now().Unix(),
  4330. }
  4331. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4332. if err != nil {
  4333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4334. return
  4335. }
  4336. }
  4337. } else if err == nil {
  4338. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4339. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4340. if daySchedule.ID > 0 {
  4341. //daySchedule.BedId = bedID
  4342. //daySchedule.PartitionId = deviceNumber.ZoneID
  4343. //
  4344. //daySchedule.ScheduleType = schedual_type
  4345. //daySchedule.UpdatedTime = time.Now().Unix()
  4346. //err := service.UpdateSchedule(&daySchedule)
  4347. xtSchedule := models.Schedule{
  4348. PartitionId: deviceNumber.ZoneID,
  4349. BedId: bedID,
  4350. ScheduleType: schedual_type,
  4351. UpdatedTime: time.Now().Unix(),
  4352. }
  4353. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4354. if err != nil {
  4355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4356. return
  4357. }
  4358. }
  4359. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4361. return
  4362. }
  4363. } else if err != nil {
  4364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4365. return
  4366. }
  4367. }
  4368. dialysisRecord := &models.DialysisOrder{
  4369. ID: record_id,
  4370. UserOrgId: adminUserInfo.Org.Id,
  4371. BedID: bedID,
  4372. StartNurse: nurseID,
  4373. StartTime: startDate.Unix(),
  4374. PunctureNurse: puncture_nurse,
  4375. Creator: adminUserInfo.AdminUser.Id,
  4376. Modifier: adminUserInfo.AdminUser.Id,
  4377. WashpipeNurse: washpipe_nurse,
  4378. SchedualType: schedual_type,
  4379. ChangeNurse: change_nurse,
  4380. DifficultPunctureNurse: difficult_puncture_nurse,
  4381. NewFistulaNurse: new_fistula_nurse,
  4382. QualityNurseId: quality_nurse_id,
  4383. PunctureNeedle: puncture_needle,
  4384. PunctureWay: puncture_way,
  4385. DialysisDialyszers: dialysis_dialyszers,
  4386. DialysisIrrigation: dialysis_irrigation,
  4387. BloodAccessId: blood_access_id,
  4388. NucleinDate: theNucleinDate,
  4389. OrderRemark: order_remark,
  4390. ScheduleRemark: schedule_remark,
  4391. CatheterOperation: catheter_operation,
  4392. BloodFlowVolume: blood_flow_volume,
  4393. BloodDrawing: blood_drawing,
  4394. DialysisStrainer: dialysis_strainer,
  4395. }
  4396. //修改床位号需要重新消毒
  4397. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4398. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4399. //查询第一条监测
  4400. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4401. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4402. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4403. redis := service.RedisClient()
  4404. //清空key 值
  4405. redis.Set(key, "", time.Second)
  4406. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4407. redis.Set(keyOne, "", time.Second)
  4408. defer redis.Close()
  4409. }
  4410. // 查询信息规挡的设置天数
  4411. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4412. if infor.ID > 0 && infor.WeekDay > 0 {
  4413. var cha_time int64
  4414. timeNowStr := time.Now().Format("2006-01-02")
  4415. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4416. //今日的日期减去设置的日期
  4417. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4418. if cha_time >= record_date {
  4419. //查询审核是否允许
  4420. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4421. //申请状态不允许的情况 拒绝修改
  4422. if infor.ApplicationStatus != 1 {
  4423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4424. return
  4425. }
  4426. }
  4427. }
  4428. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4429. //修改床位后重新生成消毒计划
  4430. if adminUserInfo.Org.Id == 10340 {
  4431. //根据床位号获取设备型号
  4432. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4433. //查询使用消毒最后一条消毒记录
  4434. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4435. fmt.Println("err", err)
  4436. if err == gorm.ErrRecordNotFound {
  4437. //查找排班
  4438. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4439. //查询改设备是否有消毒计划
  4440. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4441. //根据床位号获取设备id
  4442. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4443. //查询病人信息
  4444. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4445. var con = ""
  4446. if patients.IsInfectious == 0 {
  4447. con = ""
  4448. }
  4449. if patients.IsInfectious == 1 {
  4450. con = "无"
  4451. }
  4452. if patients.IsInfectious == 2 {
  4453. con = "有"
  4454. }
  4455. if errcode == nil {
  4456. var end_time int64
  4457. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4458. //新增消毒
  4459. information := models.DeviceInformation{
  4460. Date: dialysisRecord.DialysisDate,
  4461. Zone: dialysisRecord.ZoneId,
  4462. Class: dialysisRecord.SchedualType,
  4463. BedNumber: dialysisRecord.BedID,
  4464. PatientId: dialysisRecord.PatientId,
  4465. DialysisMode: scheduleByPatient.ModeId,
  4466. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4467. Disinfection: 1,
  4468. DialysisConcentration: 1,
  4469. DisinfectionStatus: 1,
  4470. Move: 1,
  4471. UserOrgId: dialysisRecord.UserOrgId,
  4472. DisinfectType: plan.Way,
  4473. DisinfectantType: plan.MachineDisinfectant,
  4474. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4475. Disinfectant: plan.Disinfectant,
  4476. Ctime: time.Now().Unix(),
  4477. Status: 1,
  4478. SignName: nurseID,
  4479. EquimentId: addmacher.ID,
  4480. DisinfectionResidue: 2,
  4481. Bed: addmacher.BedNumber,
  4482. StartTime: dialysisRecord.StartTime,
  4483. EndTime: dialysisRecord.EndTime,
  4484. Contagion: con,
  4485. WeightLoss: 0,
  4486. Hyperfiltratio: 0,
  4487. DialysisHour: "",
  4488. MachineRun: 1,
  4489. DisinfecStartime: dialysisRecord.EndTime,
  4490. DisinfecEndtime: end_time,
  4491. }
  4492. err := service.CreateInformationTwo(&information)
  4493. fmt.Println("报错", err)
  4494. }
  4495. }
  4496. }
  4497. order, _ := service.GetLastPatientOrder(record_id)
  4498. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4499. redis := service.RedisClient()
  4500. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4501. redis.Set(key, "", time.Second)
  4502. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4503. //清空key 值
  4504. redis.Set(keyOne, "", time.Second)
  4505. scheduleDateStartOne := startDate.Format("2006-01-02")
  4506. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4507. redis.Set(keyTwo, "", time.Second)
  4508. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4509. redis.Set(keyThree, "", time.Second)
  4510. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4511. redis.Set(keyFour, "", time.Second)
  4512. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4513. redis.Set(keyFive, "", time.Second)
  4514. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4515. redis.Set(keySix, "", time.Second)
  4516. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4517. redis.Set(keySeven, "", time.Second)
  4518. if updateErr != nil {
  4519. this.ErrorLog("修改上机失败:%v", updateErr)
  4520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4521. return
  4522. }
  4523. if updateErr == nil {
  4524. if tempDialysisRecord.Stage == 2 {
  4525. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4526. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4527. fmt.Println(value)
  4528. a, b := math.Modf(value)
  4529. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4530. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4531. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4532. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4533. redis := service.RedisClient()
  4534. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4535. redis.Set(key, "", time.Second)
  4536. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4537. redis.Set(keyOne, "", time.Second)
  4538. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4539. //清空key 值
  4540. redis.Set(keySix, "", time.Second)
  4541. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4542. redis.Set(keySeven, "", time.Second)
  4543. redis.Close()
  4544. if updateAssessmentErr != nil {
  4545. utils.ErrorLog("%v", updateAssessmentErr)
  4546. }
  4547. }
  4548. }
  4549. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4550. this.ServeSuccessJSON(map[string]interface{}{
  4551. "dialysis_order": dialysisRecords,
  4552. })
  4553. }
  4554. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4555. record_id, _ := c.GetInt64("id")
  4556. nurseID, _ := c.GetInt64("nurse")
  4557. end_time := c.GetString("end_time")
  4558. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4559. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4560. catheter := c.GetString("catheter")
  4561. cruor := c.GetString("cruor")
  4562. mission := c.GetString("mission")
  4563. condenser := c.GetString("condenser")
  4564. if record_id <= 0 || nurseID <= 0 {
  4565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4566. return
  4567. }
  4568. adminUserInfo := c.GetMobileAdminUserInfo()
  4569. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4570. if getNurseErr != nil {
  4571. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4573. return
  4574. } else if nurse == nil {
  4575. c.ErrorLog("护士不存在")
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4577. return
  4578. }
  4579. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4580. if parseEndDateErr != nil {
  4581. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4583. return
  4584. }
  4585. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4586. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4587. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4588. // if getPermissionErr != nil {
  4589. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4590. // return
  4591. // } else if headNursePermission == nil {
  4592. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4593. // return
  4594. // }
  4595. //}
  4596. // 查询信息规挡的设置天数
  4597. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4598. if infor.ID > 0 {
  4599. var cha_time int64
  4600. timeNowStr := time.Now().Format("2006-01-02")
  4601. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4602. //今日的日期减去设置的日期
  4603. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4604. if cha_time >= tempDialysisRecords.DialysisDate {
  4605. //查询审核是否允许
  4606. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4607. //申请状态不允许的情况 拒绝修改
  4608. if infor.ApplicationStatus != 1 {
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4610. return
  4611. }
  4612. }
  4613. }
  4614. dialysisRecord := &models.DialysisOrder{
  4615. ID: record_id,
  4616. UserOrgId: adminUserInfo.Org.Id,
  4617. EndTime: endDate.Unix(),
  4618. FinishNurse: nurseID,
  4619. FinishModifier: adminUserInfo.AdminUser.Id,
  4620. PuncturePointHaematoma: puncture_point_haematoma,
  4621. BloodAccessInternalFistula: blood_access_internal_fistula,
  4622. Catheter: catheter,
  4623. Cruor: cruor,
  4624. Mission: mission,
  4625. Condenser: condenser,
  4626. }
  4627. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4628. redis := service.RedisClient()
  4629. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4630. //清空key 值
  4631. redis.Set(key, "", time.Second)
  4632. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4633. //清空key 值
  4634. redis.Set(keyOne, "", time.Second)
  4635. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4636. redis.Set(keySeven, "", time.Second)
  4637. redis.Close()
  4638. if updateErr != nil {
  4639. c.ErrorLog("修改下机失败:%v", updateErr)
  4640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4641. return
  4642. }
  4643. if updateErr == nil {
  4644. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4645. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4646. a, b := math.Modf(value)
  4647. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4648. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4649. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4650. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4651. redis := service.RedisClient()
  4652. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4653. redis.Set(keyTen, "", time.Second)
  4654. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4655. redis.Set(keyTwo, "", time.Second)
  4656. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4657. redis.Set(key, "", time.Second)
  4658. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4659. redis.Set(keyThree, "", time.Second)
  4660. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4661. redis.Set(keySeven, "", time.Second)
  4662. defer redis.Close()
  4663. if updateAssessmentErr != nil {
  4664. utils.ErrorLog("%v", updateAssessmentErr)
  4665. }
  4666. }
  4667. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4668. c.ServeSuccessJSON(map[string]interface{}{
  4669. "dialysis_order": dialysisRecords,
  4670. })
  4671. }
  4672. func (c *DialysisAPIController) GetLongAdvice() {
  4673. patient_id, _ := c.GetInt64("id")
  4674. adminUserInfo := c.GetMobileAdminUserInfo()
  4675. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4676. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4677. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4678. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4679. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4680. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4681. c.ServeSuccessJSON(map[string]interface{}{
  4682. "status": "1",
  4683. })
  4684. return
  4685. } else { //开启推送提醒
  4686. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4687. var advice_three []*models.DoctorAdvice
  4688. recordDateStr := time.Now().Format("2006-01-02")
  4689. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4690. nowtime := recordDate.Unix()
  4691. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4692. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4693. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4694. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4695. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4696. for _, advice := range advices {
  4697. if advice.FrequencyType == 3 {
  4698. t := time.Now()
  4699. week := int(t.Weekday())
  4700. fmt.Println(t.Weekday())
  4701. fmt.Println(week)
  4702. switch week {
  4703. case 1:
  4704. if strings.Index(advice.WeekDay, "周一") == -1 {
  4705. advice_three = append(advice_three, advice)
  4706. }
  4707. break
  4708. case 2:
  4709. if strings.Index(advice.WeekDay, "周二") == -1 {
  4710. advice_three = append(advice_three, advice)
  4711. }
  4712. break
  4713. case 3:
  4714. if strings.Index(advice.WeekDay, "周三") == -1 {
  4715. advice_three = append(advice_three, advice)
  4716. }
  4717. break
  4718. case 4:
  4719. if strings.Index(advice.WeekDay, "周四") == -1 {
  4720. advice_three = append(advice_three, advice)
  4721. }
  4722. break
  4723. case 5:
  4724. if strings.Index(advice.WeekDay, "周五") == -1 {
  4725. advice_three = append(advice_three, advice)
  4726. }
  4727. break
  4728. case 6:
  4729. if strings.Index(advice.WeekDay, "周六") == -1 {
  4730. advice_three = append(advice_three, advice)
  4731. }
  4732. break
  4733. case 0:
  4734. if strings.Index(advice.WeekDay, "周日") == -1 {
  4735. advice_three = append(advice_three, advice)
  4736. }
  4737. break
  4738. }
  4739. }
  4740. }
  4741. for _, advice := range advices_two {
  4742. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4743. now := p.Unix()
  4744. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4745. dayStr2 := "-" + dayStr
  4746. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4747. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4748. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4749. for _, ad := range advices {
  4750. advice_three = append(advice_three, ad)
  4751. }
  4752. }
  4753. if err == nil {
  4754. c.ServeSuccessJSON(map[string]interface{}{
  4755. "status": "2",
  4756. "advices": advices,
  4757. "advices_two": RemoveRepeatedElement(advice_three),
  4758. "is_open_remind": config.IsOpenRemind,
  4759. "his_config_open": hisConfig.IsOpen,
  4760. "is_advice_open": is_advice_open.IsAdviceOpen,
  4761. "prescription_open": prescription_open.IsOpen,
  4762. })
  4763. }
  4764. }
  4765. }
  4766. func (c *DialysisAPIController) GetLongAdviceOne() {
  4767. patient_id, _ := c.GetInt64("id")
  4768. startTime := c.GetString("schedule_date")
  4769. timeLayout := "2006-01-02"
  4770. loc, _ := time.LoadLocation("Local")
  4771. var theStartTime int64
  4772. if len(startTime) > 0 {
  4773. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4774. if err != nil {
  4775. utils.ErrorLog(err.Error())
  4776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4777. return
  4778. }
  4779. theStartTime = theTime.Unix()
  4780. }
  4781. adminUserInfo := c.GetMobileAdminUserInfo()
  4782. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4783. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4784. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4785. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4786. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4787. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4788. c.ServeSuccessJSON(map[string]interface{}{
  4789. "status": "1",
  4790. })
  4791. return
  4792. } else { //开启推送提醒
  4793. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4794. var advice_three []*models.DoctorAdvice
  4795. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4796. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4797. for _, advice := range advices {
  4798. if advice.FrequencyType == 3 {
  4799. t := time.Now()
  4800. week := int(t.Weekday())
  4801. fmt.Println(t.Weekday())
  4802. fmt.Println(week)
  4803. switch week {
  4804. case 1:
  4805. if strings.Index(advice.WeekDay, "周一") == -1 {
  4806. advice_three = append(advice_three, advice)
  4807. }
  4808. break
  4809. case 2:
  4810. if strings.Index(advice.WeekDay, "周二") == -1 {
  4811. advice_three = append(advice_three, advice)
  4812. }
  4813. break
  4814. case 3:
  4815. if strings.Index(advice.WeekDay, "周三") == -1 {
  4816. advice_three = append(advice_three, advice)
  4817. }
  4818. break
  4819. case 4:
  4820. if strings.Index(advice.WeekDay, "周四") == -1 {
  4821. advice_three = append(advice_three, advice)
  4822. }
  4823. break
  4824. case 5:
  4825. if strings.Index(advice.WeekDay, "周五") == -1 {
  4826. advice_three = append(advice_three, advice)
  4827. }
  4828. break
  4829. case 6:
  4830. if strings.Index(advice.WeekDay, "周六") == -1 {
  4831. advice_three = append(advice_three, advice)
  4832. }
  4833. break
  4834. case 0:
  4835. if strings.Index(advice.WeekDay, "周日") == -1 {
  4836. advice_three = append(advice_three, advice)
  4837. }
  4838. break
  4839. }
  4840. }
  4841. }
  4842. for _, advice := range advices_two {
  4843. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4844. now := p.Unix()
  4845. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4846. dayStr2 := "-" + dayStr
  4847. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4848. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4849. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4850. for _, ad := range advices {
  4851. advice_three = append(advice_three, ad)
  4852. }
  4853. }
  4854. if err == nil {
  4855. c.ServeSuccessJSON(map[string]interface{}{
  4856. "status": "2",
  4857. "advices": advices,
  4858. "advices_two": RemoveRepeatedElement(advice_three),
  4859. "is_open_remind": config.IsOpenRemind,
  4860. "his_config_open": hisConfig.IsOpen,
  4861. "is_advice_open": is_advice_open.IsAdviceOpen,
  4862. "prescription_open": prescription_open.IsOpen,
  4863. })
  4864. }
  4865. }
  4866. }
  4867. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4868. newArr = make([]*models.DoctorAdvice, 0)
  4869. for i := 0; i < len(arr); i++ {
  4870. repeat := false
  4871. for j := i + 1; j < len(arr); j++ {
  4872. if arr[i].ID == arr[j].ID {
  4873. repeat = true
  4874. break
  4875. }
  4876. }
  4877. if !repeat {
  4878. newArr = append(newArr, arr[i])
  4879. }
  4880. }
  4881. return
  4882. }
  4883. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4884. patient, _ := c.GetInt64("id", 0)
  4885. groupNo, _ := c.GetInt64("groupno", 0)
  4886. if patient <= 0 {
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. adminUserInfo := c.GetMobileAdminUserInfo()
  4891. dataBody := make(map[string]interface{}, 0)
  4892. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4893. if err != nil {
  4894. utils.ErrorLog(err.Error())
  4895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4896. return
  4897. }
  4898. utils.ErrorLog("%v", dataBody)
  4899. timeLayout := "2006-01-02 15:04"
  4900. loc, _ := time.LoadLocation("Local")
  4901. timeLayout2 := "2006-01-02"
  4902. loc2, _ := time.LoadLocation("Local")
  4903. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4904. utils.ErrorLog("advice_type")
  4905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4906. return
  4907. }
  4908. adviceType := int64(2)
  4909. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4910. utils.ErrorLog("advice_date")
  4911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4912. return
  4913. }
  4914. adviceDate, _ := dataBody["advice_date"].(string)
  4915. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4916. AdviceDate := theTime.Unix()
  4917. RecordDate := theTime.Unix()
  4918. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4919. utils.ErrorLog("start_time")
  4920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4921. return
  4922. }
  4923. startTime, _ := dataBody["start_time"].(string)
  4924. if len(startTime) == 0 {
  4925. utils.ErrorLog("len(start_time) == 0")
  4926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4927. return
  4928. }
  4929. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4930. if err != nil {
  4931. utils.ErrorLog(err.Error())
  4932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4933. return
  4934. }
  4935. StartTime := theTime.Unix()
  4936. Remark := ""
  4937. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4938. remark, _ := dataBody["remark"].(string)
  4939. Remark = remark
  4940. }
  4941. var advices []*models.GroupAdvice
  4942. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4943. utils.ErrorLog("advices")
  4944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4945. return
  4946. }
  4947. adviceNames := dataBody["advices"].([]interface{})
  4948. for _, adviceNameMap := range adviceNames {
  4949. adviceNameM := adviceNameMap.(map[string]interface{})
  4950. var advice models.GroupAdvice
  4951. advice.Remark = Remark
  4952. advice.AdviceType = adviceType
  4953. advice.StartTime = StartTime
  4954. advice.AdviceDate = AdviceDate
  4955. advice.RecordDate = RecordDate
  4956. advice.Status = 1
  4957. advice.CreatedTime = time.Now().Unix()
  4958. advice.UpdatedTime = time.Now().Unix()
  4959. advice.StopState = 2
  4960. advice.ExecutionState = 2
  4961. advice.UserOrgId = adminUserInfo.Org.Id
  4962. advice.PatientId = patient
  4963. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4964. advice.IsSettle = 2
  4965. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4966. utils.ErrorLog("advice_name")
  4967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4968. return
  4969. }
  4970. adviceName, _ := adviceNameM["advice_name"].(string)
  4971. if len(adviceName) == 0 {
  4972. utils.ErrorLog("len(advice_name) == 0")
  4973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4974. return
  4975. }
  4976. advice.AdviceName = adviceName
  4977. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4978. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4979. advice.DrugSpec = drugSpec
  4980. }
  4981. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4982. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4983. advice.AdviceDesc = adviceDesc
  4984. }
  4985. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4986. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4987. advice.DrugSpecUnit = drugSpecUnit
  4988. }
  4989. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4990. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4991. // advice.SingleDose = singleDose
  4992. //}
  4993. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4994. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4995. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4996. }
  4997. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4998. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4999. advice.SingleDoseUnit = singleDoseUnit
  5000. }
  5001. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5002. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5003. // advice.PrescribingNumber = prescribingNumber
  5004. //}
  5005. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5006. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5007. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5008. }
  5009. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5010. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5011. advice.PrescribingNumberUnit = prescribingNumberUnit
  5012. }
  5013. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5014. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5015. advice.DeliveryWay = deliveryWay
  5016. }
  5017. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5018. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5019. advice.ExecutionFrequency = executionFrequency
  5020. }
  5021. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5022. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5023. advice.FrequencyType = frequency_type
  5024. }
  5025. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5026. day_count := int64(adviceNameM["day_count"].(float64))
  5027. advice.DayCount = day_count
  5028. }
  5029. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5030. week_day, _ := adviceNameM["week_day"].(string)
  5031. advice.WeekDay = week_day
  5032. }
  5033. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5034. way := int64(adviceNameM["way"].(float64))
  5035. advice.Way = way
  5036. }
  5037. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5038. drug_id := int64(adviceNameM["drug_id"].(float64))
  5039. advice.DrugId = drug_id
  5040. }
  5041. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5042. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5043. advice.DrugNameId = drug_name_id
  5044. }
  5045. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5046. remark, _ := adviceNameM["remark"].(string)
  5047. advice.Remark = remark
  5048. }
  5049. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5050. groupno := int64(adviceNameM["groupno"].(float64))
  5051. advice.GroupNo = groupno
  5052. }
  5053. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5054. template_id, _ := adviceNameM["template_id"].(string)
  5055. advice.TemplateId = template_id
  5056. }
  5057. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5058. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5059. advice.ExecutionFrequency = executionFrequency
  5060. }
  5061. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5062. children := adviceNameM["child"].([]interface{})
  5063. if len(children) > 0 {
  5064. for _, childrenMap := range children {
  5065. childMap := childrenMap.(map[string]interface{})
  5066. var child models.GroupAdvice
  5067. child.Remark = Remark
  5068. child.AdviceType = adviceType
  5069. child.StartTime = StartTime
  5070. child.AdviceDate = AdviceDate
  5071. child.RecordDate = RecordDate
  5072. child.Status = 1
  5073. child.CreatedTime = time.Now().Unix()
  5074. child.UpdatedTime = time.Now().Unix()
  5075. child.StopState = 2
  5076. child.ExecutionState = 2
  5077. child.UserOrgId = adminUserInfo.Org.Id
  5078. child.PatientId = patient
  5079. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5080. child.IsSettle = 1
  5081. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5082. utils.ErrorLog("child advice_name")
  5083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5084. return
  5085. }
  5086. childAdviceName, _ := childMap["advice_name"].(string)
  5087. if len(childAdviceName) == 0 {
  5088. utils.ErrorLog("len(child advice_name) == 0")
  5089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5090. return
  5091. }
  5092. child.AdviceName = childAdviceName
  5093. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5094. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5095. child.AdviceDesc = childAdviceDesc
  5096. }
  5097. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5098. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5099. child.DrugSpec = childDrugSpec
  5100. }
  5101. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5102. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5103. child.DrugSpecUnit = childDrugSpecUnit
  5104. }
  5105. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5106. child.SingleDose = childMap["single_dose"].(float64)
  5107. }
  5108. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5109. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5110. child.SingleDoseUnit = childSingleDoseUnit
  5111. }
  5112. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5113. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5114. }
  5115. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5116. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5117. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5118. }
  5119. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5120. groupno := int64(childMap["groupno"].(float64))
  5121. advice.GroupNo = groupno
  5122. }
  5123. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5124. remark, _ := childMap["remark"].(string)
  5125. child.Remark = remark
  5126. }
  5127. child.DeliveryWay = advice.DeliveryWay
  5128. child.ExecutionFrequency = advice.ExecutionFrequency
  5129. advice.Children = append(advice.Children, &child)
  5130. }
  5131. }
  5132. }
  5133. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5134. if temp_advice.ID == 0 {
  5135. advices = append(advices, &advice)
  5136. }
  5137. }
  5138. if len(advices) > 0 {
  5139. finish := models.XtDialysisFinish{
  5140. IsFinish: 1,
  5141. UserOrgId: adminUserInfo.Org.Id,
  5142. Status: 1,
  5143. Ctime: time.Now().Unix(),
  5144. Mtime: 0,
  5145. Module: 4,
  5146. RecordDate: AdviceDate,
  5147. Sourse: 1,
  5148. PatientId: patient,
  5149. }
  5150. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5151. if dialysisFinish.ID == 0 {
  5152. service.CreateDialysisFinish(finish)
  5153. }
  5154. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5155. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5156. for _, item := range advices {
  5157. byterequest, _ := json.Marshal(item)
  5158. adviceLog := models.XtDoctorAdviceLog{
  5159. UserOrgId: adminUserInfo.Org.Id,
  5160. PatientId: patient,
  5161. AdminUserId: adminUserInfo.AdminUser.Id,
  5162. Module: 1,
  5163. ErrLog: string(byterequest),
  5164. Status: 1,
  5165. Ctime: time.Now().Unix(),
  5166. Mtime: 0,
  5167. Source: "手机端医嘱推送",
  5168. RecordDate: item.AdviceDate,
  5169. }
  5170. service.CreateDoctorAdviceLog(adviceLog)
  5171. }
  5172. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5173. redis := service.RedisClient()
  5174. //清空key 值
  5175. redis.Set(key, "", time.Second)
  5176. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5177. redis.Set(keyOne, "", time.Second)
  5178. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5179. defer redis.Close()
  5180. redis.Set(keyThree, "", time.Second)
  5181. if err != nil {
  5182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5183. return
  5184. }
  5185. c.ServeSuccessJSON(map[string]interface{}{
  5186. "msg": "ok",
  5187. "advices": list,
  5188. })
  5189. } else {
  5190. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5191. for _, item := range advices {
  5192. byterequest, _ := json.Marshal(item)
  5193. adviceLog := models.XtDoctorAdviceLog{
  5194. UserOrgId: adminUserInfo.Org.Id,
  5195. PatientId: patient,
  5196. AdminUserId: adminUserInfo.AdminUser.Id,
  5197. Module: 1,
  5198. ErrLog: string(byterequest),
  5199. Status: 1,
  5200. Ctime: time.Now().Unix(),
  5201. Mtime: 0,
  5202. Source: "手机端医嘱推送",
  5203. RecordDate: item.AdviceDate,
  5204. }
  5205. service.CreateDoctorAdviceLog(adviceLog)
  5206. }
  5207. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5208. redis := service.RedisClient()
  5209. //清空key 值
  5210. redis.Set(key, "", time.Second)
  5211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5212. redis.Set(keyOne, "", time.Second)
  5213. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5214. defer redis.Close()
  5215. redis.Set(keyThree, "", time.Second)
  5216. if err != nil {
  5217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5218. return
  5219. }
  5220. c.ServeSuccessJSON(map[string]interface{}{
  5221. "msg": "ok",
  5222. "advices": list,
  5223. })
  5224. }
  5225. } else {
  5226. c.ServeSuccessJSON(map[string]interface{}{
  5227. "msg": "ok",
  5228. })
  5229. }
  5230. return
  5231. }
  5232. func (c *DialysisAPIController) UploadDryWeight() {
  5233. patient_id, _ := c.GetInt64("id")
  5234. dry_weight, _ := c.GetFloat("dry_weight")
  5235. doctor_id, _ := c.GetInt64("doctor_id")
  5236. remark := c.GetString("remark")
  5237. adminUserInfo := c.GetMobileAdminUserInfo()
  5238. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5239. if err == gorm.ErrRecordNotFound {
  5240. dryWeight := &models.SgjPatientDryweight{
  5241. PatientId: patient_id,
  5242. DryWeight: dry_weight,
  5243. Remakes: remark,
  5244. Ctime: time.Now().Unix(),
  5245. Mtime: time.Now().Unix(),
  5246. Creator: doctor_id,
  5247. Status: 1,
  5248. UserOrgId: adminUserInfo.Org.Id,
  5249. AdjustedValue: "/",
  5250. UserId: adminUserInfo.AdminUser.Id,
  5251. }
  5252. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5253. redis := service.RedisClient()
  5254. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5255. redis.Set(keyOne, "", time.Second)
  5256. loc, _ := time.LoadLocation("Local")
  5257. nowTime := time.Now()
  5258. nowDay := nowTime.Format("2006-01-02")
  5259. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5260. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5261. redis.Set(key, "", time.Second)
  5262. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5263. redis.Set(keyTwo, "", time.Second)
  5264. redis.Close()
  5265. if createErr == nil {
  5266. c.ServeSuccessJSON(map[string]interface{}{
  5267. "msg": "提交成功",
  5268. "weight": dryWeight,
  5269. })
  5270. }
  5271. } else {
  5272. dryWeight := &models.SgjPatientDryweight{
  5273. PatientId: patient_id,
  5274. DryWeight: dry_weight,
  5275. Remakes: remark,
  5276. Ctime: time.Now().Unix(),
  5277. Mtime: time.Now().Unix(),
  5278. Creator: doctor_id,
  5279. Status: 1,
  5280. UserOrgId: adminUserInfo.Org.Id,
  5281. AdjustedValue: "/",
  5282. UserId: adminUserInfo.AdminUser.Id,
  5283. }
  5284. var value float64
  5285. value = dry_weight - weightAdjust.DryWeight
  5286. if value < 0 {
  5287. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5288. } else if value == 0 {
  5289. dryWeight.AdjustedValue = "/"
  5290. } else if value > 0 {
  5291. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5292. }
  5293. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5294. //康桥
  5295. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 {
  5296. timeNowStr := time.Now().Format("2006-01-02")
  5297. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5298. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5299. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5300. if beforAssesment.ID > 0 {
  5301. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5302. var dewater_amount float64
  5303. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5304. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5305. //获取key,清空redis
  5306. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5307. redis := service.RedisClient()
  5308. //清空key 值
  5309. redis.Set(key, "", time.Second)
  5310. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5311. //清空key 值
  5312. redis.Set(keyOne, "", time.Second)
  5313. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5314. //清空key 值
  5315. redis.Set(keyTwo, "", time.Second)
  5316. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5317. redis.Set(keySix, "", time.Second)
  5318. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5319. redis.Set(keySeven, "", time.Second)
  5320. }
  5321. }
  5322. redis := service.RedisClient()
  5323. loc, _ := time.LoadLocation("Local")
  5324. nowTime := time.Now()
  5325. nowDay := nowTime.Format("2006-01-02")
  5326. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5327. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5328. redis.Set(keyOne, "", time.Second)
  5329. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5330. redis.Set(key, "", time.Second)
  5331. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5332. redis.Set(keyTwo, "", time.Second)
  5333. redis.Close()
  5334. if createErr == nil {
  5335. c.ServeSuccessJSON(map[string]interface{}{
  5336. "msg": "提交成功",
  5337. "weight": dryWeight,
  5338. })
  5339. }
  5340. }
  5341. }
  5342. func (c *DialysisAPIController) GetSolution() {
  5343. patient_id, _ := c.GetInt64("patient_id")
  5344. mode_id, _ := c.GetInt64("mode_id")
  5345. adminUserInfo := c.GetMobileAdminUserInfo()
  5346. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5347. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5348. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5349. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5350. if err != nil {
  5351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5352. return
  5353. }
  5354. c.ServeSuccessJSON(map[string]interface{}{
  5355. "solution": solution,
  5356. "prescription": prescription,
  5357. "system_prescription": system_prescription,
  5358. "dialysisPrescription": dialysisPrescription,
  5359. })
  5360. }
  5361. func (c *DialysisAPIController) GetSchedule() {
  5362. schedual_type, _ := c.GetInt64("schedual_type")
  5363. adminUserInfo := c.GetMobileAdminUserInfo()
  5364. scheduleTime, _ := c.GetInt64("record_date")
  5365. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5366. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5367. c.ServeSuccessJSON(map[string]interface{}{
  5368. "number": deviceNumber,
  5369. "list": list,
  5370. })
  5371. }
  5372. func (c *DialysisAPIController) GetPatientId() {
  5373. id, _ := c.GetInt64("id")
  5374. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5375. patientId, _ := service.GetPatientId(id)
  5376. //获取该患者的所有传染病
  5377. list, _ := service.GetPatientInfectious(id)
  5378. c.ServeSuccessJSON(map[string]interface{}{
  5379. "patient": patientId,
  5380. "infectioulist": list,
  5381. })
  5382. }
  5383. func (this *DialysisAPIController) GetDialysisSchedule() {
  5384. schedualDate := this.GetString("date")
  5385. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5386. if parseDateErr != nil {
  5387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5388. return
  5389. }
  5390. adminInfo := this.GetMobileAdminUserInfo()
  5391. orgID := adminInfo.Org.Id
  5392. redis := service.RedisClient()
  5393. defer redis.Close()
  5394. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5395. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5396. if len(scheduals) > 0 {
  5397. //缓存数据
  5398. scheduals_json, err := json.Marshal(scheduals)
  5399. if err == nil {
  5400. redis.Set(key, scheduals_json, time.Second*30)
  5401. }
  5402. }
  5403. this.ServeSuccessJSON(map[string]interface{}{
  5404. "scheduals": scheduals,
  5405. })
  5406. }
  5407. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5408. change_type, _ := this.GetInt64("type", 0)
  5409. record_date := this.GetString("record_time")
  5410. patient_id, _ := this.GetInt64("patient_id", 0)
  5411. timeLayout := "2006-01-02"
  5412. loc, _ := time.LoadLocation("Local")
  5413. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5414. record_time := theAdviceRecordTime.Unix()
  5415. adminUserInfo := this.GetMobileAdminUserInfo()
  5416. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5417. if err == nil {
  5418. if len(advices) == 0 {
  5419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5420. return
  5421. } else {
  5422. this.ServeSuccessJSON(map[string]interface{}{
  5423. "advices": advices,
  5424. "schedule": sch,
  5425. })
  5426. return
  5427. }
  5428. } else {
  5429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5430. return
  5431. }
  5432. }
  5433. func (c *DialysisAPIController) CreateConsumables() {
  5434. record_date := c.GetString("record_time")
  5435. patient_id, _ := c.GetInt64("patient_id", 0)
  5436. active, _ := c.GetInt64("active")
  5437. adminUser := c.GetMobileAdminUserInfo()
  5438. timeLayout := "2006-01-02"
  5439. loc, _ := time.LoadLocation("Local")
  5440. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5441. record_time := theRecordTime.Unix()
  5442. // 查询信息规挡的设置天数
  5443. orgid := c.GetMobileAdminUserInfo().Org.Id
  5444. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5445. if infor.ID > 0 {
  5446. var cha_time int64
  5447. timeNowStr := time.Now().Format("2006-01-02")
  5448. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5449. //今日的日期减去设置的日期
  5450. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5451. if cha_time >= record_time {
  5452. //查询审核是否允许
  5453. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5454. //申请状态不允许的情况 拒绝修改
  5455. if infor.ApplicationStatus != 1 {
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5457. return
  5458. }
  5459. }
  5460. }
  5461. dataBody := make(map[string]interface{}, 0)
  5462. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5463. if err != nil {
  5464. utils.ErrorLog(err.Error())
  5465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5466. return
  5467. }
  5468. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5469. var beforePrepares []*models.DialysisBeforePrepareGoods
  5470. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5471. var dialysisBefor []*models.DialysisBeforePrepare
  5472. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5473. goods, _ := dataBody["goods"].([]interface{})
  5474. if len(goods) > 0 {
  5475. for _, item := range goods {
  5476. items := item.(map[string]interface{})
  5477. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5478. utils.ErrorLog("good_id")
  5479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5480. return
  5481. }
  5482. good_id := int64(items["good_id"].(float64))
  5483. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5484. utils.ErrorLog("good_type_id")
  5485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5486. return
  5487. }
  5488. good_type_id := int64(items["good_type_id"].(float64))
  5489. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5490. utils.ErrorLog("count")
  5491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5492. return
  5493. }
  5494. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5495. commdity_code := items["commdity_code"].(string)
  5496. fmt.Println("commdity", commdity_code)
  5497. prepareGoods := &models.DialysisBeforePrepareGoods{
  5498. GoodTypeId: good_type_id,
  5499. GoodId: good_id,
  5500. Count: count,
  5501. StorehouseId: houseConfig.StorehouseOutInfo,
  5502. }
  5503. beforePrepares = append(beforePrepares, prepareGoods)
  5504. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5505. GoodTypeId: good_type_id,
  5506. GoodId: good_id,
  5507. Count: count,
  5508. StorehouseId: houseConfig.StorehouseOutInfo,
  5509. }
  5510. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5511. prepare := &models.DialysisBeforePrepare{
  5512. GoodTypeId: good_type_id,
  5513. GoodId: good_id,
  5514. Count: count,
  5515. PatientId: patient_id,
  5516. RecordDate: record_time,
  5517. UserOrgId: adminUser.Org.Id,
  5518. Status: 1,
  5519. Ctime: time.Now().Unix(),
  5520. Creater: adminUser.AdminUser.Id,
  5521. CommdityCode: commdity_code,
  5522. StorehouseId: houseConfig.StorehouseOutInfo,
  5523. }
  5524. dialysisBefor = append(dialysisBefor, prepare)
  5525. }
  5526. }
  5527. //查询是否有库存
  5528. for _, item := range dialysisBefor {
  5529. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5530. if err == gorm.ErrRecordNotFound {
  5531. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5532. c.ServeSuccessJSON(map[string]interface{}{
  5533. "message": "1",
  5534. "good_name": goodObj.GoodName,
  5535. "specification_name": goodObj.SpecificationName,
  5536. })
  5537. return
  5538. }
  5539. if err != nil {
  5540. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5541. c.ServeSuccessJSON(map[string]interface{}{
  5542. "message": "1",
  5543. "good_name": goodObj.GoodName,
  5544. "specification_name": goodObj.SpecificationName,
  5545. })
  5546. return
  5547. }
  5548. }
  5549. //新增
  5550. if active == 1 && len(goods) > 0 {
  5551. for _, item := range dialysisBefor {
  5552. dialyPrepareOne := models.DialysisBeforePrepare{
  5553. GoodTypeId: item.GoodTypeId,
  5554. GoodId: item.GoodId,
  5555. PatientId: item.PatientId,
  5556. RecordDate: item.RecordDate,
  5557. UserOrgId: item.UserOrgId,
  5558. Count: item.Count,
  5559. Ctime: time.Now().Unix(),
  5560. Creater: item.Creater,
  5561. CommdityCode: item.CommdityCode,
  5562. Status: 1,
  5563. StorehouseId: houseConfig.StorehouseOutInfo,
  5564. }
  5565. //先清除再插入
  5566. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5567. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5568. //查询默认仓库
  5569. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5570. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5571. var total_count int64
  5572. for _, it := range stockList {
  5573. total_count += it.StockCount
  5574. }
  5575. //基础库插入数据
  5576. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5577. //更新库存
  5578. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5579. var flush_count int64
  5580. for _, it := range goodList {
  5581. flush_count += it.StockCount
  5582. }
  5583. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5584. }
  5585. if err == nil {
  5586. c.ServeSuccessJSON(map[string]interface{}{
  5587. "msg": "保存成功",
  5588. "message": "2",
  5589. })
  5590. return
  5591. } else {
  5592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5593. return
  5594. }
  5595. }
  5596. if len(beforePrepares) > 0 && active == 2 {
  5597. for _, item := range beforePrepares {
  5598. //1.查看该患者该耗材型号最后一次出库数量
  5599. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5600. //判断当前出库数量和最后一次出库数量的大小
  5601. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5602. if item.Count <= goodInfo.Count {
  5603. //退库
  5604. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5605. //查询今日出库数据
  5606. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5607. for _, it := range list {
  5608. prepare := models.DialysisBeforePrepare{
  5609. UserOrgId: it.OrgId,
  5610. PatientId: patient_id,
  5611. RecordDate: it.RecordTime,
  5612. GoodId: it.GoodId,
  5613. GoodTypeId: it.GoodTypeId,
  5614. Count: it.Count,
  5615. Ctime: time.Now().Unix(),
  5616. Creater: adminUser.AdminUser.Id,
  5617. Status: 1,
  5618. StorehouseId: houseConfig.StorehouseOutInfo,
  5619. }
  5620. //删除准备表数据
  5621. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5622. service.CreateDialysisBeforePrepareOne(&prepare)
  5623. }
  5624. }
  5625. var last_total int64
  5626. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5627. if item.Count >= goodInfo.Count {
  5628. //查询当前批次当前耗材最后一条出库数据
  5629. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5630. //计算当前出库和最后一次出库数据相差数据
  5631. last_total = item.Count - lastOutInfo.Count
  5632. //查询该批次剩余库存
  5633. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5634. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5635. if lastInfo.StockCount >= last_total {
  5636. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5637. //查询今日出库数据
  5638. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5639. for _, it := range list {
  5640. prepare := models.DialysisBeforePrepare{
  5641. UserOrgId: it.OrgId,
  5642. PatientId: patient_id,
  5643. RecordDate: it.RecordTime,
  5644. GoodId: it.GoodId,
  5645. GoodTypeId: it.GoodTypeId,
  5646. Count: it.Count,
  5647. Ctime: time.Now().Unix(),
  5648. Creater: adminUser.AdminUser.Id,
  5649. Status: 1,
  5650. StorehouseId: houseConfig.StorehouseOutInfo,
  5651. }
  5652. //删除准备表数据
  5653. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5654. service.CreateDialysisBeforePrepareOne(&prepare)
  5655. //查询默认仓库
  5656. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5657. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5658. var total_count int64
  5659. for _, it := range stockList {
  5660. total_count += it.StockCount
  5661. }
  5662. //基础库插入数据
  5663. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5664. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5665. var flush_count int64
  5666. for _, it := range goodList {
  5667. flush_count += it.StockCount
  5668. }
  5669. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5670. }
  5671. }
  5672. //如果库存不够,则出库到下一个批次
  5673. if lastInfo.StockCount < last_total {
  5674. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5675. //查询今日出库数据
  5676. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5677. for _, it := range list {
  5678. prepare := models.DialysisBeforePrepare{
  5679. UserOrgId: it.OrgId,
  5680. PatientId: patient_id,
  5681. RecordDate: it.RecordTime,
  5682. GoodId: it.GoodId,
  5683. GoodTypeId: it.GoodTypeId,
  5684. Count: it.Count,
  5685. Ctime: time.Now().Unix(),
  5686. Creater: adminUser.AdminUser.Id,
  5687. Status: 1,
  5688. StorehouseId: houseConfig.StorehouseOutInfo,
  5689. }
  5690. //删除准备表数据
  5691. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5692. service.CreateDialysisBeforePrepareOne(&prepare)
  5693. //查询默认仓库
  5694. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5695. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5696. var total_count int64
  5697. for _, it := range stockList {
  5698. total_count += it.StockCount
  5699. }
  5700. //基础库插入数据
  5701. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5702. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5703. var flush_count int64
  5704. for _, it := range goodList {
  5705. flush_count += it.StockCount
  5706. }
  5707. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5708. }
  5709. if err != nil {
  5710. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5711. c.ServeSuccessJSON(map[string]interface{}{
  5712. "message": "1",
  5713. "good_name": goodObj.GoodName,
  5714. "specification_name": goodObj.SpecificationName,
  5715. })
  5716. return
  5717. }
  5718. }
  5719. }
  5720. if err != nil {
  5721. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5722. c.ServeSuccessJSON(map[string]interface{}{
  5723. "message": "1",
  5724. "good_name": goodObj.GoodName,
  5725. "specification_name": goodObj.SpecificationName,
  5726. })
  5727. return
  5728. }
  5729. }
  5730. }
  5731. }
  5732. var errs error
  5733. if errs == nil {
  5734. c.ServeSuccessJSON(map[string]interface{}{
  5735. "msg": "提交成功",
  5736. "message": "2",
  5737. "good_name": "",
  5738. "specification_name": "",
  5739. })
  5740. return
  5741. } else {
  5742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5743. return
  5744. }
  5745. }
  5746. func (c *DialysisAPIController) CreateStockOutInfo() {
  5747. patient_id, _ := c.GetInt64("patient_id", 0)
  5748. record_date := c.GetString("record_time")
  5749. if patient_id <= 0 {
  5750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5751. return
  5752. }
  5753. adminInfo := c.GetMobileAdminUserInfo()
  5754. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5755. timeLayout := "2006-01-02"
  5756. loc, _ := time.LoadLocation("Local")
  5757. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5758. record_time := theRecordTime.Unix()
  5759. // 查询信息规挡的设置天数
  5760. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5761. if infor.ID > 0 && infor.WeekDay > 0 {
  5762. var cha_time int64
  5763. timeNowStr := time.Now().Format("2006-01-02")
  5764. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5765. //今日的日期减去设置的日期
  5766. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5767. if cha_time >= record_time {
  5768. //查询审核是否允许
  5769. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5770. //申请状态不允许的情况 拒绝修改
  5771. if infor.ApplicationStatus != 1 {
  5772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5773. return
  5774. }
  5775. }
  5776. }
  5777. //创建步骤表
  5778. finish := models.XtDialysisFinish{
  5779. IsFinish: 1,
  5780. UserOrgId: adminInfo.Org.Id,
  5781. Status: 1,
  5782. Ctime: time.Now().Unix(),
  5783. Mtime: 0,
  5784. Module: 11,
  5785. RecordDate: record_time,
  5786. Sourse: 1,
  5787. PatientId: patient_id,
  5788. }
  5789. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5790. if dialysisFinish.ID == 0 {
  5791. service.CreateDialysisFinish(finish)
  5792. }
  5793. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5794. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5795. //去重
  5796. consumables = RemoveRepeatedGood(consumables)
  5797. if adminInfo.Org.Id == 9919 {
  5798. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5799. //查询是否有库存
  5800. for _, item := range consumables {
  5801. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5802. if item.Count > warehouse.Count {
  5803. goodErrcode := models.XtGoodErrcode{
  5804. UserOrgId: item.UserOrgId,
  5805. Errcode: "自动出库库存不足",
  5806. GoodId: item.GoodId,
  5807. Status: 1,
  5808. Ctime: time.Now().Unix(),
  5809. Mtime: 0,
  5810. Count: 0,
  5811. StockCount: 0,
  5812. Creater: creator,
  5813. BatchNumberId: warehouse.ID,
  5814. WarehouseOutId: 0,
  5815. }
  5816. service.CreateGoodErrcode(goodErrcode)
  5817. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5818. c.ServeSuccessJSON(map[string]interface{}{
  5819. "message": "1",
  5820. "good_name": goodObj.GoodName,
  5821. "specification_name": goodObj.SpecificationName,
  5822. })
  5823. return
  5824. }
  5825. }
  5826. //查询是否有出库单
  5827. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5828. if err == gorm.ErrRecordNotFound {
  5829. //没有记录,则创建出库单
  5830. timeStr := time.Now().Format("2006-01-02")
  5831. timeArr := strings.Split(timeStr, "-")
  5832. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5833. total = total + 1
  5834. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5835. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5836. number = number + total
  5837. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5838. creater := adminInfo.AdminUser.Id
  5839. warehouseOut := models.WarehouseOut{
  5840. WarehouseOutOrderNumber: warehousing_out_order,
  5841. OperationTime: time.Now().Unix(),
  5842. OrgId: adminInfo.Org.Id,
  5843. Creater: creater,
  5844. Ctime: time.Now().Unix(),
  5845. Status: 1,
  5846. WarehouseOutTime: record_time,
  5847. Dealer: 0,
  5848. Manufacturer: 0,
  5849. Type: 1,
  5850. IsSys: 1,
  5851. StorehouseId: houseConfig.StorehouseOutInfo,
  5852. IsCheck: 1,
  5853. }
  5854. err := service.AddSigleWarehouseOut(&warehouseOut)
  5855. if err != nil {
  5856. goodErrcode := models.XtGoodErrcode{
  5857. UserOrgId: adminInfo.Org.Id,
  5858. Errcode: "创建出库单失败",
  5859. GoodId: 0,
  5860. Status: 1,
  5861. Ctime: time.Now().Unix(),
  5862. Mtime: 0,
  5863. Count: 0,
  5864. StockCount: 0,
  5865. Creater: creator,
  5866. BatchNumberId: 0,
  5867. WarehouseOutId: 0,
  5868. }
  5869. service.CreateGoodErrcode(goodErrcode)
  5870. utils.TraceLog("创建出库单失败 err = %v", err)
  5871. } else {
  5872. for _, item := range consumables {
  5873. //出库
  5874. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5875. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5876. if err == nil {
  5877. goodErrcode := models.XtGoodErrcode{
  5878. UserOrgId: adminInfo.Org.Id,
  5879. Errcode: "自动出库接口报错",
  5880. GoodId: 0,
  5881. Status: 1,
  5882. Ctime: time.Now().Unix(),
  5883. Mtime: 0,
  5884. Count: 0,
  5885. StockCount: 0,
  5886. Creater: creator,
  5887. BatchNumberId: 0,
  5888. WarehouseOutId: 0,
  5889. }
  5890. service.CreateGoodErrcode(goodErrcode)
  5891. utils.TraceLog("创建出库单失败 err = %v", err)
  5892. }
  5893. //查询
  5894. //出库数量相加
  5895. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5896. if errs != nil {
  5897. goodErrcode := models.XtGoodErrcode{
  5898. UserOrgId: item.UserOrgId,
  5899. Errcode: "创建剩余库存字段报错",
  5900. GoodId: item.GoodId,
  5901. Status: 1,
  5902. Ctime: time.Now().Unix(),
  5903. Mtime: 0,
  5904. Count: 0,
  5905. StockCount: 0,
  5906. Creater: creater,
  5907. BatchNumberId: 0,
  5908. WarehouseOutId: 0,
  5909. }
  5910. service.CreateGoodErrcode(goodErrcode)
  5911. }
  5912. }
  5913. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5914. if len(list) == 0 {
  5915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5916. return
  5917. }
  5918. for _, item := range list {
  5919. prepare := models.DialysisBeforePrepare{
  5920. UserOrgId: adminInfo.Org.Id,
  5921. PatientId: patient_id,
  5922. RecordDate: record_time,
  5923. GoodId: item.GoodId,
  5924. GoodTypeId: item.GoodTypeId,
  5925. Count: item.Count,
  5926. Creater: adminInfo.AdminUser.Id,
  5927. Status: 1,
  5928. Ctime: time.Now().Unix(),
  5929. StorehouseId: houseConfig.StorehouseOutInfo,
  5930. }
  5931. //清空准备表数据
  5932. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5933. if err != nil {
  5934. goodErrcode := models.XtGoodErrcode{
  5935. UserOrgId: item.OrgId,
  5936. Errcode: "自动出库清空准备表数据报错",
  5937. GoodId: item.GoodId,
  5938. Status: 1,
  5939. Ctime: time.Now().Unix(),
  5940. Mtime: 0,
  5941. Count: 0,
  5942. StockCount: 0,
  5943. Creater: creater,
  5944. BatchNumberId: 0,
  5945. WarehouseOutId: 0,
  5946. }
  5947. service.CreateGoodErrcode(goodErrcode)
  5948. }
  5949. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5950. if errs != nil {
  5951. goodErrcode := models.XtGoodErrcode{
  5952. UserOrgId: item.OrgId,
  5953. Errcode: "自动出库创建准备表数据报错",
  5954. GoodId: item.GoodId,
  5955. Status: 1,
  5956. Ctime: time.Now().Unix(),
  5957. Mtime: 0,
  5958. Count: 0,
  5959. StockCount: 0,
  5960. Creater: creater,
  5961. BatchNumberId: 0,
  5962. WarehouseOutId: 0,
  5963. }
  5964. service.CreateGoodErrcode(goodErrcode)
  5965. }
  5966. //查询默认仓库
  5967. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5968. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5969. var total_count int64
  5970. for _, it := range stockList {
  5971. total_count += it.StockCount
  5972. }
  5973. //基础库插入数据
  5974. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5975. if errcodes != nil {
  5976. goodErrcode := models.XtGoodErrcode{
  5977. UserOrgId: item.OrgId,
  5978. Errcode: "自动出库基础库插入数据",
  5979. GoodId: item.GoodId,
  5980. Status: 1,
  5981. Ctime: time.Now().Unix(),
  5982. Mtime: 0,
  5983. Count: 0,
  5984. StockCount: 0,
  5985. Creater: creater,
  5986. BatchNumberId: 0,
  5987. WarehouseOutId: 0,
  5988. }
  5989. service.CreateGoodErrcode(goodErrcode)
  5990. }
  5991. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5992. var flush_count int64
  5993. for _, it := range goodList {
  5994. flush_count += it.StockCount
  5995. }
  5996. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5997. if errsss != nil {
  5998. goodErrcode := models.XtGoodErrcode{
  5999. UserOrgId: item.OrgId,
  6000. Errcode: "自动出库剩余库存更新数据",
  6001. GoodId: item.GoodId,
  6002. Status: 1,
  6003. Ctime: time.Now().Unix(),
  6004. Mtime: 0,
  6005. Count: 0,
  6006. StockCount: 0,
  6007. Creater: creater,
  6008. BatchNumberId: 0,
  6009. WarehouseOutId: 0,
  6010. }
  6011. service.CreateGoodErrcode(goodErrcode)
  6012. }
  6013. }
  6014. }
  6015. //
  6016. } else if err == nil {
  6017. for _, item := range consumables {
  6018. //出库
  6019. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6020. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6021. if err != nil {
  6022. goodErrcode := models.XtGoodErrcode{
  6023. UserOrgId: adminInfo.Org.Id,
  6024. Errcode: "自动出库接口报错",
  6025. GoodId: 0,
  6026. Status: 1,
  6027. Ctime: time.Now().Unix(),
  6028. Mtime: 0,
  6029. Count: 0,
  6030. StockCount: 0,
  6031. Creater: creator,
  6032. BatchNumberId: 0,
  6033. WarehouseOutId: 0,
  6034. }
  6035. service.CreateGoodErrcode(goodErrcode)
  6036. }
  6037. //出库数量相加
  6038. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6039. if errss != nil {
  6040. goodErrcode := models.XtGoodErrcode{
  6041. UserOrgId: item.UserOrgId,
  6042. Errcode: "创建剩余库存字段报错",
  6043. GoodId: item.GoodId,
  6044. Status: 1,
  6045. Ctime: time.Now().Unix(),
  6046. Mtime: time.Now().Unix(),
  6047. Count: 0,
  6048. StockCount: 0,
  6049. Creater: item.Creater,
  6050. BatchNumberId: 0,
  6051. WarehouseOutId: 0,
  6052. }
  6053. service.CreateGoodErrcode(goodErrcode)
  6054. }
  6055. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6056. if len(list) == 0 {
  6057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6058. return
  6059. }
  6060. for _, item := range list {
  6061. prepare := models.DialysisBeforePrepare{
  6062. UserOrgId: adminInfo.Org.Id,
  6063. PatientId: patient_id,
  6064. RecordDate: record_time,
  6065. GoodId: item.GoodId,
  6066. GoodTypeId: item.GoodTypeId,
  6067. Count: item.Count,
  6068. Creater: adminInfo.AdminUser.Id,
  6069. Status: 1,
  6070. Ctime: time.Now().Unix(),
  6071. StorehouseId: houseConfig.StorehouseOutInfo,
  6072. }
  6073. //清空准备表数据
  6074. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6075. if errs != nil {
  6076. goodErrcode := models.XtGoodErrcode{
  6077. UserOrgId: adminInfo.Org.Id,
  6078. Errcode: "自动出库清空准备表数据报错",
  6079. GoodId: 0,
  6080. Status: 1,
  6081. Ctime: time.Now().Unix(),
  6082. Mtime: 0,
  6083. Count: 0,
  6084. StockCount: 0,
  6085. Creater: creator,
  6086. BatchNumberId: 0,
  6087. WarehouseOutId: 0,
  6088. }
  6089. service.CreateGoodErrcode(goodErrcode)
  6090. }
  6091. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6092. if errcodes != nil {
  6093. goodErrcode := models.XtGoodErrcode{
  6094. UserOrgId: adminInfo.Org.Id,
  6095. Errcode: "自动出库创建准备表数据报错",
  6096. GoodId: 0,
  6097. Status: 1,
  6098. Ctime: time.Now().Unix(),
  6099. Mtime: 0,
  6100. Count: 0,
  6101. StockCount: 0,
  6102. Creater: creator,
  6103. BatchNumberId: 0,
  6104. WarehouseOutId: 0,
  6105. }
  6106. service.CreateGoodErrcode(goodErrcode)
  6107. }
  6108. //查询默认仓库
  6109. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6110. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6111. var total_count int64
  6112. for _, it := range stockList {
  6113. total_count += it.StockCount
  6114. }
  6115. //基础库插入数据
  6116. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6117. if errcodes != nil {
  6118. goodErrcode := models.XtGoodErrcode{
  6119. UserOrgId: adminInfo.Org.Id,
  6120. Errcode: "自动出库基础库插入数据报错",
  6121. GoodId: 0,
  6122. Status: 1,
  6123. Ctime: time.Now().Unix(),
  6124. Mtime: 0,
  6125. Count: 0,
  6126. StockCount: 0,
  6127. Creater: creator,
  6128. BatchNumberId: 0,
  6129. WarehouseOutId: 0,
  6130. }
  6131. service.CreateGoodErrcode(goodErrcode)
  6132. }
  6133. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6134. var flush_count int64
  6135. for _, it := range goodList {
  6136. flush_count += it.StockCount
  6137. }
  6138. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6139. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6140. if errss != nil {
  6141. goodErrcode := models.XtGoodErrcode{
  6142. UserOrgId: item.OrgId,
  6143. Errcode: "自动出库剩余库存更新数据",
  6144. GoodId: item.GoodId,
  6145. Status: 1,
  6146. Ctime: time.Now().Unix(),
  6147. Mtime: 0,
  6148. Count: 0,
  6149. StockCount: 0,
  6150. Creater: creater,
  6151. BatchNumberId: 0,
  6152. WarehouseOutId: 0,
  6153. }
  6154. service.CreateGoodErrcode(goodErrcode)
  6155. }
  6156. }
  6157. }
  6158. }
  6159. c.ServeSuccessJSON(map[string]interface{}{
  6160. "msg": "提交成功",
  6161. "message": "2",
  6162. "good_name": "",
  6163. "specification_name": "",
  6164. })
  6165. return
  6166. }
  6167. if record.IsOpen == 1 {
  6168. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6169. //查询是否有库存
  6170. for _, item := range consumables {
  6171. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6172. if item.Count > warehouse.Count {
  6173. goodErrcode := models.XtGoodErrcode{
  6174. UserOrgId: item.UserOrgId,
  6175. Errcode: "自动出库库存不足",
  6176. GoodId: item.GoodId,
  6177. Status: 1,
  6178. Ctime: time.Now().Unix(),
  6179. Mtime: 0,
  6180. Count: 0,
  6181. StockCount: 0,
  6182. Creater: creator,
  6183. BatchNumberId: warehouse.ID,
  6184. WarehouseOutId: 0,
  6185. }
  6186. service.CreateGoodErrcode(goodErrcode)
  6187. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6188. c.ServeSuccessJSON(map[string]interface{}{
  6189. "message": "1",
  6190. "good_name": goodObj.GoodName,
  6191. "specification_name": goodObj.SpecificationName,
  6192. })
  6193. return
  6194. }
  6195. }
  6196. //查询是否有出库单
  6197. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6198. if err == gorm.ErrRecordNotFound {
  6199. //没有记录,则创建出库单
  6200. timeStr := time.Now().Format("2006-01-02")
  6201. timeArr := strings.Split(timeStr, "-")
  6202. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6203. total = total + 1
  6204. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6205. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6206. number = number + total
  6207. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6208. creater := adminInfo.AdminUser.Id
  6209. warehouseOut := models.WarehouseOut{
  6210. WarehouseOutOrderNumber: warehousing_out_order,
  6211. OperationTime: time.Now().Unix(),
  6212. OrgId: adminInfo.Org.Id,
  6213. Creater: creater,
  6214. Ctime: time.Now().Unix(),
  6215. Status: 1,
  6216. WarehouseOutTime: record_time,
  6217. Dealer: 0,
  6218. Manufacturer: 0,
  6219. Type: 1,
  6220. IsSys: 1,
  6221. StorehouseId: houseConfig.StorehouseOutInfo,
  6222. IsCheck: 1,
  6223. }
  6224. err := service.AddSigleWarehouseOut(&warehouseOut)
  6225. if err != nil {
  6226. goodErrcode := models.XtGoodErrcode{
  6227. UserOrgId: adminInfo.Org.Id,
  6228. Errcode: "创建出库单失败",
  6229. GoodId: 0,
  6230. Status: 1,
  6231. Ctime: time.Now().Unix(),
  6232. Mtime: 0,
  6233. Count: 0,
  6234. StockCount: 0,
  6235. Creater: creator,
  6236. BatchNumberId: 0,
  6237. WarehouseOutId: 0,
  6238. }
  6239. service.CreateGoodErrcode(goodErrcode)
  6240. utils.TraceLog("创建出库单失败 err = %v", err)
  6241. } else {
  6242. for _, item := range consumables {
  6243. //出库
  6244. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6245. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6246. if err == nil {
  6247. goodErrcode := models.XtGoodErrcode{
  6248. UserOrgId: adminInfo.Org.Id,
  6249. Errcode: "自动出库接口报错",
  6250. GoodId: 0,
  6251. Status: 1,
  6252. Ctime: time.Now().Unix(),
  6253. Mtime: 0,
  6254. Count: 0,
  6255. StockCount: 0,
  6256. Creater: creator,
  6257. BatchNumberId: 0,
  6258. WarehouseOutId: 0,
  6259. }
  6260. service.CreateGoodErrcode(goodErrcode)
  6261. utils.TraceLog("创建出库单失败 err = %v", err)
  6262. }
  6263. //查询
  6264. //出库数量相加
  6265. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6266. if errs != nil {
  6267. goodErrcode := models.XtGoodErrcode{
  6268. UserOrgId: item.UserOrgId,
  6269. Errcode: "创建剩余库存字段报错",
  6270. GoodId: item.GoodId,
  6271. Status: 1,
  6272. Ctime: time.Now().Unix(),
  6273. Mtime: 0,
  6274. Count: 0,
  6275. StockCount: 0,
  6276. Creater: creater,
  6277. BatchNumberId: 0,
  6278. WarehouseOutId: 0,
  6279. }
  6280. service.CreateGoodErrcode(goodErrcode)
  6281. }
  6282. }
  6283. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6284. if len(list) == 0 {
  6285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6286. return
  6287. }
  6288. for _, item := range list {
  6289. prepare := models.DialysisBeforePrepare{
  6290. UserOrgId: adminInfo.Org.Id,
  6291. PatientId: patient_id,
  6292. RecordDate: record_time,
  6293. GoodId: item.GoodId,
  6294. GoodTypeId: item.GoodTypeId,
  6295. Count: item.Count,
  6296. Creater: adminInfo.AdminUser.Id,
  6297. Status: 1,
  6298. Ctime: time.Now().Unix(),
  6299. StorehouseId: houseConfig.StorehouseOutInfo,
  6300. }
  6301. //清空准备表数据
  6302. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6303. if err != nil {
  6304. goodErrcode := models.XtGoodErrcode{
  6305. UserOrgId: item.OrgId,
  6306. Errcode: "自动出库清空准备表数据报错",
  6307. GoodId: item.GoodId,
  6308. Status: 1,
  6309. Ctime: time.Now().Unix(),
  6310. Mtime: 0,
  6311. Count: 0,
  6312. StockCount: 0,
  6313. Creater: creater,
  6314. BatchNumberId: 0,
  6315. WarehouseOutId: 0,
  6316. }
  6317. service.CreateGoodErrcode(goodErrcode)
  6318. }
  6319. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6320. if errs != nil {
  6321. goodErrcode := models.XtGoodErrcode{
  6322. UserOrgId: item.OrgId,
  6323. Errcode: "自动出库创建准备表数据报错",
  6324. GoodId: item.GoodId,
  6325. Status: 1,
  6326. Ctime: time.Now().Unix(),
  6327. Mtime: 0,
  6328. Count: 0,
  6329. StockCount: 0,
  6330. Creater: creater,
  6331. BatchNumberId: 0,
  6332. WarehouseOutId: 0,
  6333. }
  6334. service.CreateGoodErrcode(goodErrcode)
  6335. }
  6336. //查询默认仓库
  6337. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6338. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6339. var total_count int64
  6340. for _, it := range stockList {
  6341. total_count += it.StockCount
  6342. }
  6343. //基础库插入数据
  6344. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6345. if errcodes != nil {
  6346. goodErrcode := models.XtGoodErrcode{
  6347. UserOrgId: item.OrgId,
  6348. Errcode: "自动出库基础库插入数据",
  6349. GoodId: item.GoodId,
  6350. Status: 1,
  6351. Ctime: time.Now().Unix(),
  6352. Mtime: 0,
  6353. Count: 0,
  6354. StockCount: 0,
  6355. Creater: creater,
  6356. BatchNumberId: 0,
  6357. WarehouseOutId: 0,
  6358. }
  6359. service.CreateGoodErrcode(goodErrcode)
  6360. }
  6361. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6362. var flush_count int64
  6363. for _, it := range goodList {
  6364. flush_count += it.StockCount
  6365. }
  6366. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6367. if errsss != nil {
  6368. goodErrcode := models.XtGoodErrcode{
  6369. UserOrgId: item.OrgId,
  6370. Errcode: "自动出库剩余库存更新数据",
  6371. GoodId: item.GoodId,
  6372. Status: 1,
  6373. Ctime: time.Now().Unix(),
  6374. Mtime: 0,
  6375. Count: 0,
  6376. StockCount: 0,
  6377. Creater: creater,
  6378. BatchNumberId: 0,
  6379. WarehouseOutId: 0,
  6380. }
  6381. service.CreateGoodErrcode(goodErrcode)
  6382. }
  6383. }
  6384. }
  6385. //
  6386. } else if err == nil {
  6387. for _, item := range consumables {
  6388. //出库
  6389. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6390. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6391. if err != nil {
  6392. goodErrcode := models.XtGoodErrcode{
  6393. UserOrgId: adminInfo.Org.Id,
  6394. Errcode: "自动出库接口报错",
  6395. GoodId: 0,
  6396. Status: 1,
  6397. Ctime: time.Now().Unix(),
  6398. Mtime: 0,
  6399. Count: 0,
  6400. StockCount: 0,
  6401. Creater: creator,
  6402. BatchNumberId: 0,
  6403. WarehouseOutId: 0,
  6404. }
  6405. service.CreateGoodErrcode(goodErrcode)
  6406. }
  6407. //出库数量相加
  6408. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6409. if errss != nil {
  6410. goodErrcode := models.XtGoodErrcode{
  6411. UserOrgId: item.UserOrgId,
  6412. Errcode: "创建剩余库存字段报错",
  6413. GoodId: item.GoodId,
  6414. Status: 1,
  6415. Ctime: time.Now().Unix(),
  6416. Mtime: time.Now().Unix(),
  6417. Count: 0,
  6418. StockCount: 0,
  6419. Creater: item.Creater,
  6420. BatchNumberId: 0,
  6421. WarehouseOutId: 0,
  6422. }
  6423. service.CreateGoodErrcode(goodErrcode)
  6424. }
  6425. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6426. if len(list) == 0 {
  6427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6428. return
  6429. }
  6430. for _, item := range list {
  6431. prepare := models.DialysisBeforePrepare{
  6432. UserOrgId: adminInfo.Org.Id,
  6433. PatientId: patient_id,
  6434. RecordDate: record_time,
  6435. GoodId: item.GoodId,
  6436. GoodTypeId: item.GoodTypeId,
  6437. Count: item.Count,
  6438. Creater: adminInfo.AdminUser.Id,
  6439. Status: 1,
  6440. Ctime: time.Now().Unix(),
  6441. StorehouseId: houseConfig.StorehouseOutInfo,
  6442. }
  6443. //清空准备表数据
  6444. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6445. if errs != nil {
  6446. goodErrcode := models.XtGoodErrcode{
  6447. UserOrgId: adminInfo.Org.Id,
  6448. Errcode: "自动出库清空准备表数据报错",
  6449. GoodId: 0,
  6450. Status: 1,
  6451. Ctime: time.Now().Unix(),
  6452. Mtime: 0,
  6453. Count: 0,
  6454. StockCount: 0,
  6455. Creater: creator,
  6456. BatchNumberId: 0,
  6457. WarehouseOutId: 0,
  6458. }
  6459. service.CreateGoodErrcode(goodErrcode)
  6460. }
  6461. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6462. if errcodes != nil {
  6463. goodErrcode := models.XtGoodErrcode{
  6464. UserOrgId: adminInfo.Org.Id,
  6465. Errcode: "自动出库创建准备表数据报错",
  6466. GoodId: 0,
  6467. Status: 1,
  6468. Ctime: time.Now().Unix(),
  6469. Mtime: 0,
  6470. Count: 0,
  6471. StockCount: 0,
  6472. Creater: creator,
  6473. BatchNumberId: 0,
  6474. WarehouseOutId: 0,
  6475. }
  6476. service.CreateGoodErrcode(goodErrcode)
  6477. }
  6478. //查询默认仓库
  6479. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6480. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6481. var total_count int64
  6482. for _, it := range stockList {
  6483. total_count += it.StockCount
  6484. }
  6485. //基础库插入数据
  6486. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6487. if errcodes != nil {
  6488. goodErrcode := models.XtGoodErrcode{
  6489. UserOrgId: adminInfo.Org.Id,
  6490. Errcode: "自动出库基础库插入数据报错",
  6491. GoodId: 0,
  6492. Status: 1,
  6493. Ctime: time.Now().Unix(),
  6494. Mtime: 0,
  6495. Count: 0,
  6496. StockCount: 0,
  6497. Creater: creator,
  6498. BatchNumberId: 0,
  6499. WarehouseOutId: 0,
  6500. }
  6501. service.CreateGoodErrcode(goodErrcode)
  6502. }
  6503. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6504. var flush_count int64
  6505. for _, it := range goodList {
  6506. flush_count += it.StockCount
  6507. }
  6508. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6509. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6510. if errss != nil {
  6511. goodErrcode := models.XtGoodErrcode{
  6512. UserOrgId: item.OrgId,
  6513. Errcode: "自动出库剩余库存更新数据",
  6514. GoodId: item.GoodId,
  6515. Status: 1,
  6516. Ctime: time.Now().Unix(),
  6517. Mtime: 0,
  6518. Count: 0,
  6519. StockCount: 0,
  6520. Creater: creater,
  6521. BatchNumberId: 0,
  6522. WarehouseOutId: 0,
  6523. }
  6524. service.CreateGoodErrcode(goodErrcode)
  6525. }
  6526. }
  6527. }
  6528. }
  6529. c.ServeSuccessJSON(map[string]interface{}{
  6530. "msg": "提交成功",
  6531. "message": "2",
  6532. "good_name": "",
  6533. "specification_name": "",
  6534. })
  6535. return
  6536. } else {
  6537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6538. return
  6539. }
  6540. }
  6541. func (c *DialysisAPIController) EditConsumables() {
  6542. patient_id, _ := c.GetInt64("patient_id", 0)
  6543. record_date := c.GetString("record_time")
  6544. if patient_id <= 0 {
  6545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6546. return
  6547. }
  6548. adminInfo := c.GetMobileAdminUserInfo()
  6549. timeLayout := "2006-01-02"
  6550. loc, _ := time.LoadLocation("Local")
  6551. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6552. record_time := theRecordTime.Unix()
  6553. // 查询信息规挡的设置天数
  6554. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6555. if infor.ID > 0 && infor.WeekDay > 0 {
  6556. var cha_time int64
  6557. timeNowStr := time.Now().Format("2006-01-02")
  6558. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6559. //今日的日期减去设置的日期
  6560. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6561. if cha_time >= record_time {
  6562. //查询审核是否允许
  6563. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6564. //申请状态不允许的情况 拒绝修改
  6565. if infor.ApplicationStatus != 1 {
  6566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6567. return
  6568. }
  6569. }
  6570. }
  6571. dataBody := make(map[string]interface{}, 0)
  6572. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6573. if err != nil {
  6574. utils.ErrorLog(err.Error())
  6575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6576. return
  6577. }
  6578. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6579. var beforePrepares []*models.DialysisBeforePrepareGoods
  6580. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6581. var cancelbefor []*models.DialysisBeforePrepareGoods
  6582. var outbefor []*models.DialysisBeforePrepareGoods
  6583. //判断是否开启自动出库
  6584. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6585. if record.IsOpen == 1 {
  6586. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6587. goods, _ := dataBody["goods"].([]interface{})
  6588. if len(goods) > 0 {
  6589. for _, item := range goods {
  6590. items := item.(map[string]interface{})
  6591. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6592. utils.ErrorLog("good_id")
  6593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6594. return
  6595. }
  6596. good_id := int64(items["good_id"].(float64))
  6597. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6598. utils.ErrorLog("good_type_id")
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. good_type_id := int64(items["good_type_id"].(float64))
  6603. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6604. utils.ErrorLog("count")
  6605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6606. return
  6607. }
  6608. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6609. commdity_code := items["commdity_code"].(string)
  6610. fmt.Println(commdity_code)
  6611. prepareGoods := &models.DialysisBeforePrepareGoods{
  6612. GoodTypeId: good_type_id,
  6613. GoodId: good_id,
  6614. Count: count,
  6615. StorehouseId: houseConfig.StorehouseOutInfo,
  6616. }
  6617. beforePrepares = append(beforePrepares, prepareGoods)
  6618. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6619. GoodTypeId: good_type_id,
  6620. GoodId: good_id,
  6621. Count: count,
  6622. StorehouseId: houseConfig.StorehouseOutInfo,
  6623. }
  6624. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6625. }
  6626. for _, item := range beforePrepares {
  6627. //1.查看该患者该耗材型号最后一次出库数量
  6628. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6629. //判断当前出库数量和最后一次出库数量的大小
  6630. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6631. if item.Count < goodInfo.Count {
  6632. cancelbefor = append(cancelbefor, item)
  6633. }
  6634. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6635. if item.Count > goodInfo.Count {
  6636. outbefor = append(outbefor, item)
  6637. }
  6638. //处理编辑耗材新增不了的问题
  6639. if goodInfo.Count == item.Count {
  6640. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6641. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6642. }
  6643. }
  6644. if len(cancelbefor) > 0 {
  6645. //退库
  6646. for _, item := range cancelbefor {
  6647. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6648. creater := adminInfo.AdminUser.Id
  6649. //查询该患者当天已经出库的耗材信息
  6650. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6651. var delete_count int64 = 0
  6652. delete_count = warehouseOutInfos.Count - item.Count
  6653. //增加库存数量
  6654. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6655. //减少实际出库库存数量
  6656. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6657. // 删除出库完成后,要增加对应批次的库存数量
  6658. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6659. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6660. //更新剩余库存
  6661. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6662. var flush_count int64
  6663. for _, it := range goodListOne {
  6664. flush_count += it.StockCount
  6665. }
  6666. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6667. //查询剩余库存
  6668. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6669. var sum_count int64
  6670. for _, item := range goodList {
  6671. sum_count += item.StockCount
  6672. }
  6673. // 在出库记录表里记录退库详情
  6674. warehouseOutInfo := &models.WarehouseOutInfo{
  6675. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6676. WarehouseOutId: warehouseOut.ID,
  6677. Status: 1,
  6678. Ctime: time.Now().Unix(),
  6679. OrgId: adminInfo.Org.Id,
  6680. Type: 1,
  6681. IsSys: 1,
  6682. SysRecordTime: record_time,
  6683. GoodTypeId: item.GoodTypeId,
  6684. GoodId: item.GoodId,
  6685. PatientId: patient_id,
  6686. ConsumableType: 2,
  6687. StorehouseId: houseConfig.StorehouseOutInfo,
  6688. IsCheck: 1,
  6689. OverCount: sum_count,
  6690. }
  6691. warehouseOutInfo.Count = item.Count
  6692. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6693. warehouseOutInfo.Price = stockInInfo.Price
  6694. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6695. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6696. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6697. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6698. warehouseOutInfo.Number = warehouseOutInfos.Number
  6699. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6700. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6701. //查找当天是否存在出库记录
  6702. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6703. if errcod == gorm.ErrRecordNotFound {
  6704. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6705. //插入详情明细表
  6706. stockFlow := models.VmStockFlow{
  6707. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6708. WarehouseOutId: warehouseOut.ID,
  6709. GoodId: item.GoodId,
  6710. Number: warehouseOutInfos.Number,
  6711. ProductDate: stockInInfo.ProductDate,
  6712. ExpireDate: stockInInfo.ExpiryDate,
  6713. Count: item.Count,
  6714. Price: stockInInfo.Price,
  6715. Status: 1,
  6716. Ctime: record_time,
  6717. UserOrgId: adminInfo.Org.Id,
  6718. Manufacturer: stockInInfo.Manufacturer,
  6719. Dealer: stockInInfo.Dealer,
  6720. LicenseNumber: stockInInfo.LicenseNumber,
  6721. IsEdit: 2,
  6722. Creator: creater,
  6723. SystemTime: record_time,
  6724. ConsumableType: 3,
  6725. WarehousingDetailId: 0,
  6726. IsSys: 1,
  6727. UpdateCreator: creater,
  6728. PatientId: patient_id,
  6729. StorehouseId: houseConfig.StorehouseOutInfo,
  6730. }
  6731. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6732. if errflow == gorm.ErrRecordNotFound {
  6733. //创建流水表
  6734. err := service.CreateStockFlowOne(stockFlow)
  6735. fmt.Println("err", err)
  6736. } else if errflow == nil {
  6737. //插入详情明细表
  6738. stockFlow := models.VmStockFlow{
  6739. ID: exsit.ID,
  6740. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6741. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6742. WarehouseOutId: warehouseOut.ID,
  6743. GoodId: item.GoodId,
  6744. Number: warehouseOutInfos.Number,
  6745. ProductDate: stockInInfo.ProductDate,
  6746. ExpireDate: stockInInfo.ExpiryDate,
  6747. Count: exsit.Count - delete_count,
  6748. Price: stockInInfo.Price,
  6749. Status: 1,
  6750. Ctime: record_time,
  6751. UserOrgId: adminInfo.Org.Id,
  6752. Manufacturer: stockInInfo.Manufacturer,
  6753. Dealer: stockInInfo.Dealer,
  6754. LicenseNumber: stockInInfo.LicenseNumber,
  6755. IsEdit: 2,
  6756. Creator: creater,
  6757. SystemTime: record_time,
  6758. ConsumableType: 3,
  6759. WarehousingDetailId: 0,
  6760. IsSys: 1,
  6761. UpdateCreator: creater,
  6762. PatientId: patient_id,
  6763. StorehouseId: houseConfig.StorehouseOutInfo,
  6764. }
  6765. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6766. }
  6767. } else if errcod == nil {
  6768. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6769. //查询剩余库存
  6770. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6771. var sum_count int64
  6772. for _, item := range goodList {
  6773. sum_count += item.StockCount
  6774. }
  6775. //创建退库单,生成退库数据
  6776. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6777. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6778. operation_time := time.Now().Unix()
  6779. creater := adminInfo.AdminUser.Id
  6780. //创建退库单
  6781. timeStr := time.Now().Format("2006-01-02")
  6782. timeArr := strings.Split(timeStr, "-")
  6783. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6784. total = total + 1
  6785. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6786. cancelStock := models.CancelStock{
  6787. OrderNumber: orderNumber,
  6788. OperaTime: operation_time,
  6789. OrgId: adminInfo.Org.Id,
  6790. Creater: creater,
  6791. Ctime: time.Now().Unix(),
  6792. Status: 1,
  6793. ReturnTime: record_time,
  6794. Type: 1,
  6795. StorehouseId: houseConfig.StorehouseOutInfo,
  6796. IsCheck: 1,
  6797. }
  6798. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6799. if msgerrkonde == gorm.ErrRecordNotFound {
  6800. service.AddSigleCancelStock(&cancelStock)
  6801. }
  6802. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6803. //查询是否有出库
  6804. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6805. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6806. deaerler, _ := service.GetDealerById(info.Dealer)
  6807. if info.ID > 0 {
  6808. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6809. cancelStockInfo := models.CancelStockInfo{
  6810. GoodId: item.GoodId,
  6811. CancelStockId: cancel.ID,
  6812. GoodTypeId: good.GoodTypeId,
  6813. Count: delete_count,
  6814. Price: info.Price,
  6815. Total: 0,
  6816. ProductDate: info.ProductDate,
  6817. ExpiryDate: info.ExpiryDate,
  6818. Ctime: time.Now().Unix(),
  6819. Status: 1,
  6820. OrgId: adminInfo.Org.Id,
  6821. OrderNumber: cancel.OrderNumber,
  6822. Type: 0,
  6823. Dealer: deaerler.DealerName,
  6824. Manufacturer: manufacturer.ManufacturerName,
  6825. Number: info.Number,
  6826. RegisterAccount: "",
  6827. Remark: "",
  6828. WarehouseInfoId: info.WarehouseInfotId,
  6829. PatientId: info.PatientId,
  6830. RecordDate: info.SysRecordTime,
  6831. StorehouseId: houseConfig.StorehouseOutInfo,
  6832. IsCheck: 1,
  6833. }
  6834. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6835. //退库数量增加
  6836. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6837. //查询剩余库存
  6838. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6839. var over_count int64
  6840. for _, it := range goodList {
  6841. over_count += it.StockCount
  6842. }
  6843. flow := models.VmStockFlow{
  6844. WarehousingId: info.WarehouseInfotId,
  6845. GoodId: item.GoodId,
  6846. Number: info.Number,
  6847. LicenseNumber: info.LicenseNumber,
  6848. Count: delete_count,
  6849. UserOrgId: adminInfo.Org.Id,
  6850. PatientId: patient_id,
  6851. SystemTime: info.SysRecordTime,
  6852. ConsumableType: 7,
  6853. IsSys: 0,
  6854. WarehousingOrder: "",
  6855. WarehouseOutId: info.WarehouseOutId,
  6856. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6857. IsEdit: 0,
  6858. CancelStockId: cancel.ID,
  6859. CancelOrderNumber: cancel.OrderNumber,
  6860. Manufacturer: manufacturer.ID,
  6861. Dealer: 0,
  6862. Creator: adminInfo.AdminUser.Id,
  6863. UpdateCreator: 0,
  6864. Status: 1,
  6865. Ctime: record_time,
  6866. Mtime: 0,
  6867. Price: info.Price,
  6868. WarehousingDetailId: info.WarehouseInfotId,
  6869. WarehouseOutDetailId: info.ID,
  6870. CancelOutDetailId: cancelInfo.ID,
  6871. ProductDate: info.ProductDate,
  6872. ExpireDate: info.ExpiryDate,
  6873. StorehouseId: houseConfig.StorehouseOutInfo,
  6874. OverCount: over_count,
  6875. }
  6876. service.CreateStockFlowOne(flow)
  6877. }
  6878. }
  6879. //更改自动出库的表格
  6880. details := models.BloodAutomaticReduceDetail{
  6881. WarehouseOutId: warehouseOutInfo.ID,
  6882. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6883. PatientId: patient_id,
  6884. Ctime: time.Now().Unix(),
  6885. Mtime: time.Now().Unix(),
  6886. Status: 1,
  6887. RecordTime: record_time,
  6888. OrgId: adminInfo.Org.Id,
  6889. GoodId: item.GoodId,
  6890. GoodTypeId: item.GoodTypeId,
  6891. Count: item.Count,
  6892. StorehouseId: houseConfig.StorehouseOutInfo,
  6893. }
  6894. //查询当天耗材是否已经存在数据
  6895. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6896. if errcode == gorm.ErrRecordNotFound {
  6897. service.CreateAutoReduceRecord(&details)
  6898. } else if errcode == nil {
  6899. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6900. service.CreateAutoReduceRecord(&details)
  6901. }
  6902. //查询默认仓库
  6903. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6904. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6905. var total_count int64
  6906. for _, it := range stockList {
  6907. total_count += it.StockCount
  6908. }
  6909. //基础库插入数据
  6910. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6911. }
  6912. }
  6913. if len(outbefor) > 0 {
  6914. //出库
  6915. for _, item := range outbefor {
  6916. var last_total int64
  6917. //1.查看该患者该耗材型号最后一次出库数量
  6918. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6919. //计算当前出库和最后一次出库数据相差数据
  6920. last_total = item.Count - goodInfoOne.Count
  6921. //查询该耗材的总库存
  6922. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6923. // 如果库存差大于剩余库存则提示库存不足
  6924. if last_total > wareinfo.StockCount {
  6925. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6926. c.ServeSuccessJSON(map[string]interface{}{
  6927. "message": "1",
  6928. "good_name": goodObj.GoodName,
  6929. "specification_name": goodObj.SpecificationName,
  6930. })
  6931. return
  6932. } else {
  6933. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6934. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6935. if err == gorm.ErrRecordNotFound {
  6936. //没有记录,则创建出库单
  6937. timeStr := time.Now().Format("2006-01-02")
  6938. timeArr := strings.Split(timeStr, "-")
  6939. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6940. total = total + 1
  6941. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6942. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6943. number = number + total
  6944. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6945. warehouseOut := models.WarehouseOut{
  6946. WarehouseOutOrderNumber: warehousing_out_order,
  6947. OperationTime: time.Now().Unix(),
  6948. OrgId: adminInfo.Org.Id,
  6949. Creater: adminInfo.AdminUser.Id,
  6950. Ctime: time.Now().Unix(),
  6951. Status: 1,
  6952. WarehouseOutTime: record_time,
  6953. Dealer: 0,
  6954. Manufacturer: 0,
  6955. Type: 1,
  6956. IsSys: 1,
  6957. StorehouseId: houseConfig.StorehouseOutInfo,
  6958. IsCheck: 1,
  6959. }
  6960. service.AddSigleWarehouseOut(&warehouseOut)
  6961. }
  6962. //出库
  6963. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6964. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6965. //1.查看该患者该耗材型号最后一次出库数量
  6966. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6967. prepare := models.DialysisBeforePrepare{
  6968. UserOrgId: adminInfo.Org.Id,
  6969. PatientId: patient_id,
  6970. RecordDate: record_time,
  6971. GoodId: item.GoodId,
  6972. GoodTypeId: item.GoodTypeId,
  6973. Count: item.Count - goodInfoTwo.Count,
  6974. Ctime: time.Now().Unix(),
  6975. Mtime: 0,
  6976. Creater: adminInfo.AdminUser.Id,
  6977. Modifier: adminInfo.AdminUser.Id,
  6978. Status: 1,
  6979. CommdityCode: "",
  6980. NewCount: 0,
  6981. ProjectId: 0,
  6982. StorehouseId: houseConfig.StorehouseOutInfo,
  6983. }
  6984. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6985. //增加出库数量
  6986. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6987. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6988. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6989. var total_count int64
  6990. for _, it := range stockList {
  6991. total_count += it.StockCount
  6992. }
  6993. //基础库插入数据
  6994. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6995. //剩余库存
  6996. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6997. var flush_count int64
  6998. for _, it := range goodList {
  6999. flush_count += it.StockCount
  7000. }
  7001. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7002. }
  7003. }
  7004. }
  7005. //查询今日出库数据
  7006. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7007. for _, it := range list {
  7008. prepare := models.DialysisBeforePrepare{
  7009. UserOrgId: it.OrgId,
  7010. PatientId: patient_id,
  7011. RecordDate: it.RecordTime,
  7012. GoodId: it.GoodId,
  7013. GoodTypeId: it.GoodTypeId,
  7014. Count: it.Count,
  7015. Ctime: time.Now().Unix(),
  7016. Creater: adminInfo.AdminUser.Id,
  7017. Status: 1,
  7018. StorehouseId: houseConfig.StorehouseOutInfo,
  7019. ProjectId: it.ProjectId,
  7020. }
  7021. //删除准备表数据
  7022. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7023. service.CreateDialysisBeforePrepareOne(&prepare)
  7024. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7025. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7026. var total_count int64
  7027. for _, it := range stockList {
  7028. total_count += it.StockCount
  7029. }
  7030. //基础库插入数据
  7031. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7032. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7033. var flush_count int64
  7034. for _, it := range goodList {
  7035. flush_count += it.StockCount
  7036. }
  7037. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7038. }
  7039. }
  7040. }
  7041. //更新自动出库的地方
  7042. var errs error
  7043. if errs == nil {
  7044. c.ServeSuccessJSON(map[string]interface{}{
  7045. "msg": "修改成功",
  7046. "message": "2",
  7047. "good_name": "",
  7048. "specification_name": "",
  7049. })
  7050. return
  7051. } else {
  7052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7053. return
  7054. }
  7055. }
  7056. }
  7057. func (c *DialysisAPIController) GetDialysisGoods() {
  7058. schedualDate := c.GetString("schedule_date")
  7059. schedule_type, _ := c.GetInt64("schedule_type")
  7060. partition_id, _ := c.GetInt64("partition_id")
  7061. page, _ := c.GetInt("page")
  7062. patient_id, _ := c.GetInt64("patient_id")
  7063. schedualEndDate := int64(0)
  7064. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7065. if parseDateErr != nil && len(schedualDate) != 0 {
  7066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7067. return
  7068. }
  7069. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7070. if parseDateErr != nil && len(schedualDate) != 0 {
  7071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7072. return
  7073. }
  7074. schedualEndDate = endDate.Unix()
  7075. adminUser := c.GetMobileAdminUserInfo()
  7076. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7077. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7078. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7079. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7080. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7081. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7082. //获取当天该病人的透析处方
  7083. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7084. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7085. if err == gorm.ErrRecordNotFound {
  7086. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7087. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7088. if patient_id != 0 {
  7089. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7090. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7091. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7092. //获取患者总的出库数据
  7093. item.LastAutomaticReduceDetail = goodUser
  7094. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7095. item.Project = project
  7096. for _, it := range item.AutomaticReduceDetail {
  7097. var total int64
  7098. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7099. for _, its := range auto {
  7100. total += its.Count
  7101. }
  7102. it.Count = total
  7103. }
  7104. }
  7105. }
  7106. c.ServeSuccessJSON(map[string]interface{}{
  7107. "dialysis_goods": dialysisGoods,
  7108. "good_type": goodTypes,
  7109. "total": total,
  7110. "prescribe": prescribe,
  7111. "good_info": good_info,
  7112. "warehouseOutList": warehouseOutList,
  7113. "config": config,
  7114. "outConfig": outConfig,
  7115. "settleConfig": settleConfig,
  7116. })
  7117. return
  7118. } else if err == nil {
  7119. //获取当天排班的每个患者的库存使用情况
  7120. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7121. //获取患者总的出库数据
  7122. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7123. if patient_id != 0 {
  7124. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7125. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7126. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7127. item.Project = project
  7128. item.LastAutomaticReduceDetail = goodUser
  7129. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7130. for _, it := range item.AutomaticReduceDetail {
  7131. var total int64
  7132. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7133. for _, its := range auto {
  7134. total += its.Count
  7135. }
  7136. it.Count = total
  7137. }
  7138. }
  7139. }
  7140. if err == nil {
  7141. c.ServeSuccessJSON(map[string]interface{}{
  7142. "dialysis_goods": dialysisGoods,
  7143. "good_type": goodTypes,
  7144. "total": total,
  7145. "prescribe": prescribe,
  7146. "good_info": good_info,
  7147. "project": project,
  7148. "warehouseOutList": warehouseOutList,
  7149. "config": config,
  7150. "outConfig": outConfig,
  7151. "settleConfig": settleConfig,
  7152. })
  7153. return
  7154. } else {
  7155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7156. return
  7157. }
  7158. } else if err != nil {
  7159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7160. return
  7161. }
  7162. }
  7163. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7164. start_time := c.GetString("start_time")
  7165. end_time := c.GetString("end_time")
  7166. timeLayout := "2006-01-02"
  7167. loc, _ := time.LoadLocation("Local")
  7168. var theStartTime int64
  7169. if len(start_time) > 0 {
  7170. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7171. if err != nil {
  7172. utils.ErrorLog(err.Error())
  7173. }
  7174. theStartTime = theTime.Unix()
  7175. }
  7176. var theEndtTime int64
  7177. if len(end_time) > 0 {
  7178. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7179. if err != nil {
  7180. utils.ErrorLog(err.Error())
  7181. }
  7182. theEndtTime = theTime.Unix()
  7183. }
  7184. adminUser := c.GetMobileAdminUserInfo()
  7185. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7186. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7187. if err == nil {
  7188. c.ServeSuccessJSON(map[string]interface{}{
  7189. "stock_out": outInfo,
  7190. "stockCount": stockCount,
  7191. })
  7192. return
  7193. } else {
  7194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7195. return
  7196. }
  7197. }
  7198. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7199. patient_id, _ := c.GetInt64("patient_id", 0)
  7200. record_time := c.GetString("record_time")
  7201. adminUser := c.GetMobileAdminUserInfo()
  7202. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7203. if parseDateErr != nil && len(record_time) != 0 {
  7204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7205. return
  7206. }
  7207. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7208. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7209. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7210. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7211. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7212. //获取今日患者的透析处方参数
  7213. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7214. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7215. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7216. c.ServeSuccessJSON(map[string]interface{}{
  7217. "good_type": goodTypes,
  7218. "good_user": goodUser,
  7219. "good_info": good_info,
  7220. "last_good_user": lastGoodUserDetial,
  7221. "project": project,
  7222. "prescription": prescribe,
  7223. "outInfo": outInfo,
  7224. "configs": configs,
  7225. })
  7226. return
  7227. }
  7228. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7229. patient_id, _ := c.GetInt64("patient_id", 0)
  7230. record_date := c.GetString("record_time")
  7231. timeLayout := "2006-01-02"
  7232. loc, _ := time.LoadLocation("Local")
  7233. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7234. record_time := theRecordTime.Unix()
  7235. adminInfo := c.GetMobileAdminUserInfo()
  7236. dataBody := make(map[string]interface{}, 0)
  7237. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7238. if err != nil {
  7239. utils.ErrorLog(err.Error())
  7240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7241. return
  7242. }
  7243. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7244. var beforePrepares []*models.DialysisBeforePrepareGoods
  7245. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7246. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7247. goods, _ := dataBody["goods"].([]interface{})
  7248. if len(goods) > 0 {
  7249. for _, item := range goods {
  7250. items := item.(map[string]interface{})
  7251. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7252. utils.ErrorLog("good_id")
  7253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7254. return
  7255. }
  7256. good_id := int64(items["good_id"].(float64))
  7257. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7258. utils.ErrorLog("good_type_id")
  7259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7260. return
  7261. }
  7262. good_type_id := int64(items["good_type_id"].(float64))
  7263. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7264. utils.ErrorLog("count")
  7265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7266. return
  7267. }
  7268. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7269. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7270. utils.ErrorLog("project_id")
  7271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7272. return
  7273. }
  7274. project_id := int64(items["project_id"].(float64))
  7275. new_count := int64(items["new_count"].(float64))
  7276. old_count := int64(items["old_count"].(float64))
  7277. prepare := &models.DialysisBeforePrepareGoods{
  7278. GoodId: good_id,
  7279. GoodTypeId: good_type_id,
  7280. Count: count,
  7281. ProjectId: project_id,
  7282. StorehouseId: houseConfig.StorehouseOutInfo,
  7283. NewCount: new_count,
  7284. OldCount: old_count,
  7285. }
  7286. beforePrepares = append(beforePrepares, prepare)
  7287. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7288. GoodId: good_id,
  7289. GoodTypeId: good_type_id,
  7290. Count: count,
  7291. ProjectId: project_id,
  7292. StorehouseId: houseConfig.StorehouseOutInfo,
  7293. NewCount: new_count,
  7294. OldCount: old_count,
  7295. }
  7296. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7297. }
  7298. }
  7299. }
  7300. //查询是否有库存
  7301. for _, item := range beforePrepares {
  7302. if item.NewCount > 0 {
  7303. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7304. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7305. if item.Count > warehouse.Count {
  7306. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7307. c.ServeSuccessJSON(map[string]interface{}{
  7308. "message": "1",
  7309. "good_name": goodObj.GoodName,
  7310. "specification_name": goodObj.SpecificationName,
  7311. })
  7312. return
  7313. }
  7314. }
  7315. }
  7316. // 查询信息规挡的设置天数
  7317. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7318. if infor.ID > 0 && infor.WeekDay > 0 {
  7319. var cha_time int64
  7320. timeNowStr := time.Now().Format("2006-01-02")
  7321. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7322. //今日的日期减去设置的日期
  7323. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7324. if cha_time >= record_time {
  7325. //查询审核是否允许
  7326. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7327. //申请状态不允许的情况 拒绝修改
  7328. if infor.ApplicationStatus != 1 {
  7329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7330. return
  7331. }
  7332. }
  7333. }
  7334. //出库逻辑
  7335. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7336. if err != nil {
  7337. utils.ErrorLog(err.Error())
  7338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7339. return
  7340. }
  7341. finish := models.XtDialysisFinish{
  7342. IsFinish: 1,
  7343. UserOrgId: adminInfo.Org.Id,
  7344. Status: 1,
  7345. Ctime: time.Now().Unix(),
  7346. Mtime: 0,
  7347. Module: 11,
  7348. RecordDate: record_time,
  7349. Sourse: 1,
  7350. PatientId: patient_id,
  7351. }
  7352. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7353. if dialysisFinish.ID == 0 {
  7354. service.CreateDialysisFinish(finish)
  7355. }
  7356. //查询当天出库的数据
  7357. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7358. for _, item := range list {
  7359. prepare := models.DialysisBeforePrepare{
  7360. UserOrgId: item.OrgId,
  7361. PatientId: item.PatientId,
  7362. RecordDate: item.RecordTime,
  7363. GoodId: item.GoodId,
  7364. GoodTypeId: item.GoodTypeId,
  7365. Count: item.Count,
  7366. Creater: adminInfo.AdminUser.Id,
  7367. Status: 1,
  7368. Ctime: time.Now().Unix(),
  7369. ProjectId: item.ProjectId,
  7370. StorehouseId: houseConfig.StorehouseOutInfo,
  7371. }
  7372. //清空准备表的数据
  7373. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7374. //插入准备表数据
  7375. service.CreateDialysisBeforePrepareOne(&prepare)
  7376. //查询默认仓库
  7377. //查询默认仓库
  7378. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7379. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7380. var total_count int64
  7381. for _, it := range stockList {
  7382. total_count += it.StockCount
  7383. }
  7384. //基础库插入数据
  7385. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7386. ////更新剩余库存
  7387. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7388. var flush_count int64
  7389. for _, it := range goodList {
  7390. flush_count += it.StockCount
  7391. }
  7392. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7393. if errs != nil {
  7394. goodErrcode := models.XtGoodErrcode{
  7395. UserOrgId: item.OrgId,
  7396. Errcode: "手动出库更新剩余出库失败",
  7397. GoodId: item.GoodId,
  7398. Status: 1,
  7399. Ctime: time.Now().Unix(),
  7400. Mtime: 0,
  7401. Count: 0,
  7402. StockCount: 0,
  7403. Creater: adminInfo.AdminUser.Id,
  7404. BatchNumberId: 0,
  7405. WarehouseOutId: 0,
  7406. }
  7407. service.CreateGoodErrcode(goodErrcode)
  7408. }
  7409. }
  7410. //更新自动出库的地方
  7411. var errs error
  7412. if errs == nil {
  7413. c.ServeSuccessJSON(map[string]interface{}{
  7414. "msg": "修改成功",
  7415. "message": "2",
  7416. "good_name": "",
  7417. "specification_name": "",
  7418. })
  7419. return
  7420. } else {
  7421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7422. return
  7423. }
  7424. }
  7425. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7426. newArr = make([]*models.DialysisBeforePrepare, 0)
  7427. for i := 0; i < len(arr); i++ {
  7428. repeat := false
  7429. for j := i + 1; j < len(arr); j++ {
  7430. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7431. repeat = true
  7432. break
  7433. }
  7434. }
  7435. if !repeat {
  7436. newArr = append(newArr, arr[i])
  7437. }
  7438. }
  7439. return
  7440. }
  7441. func (c *DialysisAPIController) GetAllDrug() {
  7442. patient_id, _ := c.GetInt64("patient_id", 0)
  7443. adminInfo := c.GetMobileAdminUserInfo()
  7444. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7445. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7446. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7447. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7448. c.ServeSuccessJSON(map[string]interface{}{
  7449. "base_drug_config": drugStockConfig,
  7450. "private_drug_config": privateDrugConfig,
  7451. "base_drug_list": drugList,
  7452. "private_drug_list": privateDrugList,
  7453. })
  7454. }
  7455. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7456. newArr = make([]*models.DialysisBeforePrepare, 0)
  7457. for i := 0; i < len(arr); i++ {
  7458. repeat := false
  7459. for j := i + 1; j < len(arr); j++ {
  7460. if arr[i].GoodId == arr[j].GoodId {
  7461. repeat = true
  7462. break
  7463. }
  7464. }
  7465. if !repeat {
  7466. newArr = append(newArr, arr[i])
  7467. }
  7468. }
  7469. return
  7470. }
  7471. func (c *DialysisAPIController) GetDepartment() {
  7472. adminInfo := c.GetMobileAdminUserInfo()
  7473. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7474. if err == nil {
  7475. c.ServeSuccessJSON(map[string]interface{}{
  7476. "departments": departments,
  7477. })
  7478. } else {
  7479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7480. return
  7481. }
  7482. }
  7483. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7484. types, _ := c.GetInt("type", 0)
  7485. start_time := c.GetString("start_time")
  7486. end_time := c.GetString("end_time")
  7487. orgId := c.GetMobileAdminUserInfo().Org.Id
  7488. timeLayout := "2006-01-02"
  7489. loc, _ := time.LoadLocation("Local")
  7490. var startTime int64
  7491. if len(start_time) > 0 {
  7492. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7493. if err != nil {
  7494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7495. return
  7496. }
  7497. startTime = theTime.Unix()
  7498. }
  7499. var endTime int64
  7500. if len(end_time) > 0 {
  7501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7502. if err != nil {
  7503. utils.ErrorLog(err.Error())
  7504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7505. return
  7506. }
  7507. endTime = theTime.Unix()
  7508. }
  7509. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7510. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7511. if err != nil {
  7512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7513. } else {
  7514. c.ServeSuccessJSON(map[string]interface{}{
  7515. "list": list,
  7516. "type": types,
  7517. "stockTotal": stockTotal,
  7518. })
  7519. }
  7520. }
  7521. func (c *DialysisAPIController) GetPrescriptionList() {
  7522. start_time := c.GetString("start_time")
  7523. end_time := c.GetString("end_time")
  7524. schedule_type, _ := c.GetInt64("schedule_type")
  7525. partion_id, _ := c.GetInt64("partion_id")
  7526. orgId := c.GetMobileAdminUserInfo().Org.Id
  7527. timeLayout := "2006-01-02"
  7528. loc, _ := time.LoadLocation("Local")
  7529. var startTime int64
  7530. if len(start_time) > 0 {
  7531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7532. if err != nil {
  7533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7534. return
  7535. }
  7536. startTime = theTime.Unix()
  7537. }
  7538. var endTime int64
  7539. if len(end_time) > 0 {
  7540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7541. if err != nil {
  7542. utils.ErrorLog(err.Error())
  7543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7544. return
  7545. }
  7546. endTime = theTime.Unix()
  7547. }
  7548. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7549. fmt.Println("schedulelist22222222", schedulelist)
  7550. c.ServeSuccessJSON(map[string]interface{}{
  7551. "list": schedulelist,
  7552. })
  7553. return
  7554. }
  7555. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7556. ids := c.GetString("ids")
  7557. //patient_id, _ := c.GetInt64("patient_id")
  7558. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7559. idArray := strings.Split(ids, ",")
  7560. err := service.BatchDeleteMonitor(idArray)
  7561. fmt.Print("err", err)
  7562. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7563. //redis := service.RedisClient()
  7564. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7565. //redis.Set(key, "", time.Second)
  7566. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7567. //redis.Set(keyOne, "", time.Second)
  7568. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7569. //redis.Close()
  7570. c.ServeSuccessJSON(map[string]interface{}{
  7571. "msg": "批量删除成功",
  7572. })
  7573. return
  7574. }
  7575. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7576. id, _ := c.GetInt64("id")
  7577. timeLayout := "2006-01-02"
  7578. loc, _ := time.LoadLocation("Local")
  7579. //start_time := time.Now().Format("2006-01-02")
  7580. start_time := c.GetString("start_time")
  7581. end_time := c.GetString("end_time")
  7582. var startdateunix int64
  7583. if len(start_time) > 0 {
  7584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7585. if err != nil {
  7586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7587. return
  7588. }
  7589. startdateunix = theTime.Unix()
  7590. }
  7591. var enddateunix int64
  7592. if len(end_time) > 0 {
  7593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7594. if err != nil {
  7595. utils.ErrorLog(err.Error())
  7596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7597. return
  7598. }
  7599. enddateunix = theTime.Unix()
  7600. }
  7601. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7602. //nowTime := time.Now()
  7603. //endTime := nowTime.AddDate(-30, 0, 0)
  7604. //endTimes := endTime.Format("2006-01-02")
  7605. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7606. org_id := c.GetMobileAdminUserInfo().Org.Id
  7607. //if org_id == 10579 {
  7608. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7609. // c.ServeSuccessJSON(map[string]interface{}{
  7610. // "list": list,
  7611. // })
  7612. // return
  7613. //} else {
  7614. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7615. // c.ServeSuccessJSON(map[string]interface{}{
  7616. // "list": list,
  7617. // })
  7618. // return
  7619. //}
  7620. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7621. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7622. c.ServeSuccessJSON(map[string]interface{}{
  7623. "list": list,
  7624. })
  7625. return
  7626. } else {
  7627. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7628. c.ServeSuccessJSON(map[string]interface{}{
  7629. "list": list,
  7630. })
  7631. }
  7632. return
  7633. }
  7634. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7635. dataBody := make(map[string]interface{}, 0)
  7636. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7637. ids := c.GetString("ids")
  7638. idArray := strings.Split(ids, ",")
  7639. origin, _ := c.GetInt64("origin")
  7640. if origin == 1 {
  7641. err = service.BatchDeleteAdvice(idArray)
  7642. fmt.Print("err", err)
  7643. c.ServeSuccessJSON(map[string]interface{}{
  7644. "msg": "批量删除成功",
  7645. })
  7646. return
  7647. }
  7648. if origin == 2 {
  7649. service.BatchDeleteHisAdvice(idArray)
  7650. }
  7651. }
  7652. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7653. good_id, _ := c.GetInt64("good_id")
  7654. count, _ := c.GetInt64("count")
  7655. record_time, _ := c.GetInt64("record_time")
  7656. patient_id, _ := c.GetInt64("patient_id")
  7657. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7658. c.ServeSuccessJSON(map[string]interface{}{
  7659. "detail": detail,
  7660. })
  7661. return
  7662. }
  7663. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7664. good_id, _ := c.GetInt64("good_id")
  7665. record_time, _ := c.GetInt64("record_time")
  7666. patient_id, _ := c.GetInt64("patient_id")
  7667. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7668. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7669. fmt.Print("err", err)
  7670. c.ServeSuccessJSON(map[string]interface{}{
  7671. "msg": "批量删除成功",
  7672. })
  7673. return
  7674. }
  7675. func (c *DialysisAPIController) BatchAdviceCheck() {
  7676. ids := c.GetString("ids")
  7677. idArray := strings.Split(ids, ",")
  7678. creator, _ := c.GetInt64("creator")
  7679. origin, _ := c.GetInt64("origin")
  7680. if origin == 1 {
  7681. err := service.BatchAdviceCheck(idArray, creator)
  7682. fmt.Println(err)
  7683. list, _ := service.GetAdviceExecutionById(idArray)
  7684. c.ServeSuccessJSON(map[string]interface{}{
  7685. "list": list,
  7686. })
  7687. return
  7688. }
  7689. if origin == 2 {
  7690. service.BatchHisAdviceCheck(idArray, creator)
  7691. list, _ := service.GetHisAdviceExecutionById(idArray)
  7692. c.ServeSuccessJSON(map[string]interface{}{
  7693. "list": list,
  7694. })
  7695. return
  7696. }
  7697. }
  7698. func (c *DialysisAPIController) BatchAdviceExecution() {
  7699. ids := c.GetString("ids")
  7700. idArray := strings.Split(ids, ",")
  7701. executionTime := c.GetString("execution_time")
  7702. creator, _ := c.GetInt64("creator")
  7703. timeLayout := "2006-01-02 15:04:05"
  7704. loc, _ := time.LoadLocation("Local")
  7705. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7706. orgin, _ := c.GetInt64("origin")
  7707. if orgin == 1 {
  7708. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7709. list, _ := service.GetAdviceExecutionById(idArray)
  7710. fmt.Println(err)
  7711. c.ServeSuccessJSON(map[string]interface{}{
  7712. "list": list,
  7713. })
  7714. return
  7715. }
  7716. if orgin == 2 {
  7717. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7718. list, _ := service.GetHisAdviceExecutionById(idArray)
  7719. fmt.Println(err)
  7720. c.ServeSuccessJSON(map[string]interface{}{
  7721. "list": list,
  7722. })
  7723. return
  7724. }
  7725. }
  7726. func (c *DialysisAPIController) UpdateStockGoods() {
  7727. good_id, _ := c.GetInt64("good_id")
  7728. record_time, _ := c.GetInt64("record_time")
  7729. patient_id, _ := c.GetInt64("patient_id")
  7730. count, _ := c.GetInt64("count")
  7731. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7732. fmt.Print("err", err)
  7733. c.ServeSuccessJSON(map[string]interface{}{
  7734. "msg": "更新成功",
  7735. })
  7736. return
  7737. }
  7738. // 当前数据比上一次出库数据少
  7739. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7740. //查询该患者当天已经出库的耗材信息
  7741. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7742. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7743. for i := len(goods_yc) - 1; i >= 0; i-- {
  7744. goods_yc_temp := goods_yc[i]
  7745. for j := len(goods) - 1; j >= 0; j-- {
  7746. goods_temp := goods[j]
  7747. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7748. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7749. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7750. if goods_yc_temp.Count == goods_temp.Count {
  7751. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7752. goods = append(goods[:j], goods[j+1:]...)
  7753. break
  7754. }
  7755. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7756. if goods_yc_temp.Count > goods_temp.Count {
  7757. temp_count := goods_yc_temp.Count - goods_temp.Count
  7758. goods_yc[i].Count = temp_count
  7759. goods = append(goods[:j], goods[j+1:]...)
  7760. break
  7761. }
  7762. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7763. if goods_yc_temp.Count < goods_temp.Count {
  7764. temp_count := goods_temp.Count - goods_yc_temp.Count
  7765. goods[j].Count = temp_count
  7766. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7767. break
  7768. }
  7769. }
  7770. }
  7771. }
  7772. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7773. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7774. //退库
  7775. if len(goods_yc) > 0 {
  7776. for _, good_yc := range goods_yc {
  7777. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7778. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7779. }
  7780. }
  7781. return nil
  7782. }
  7783. // 耗材出库删除
  7784. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7785. // 先根据相关信息查询当天该耗材的出库信息
  7786. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7787. if err != nil {
  7788. return err
  7789. }
  7790. var delete_count int64 = 0
  7791. delete_count = warehouseOutInfos.Count - count
  7792. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7793. // 在出库记录表里记录退库详情
  7794. warehouseOutInfo := &models.WarehouseOutInfo{
  7795. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7796. WarehouseOutId: warehouseOut.ID,
  7797. Status: 1,
  7798. Ctime: time.Now().Unix(),
  7799. OrgId: orgID,
  7800. Type: 1,
  7801. IsSys: 1,
  7802. SysRecordTime: record_time,
  7803. GoodTypeId: good_yc.GoodTypeId,
  7804. GoodId: good_yc.GoodId,
  7805. PatientId: good_yc.PatientId,
  7806. ConsumableType: 2,
  7807. StorehouseId: houseConfig.StorehouseOutInfo,
  7808. IsCheck: 1,
  7809. }
  7810. warehouseOutInfo.Count = count
  7811. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7812. warehouseOutInfo.Price = stockInInfo.Price
  7813. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7814. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7815. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7816. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7817. warehouseOutInfo.Number = warehouseOutInfos.Number
  7818. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7819. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7820. //查找当天是否存在出库记录
  7821. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7822. if errcod == gorm.ErrRecordNotFound {
  7823. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7824. //插入详情明细表
  7825. stockFlow := models.VmStockFlow{
  7826. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7827. WarehouseOutId: warehouseOut.ID,
  7828. GoodId: good_yc.GoodId,
  7829. Number: warehouseOutInfos.Number,
  7830. ProductDate: stockInInfo.ProductDate,
  7831. ExpireDate: stockInInfo.ExpiryDate,
  7832. Count: count,
  7833. Price: stockInInfo.Price,
  7834. Status: 1,
  7835. Ctime: time.Now().Unix(),
  7836. UserOrgId: good_yc.OrgId,
  7837. Manufacturer: stockInInfo.Manufacturer,
  7838. Dealer: stockInInfo.Dealer,
  7839. LicenseNumber: stockInInfo.LicenseNumber,
  7840. IsEdit: 2,
  7841. Creator: creater,
  7842. SystemTime: record_time,
  7843. ConsumableType: 3,
  7844. WarehousingDetailId: 0,
  7845. IsSys: 1,
  7846. UpdateCreator: creater,
  7847. PatientId: patient_id,
  7848. StorehouseId: houseConfig.StorehouseOutInfo,
  7849. }
  7850. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7851. if errflow == gorm.ErrRecordNotFound {
  7852. //创建流水表
  7853. err := service.CreateStockFlowOne(stockFlow)
  7854. fmt.Println("err", err)
  7855. } else if errflow == nil {
  7856. //插入详情明细表
  7857. stockFlow := models.VmStockFlow{
  7858. ID: exsit.ID,
  7859. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7860. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7861. WarehouseOutId: warehouseOut.ID,
  7862. GoodId: good_yc.GoodId,
  7863. Number: warehouseOutInfos.Number,
  7864. ProductDate: stockInInfo.ProductDate,
  7865. ExpireDate: stockInInfo.ExpiryDate,
  7866. Count: exsit.Count - delete_count,
  7867. Price: stockInInfo.Price,
  7868. Status: 1,
  7869. Ctime: time.Now().Unix(),
  7870. UserOrgId: good_yc.OrgId,
  7871. Manufacturer: stockInInfo.Manufacturer,
  7872. Dealer: stockInInfo.Dealer,
  7873. LicenseNumber: stockInInfo.LicenseNumber,
  7874. IsEdit: 2,
  7875. Creator: creater,
  7876. SystemTime: record_time,
  7877. ConsumableType: 3,
  7878. WarehousingDetailId: 0,
  7879. IsSys: 1,
  7880. UpdateCreator: creater,
  7881. PatientId: patient_id,
  7882. StorehouseId: houseConfig.StorehouseOutInfo,
  7883. }
  7884. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7885. }
  7886. if errOne != nil {
  7887. return errOne
  7888. }
  7889. } else if errcod == nil {
  7890. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7891. //插入详情明细表
  7892. stockFlow := models.VmStockFlow{
  7893. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7894. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7895. WarehouseOutId: warehouseOut.ID,
  7896. GoodId: good_yc.GoodId,
  7897. Number: warehouseOutInfos.Number,
  7898. ProductDate: stockInInfo.ProductDate,
  7899. ExpireDate: stockInInfo.ExpiryDate,
  7900. Count: count,
  7901. Price: stockInInfo.Price,
  7902. Status: 1,
  7903. Ctime: time.Now().Unix(),
  7904. UserOrgId: good_yc.OrgId,
  7905. Manufacturer: stockInInfo.Manufacturer,
  7906. Dealer: stockInInfo.Dealer,
  7907. LicenseNumber: stockInInfo.LicenseNumber,
  7908. IsEdit: 2,
  7909. Creator: creater,
  7910. SystemTime: record_time,
  7911. ConsumableType: 3,
  7912. WarehousingDetailId: 0,
  7913. IsSys: 1,
  7914. UpdateCreator: creater,
  7915. PatientId: patient_id,
  7916. ReturnCount: delete_count,
  7917. StorehouseId: houseConfig.StorehouseOutInfo,
  7918. }
  7919. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7920. if errflows == gorm.ErrRecordNotFound {
  7921. //创建流水表
  7922. service.CreateStockFlowOne(stockFlow)
  7923. } else if errflows == nil {
  7924. stockFlow := models.VmStockFlow{
  7925. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7926. ID: exsit.ID,
  7927. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7928. WarehouseOutId: warehouseOut.ID,
  7929. GoodId: good_yc.GoodId,
  7930. Number: warehouseOutInfos.Number,
  7931. ProductDate: stockInInfo.ProductDate,
  7932. ExpireDate: stockInInfo.ExpiryDate,
  7933. Count: exsit.Count - delete_count,
  7934. Price: stockInInfo.Price,
  7935. Status: 1,
  7936. Ctime: time.Now().Unix(),
  7937. UserOrgId: good_yc.OrgId,
  7938. Manufacturer: stockInInfo.Manufacturer,
  7939. Dealer: stockInInfo.Dealer,
  7940. LicenseNumber: stockInInfo.LicenseNumber,
  7941. IsEdit: 2,
  7942. Creator: creater,
  7943. SystemTime: record_time,
  7944. ConsumableType: 3,
  7945. WarehousingDetailId: 0,
  7946. IsSys: 1,
  7947. UpdateCreator: creater,
  7948. PatientId: patient_id,
  7949. ReturnCount: delete_count,
  7950. StorehouseId: houseConfig.StorehouseOutInfo,
  7951. }
  7952. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7953. }
  7954. }
  7955. //更改自动出库的表格
  7956. details := models.BloodAutomaticReduceDetail{
  7957. WarehouseOutId: warehouseOutInfo.ID,
  7958. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7959. PatientId: patient_id,
  7960. Ctime: time.Now().Unix(),
  7961. Mtime: time.Now().Unix(),
  7962. Status: 1,
  7963. RecordTime: record_time,
  7964. OrgId: orgID,
  7965. GoodId: good_yc.GoodId,
  7966. GoodTypeId: good_yc.GoodTypeId,
  7967. Count: count,
  7968. StorehouseId: houseConfig.StorehouseOutInfo,
  7969. }
  7970. //查询当天耗材是否已经存在数据
  7971. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7972. if errcode == gorm.ErrRecordNotFound {
  7973. errTwo := service.CreateAutoReduceRecord(&details)
  7974. if errTwo != nil {
  7975. return errTwo
  7976. }
  7977. } else if errcode == nil {
  7978. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7979. service.CreateAutoReduceRecord(&details)
  7980. }
  7981. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7982. //增加出库库存数量
  7983. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7984. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7985. fmt.Println("errOne", errOne)
  7986. // 删除出库完成后,要增加对应批次的库存数量
  7987. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7988. if errThree != nil {
  7989. return errThree
  7990. }
  7991. if good_yc.Count == 0 {
  7992. return nil
  7993. } else {
  7994. return errors.New("退库和出库数据不匹配")
  7995. }
  7996. }
  7997. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7998. //查询该患者当天已经出库的耗材信息
  7999. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8000. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8001. for i := len(goods_yc) - 1; i >= 0; i-- {
  8002. goods_yc_temp := goods_yc[i]
  8003. for j := len(goods) - 1; j >= 0; j-- {
  8004. goods_temp := goods[j]
  8005. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8006. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8007. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8008. if goods_yc_temp.Count == goods_temp.Count {
  8009. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8010. goods = append(goods[:j], goods[j+1:]...)
  8011. break
  8012. }
  8013. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8014. if goods_yc_temp.Count > goods_temp.Count {
  8015. temp_count := goods_yc_temp.Count - goods_temp.Count
  8016. goods_yc[i].Count = temp_count
  8017. goods = append(goods[:j], goods[j+1:]...)
  8018. break
  8019. }
  8020. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8021. if goods_yc_temp.Count < goods_temp.Count {
  8022. temp_count := goods_temp.Count - goods_yc_temp.Count
  8023. goods[j].Count = temp_count
  8024. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8025. break
  8026. }
  8027. }
  8028. }
  8029. }
  8030. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8031. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8032. fmt.Println("剩余需要出库的", len(goods))
  8033. if len(goods) > 0 {
  8034. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8035. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8036. if err == gorm.ErrRecordNotFound {
  8037. //没有记录,则创建出库单
  8038. timeStr := time.Now().Format("2006-01-02")
  8039. timeArr := strings.Split(timeStr, "-")
  8040. total, _ := service.FindAllWarehouseOut(orgID)
  8041. total = total + 1
  8042. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8043. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8044. number = number + total
  8045. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8046. warehouseOut := models.WarehouseOut{
  8047. WarehouseOutOrderNumber: warehousing_out_order,
  8048. OperationTime: time.Now().Unix(),
  8049. OrgId: orgID,
  8050. Creater: creater,
  8051. Ctime: time.Now().Unix(),
  8052. Status: 1,
  8053. WarehouseOutTime: record_time,
  8054. Dealer: 0,
  8055. Manufacturer: 0,
  8056. Type: 1,
  8057. IsSys: 1,
  8058. StorehouseId: houseConfig.StorehouseOutInfo,
  8059. IsCheck: 1,
  8060. }
  8061. err := service.AddSigleWarehouseOut(&warehouseOut)
  8062. if err != nil {
  8063. utils.TraceLog("创建出库单失败 err = %v", err)
  8064. return err
  8065. } else {
  8066. out = warehouseOut
  8067. }
  8068. }
  8069. for _, item := range goods {
  8070. var newCount int64 = 0
  8071. for _, it := range goodOne {
  8072. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8073. newCount = it.Count
  8074. }
  8075. }
  8076. prepare := models.DialysisBeforePrepare{
  8077. GoodTypeId: item.GoodTypeId,
  8078. GoodId: item.GoodId,
  8079. Count: item.Count,
  8080. StorehouseId: houseConfig.StorehouseOutInfo,
  8081. }
  8082. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8083. //增加出库数量
  8084. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8085. }
  8086. }
  8087. if len(goods_yc) > 0 {
  8088. for _, good_yc := range goods_yc {
  8089. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8090. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8091. }
  8092. }
  8093. return nil
  8094. }
  8095. // 耗材出库删除
  8096. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8097. // 先根据相关信息查询当天该耗材的出库信息
  8098. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8099. if err != nil {
  8100. return err
  8101. }
  8102. var delete_count int64 = 0
  8103. for _, ware := range warehouseOutInfos {
  8104. // 判断当前出库的数据和删除出库数量
  8105. if good_yc.Count <= ware.Count {
  8106. delete_count = good_yc.Count
  8107. } else {
  8108. delete_count = ware.Count
  8109. }
  8110. warehouseOutInfo := &models.WarehouseOutInfo{
  8111. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8112. WarehouseOutId: warehouseOut.ID,
  8113. Status: 1,
  8114. Ctime: time.Now().Unix(),
  8115. Remark: "",
  8116. OrgId: orgID,
  8117. Type: 1,
  8118. Manufacturer: 0,
  8119. Dealer: 0,
  8120. IsSys: 0,
  8121. SysRecordTime: record_time,
  8122. GoodTypeId: good_yc.GoodTypeId,
  8123. GoodId: good_yc.GoodId,
  8124. StorehouseId: warehouseOut.StorehouseId,
  8125. IsCheck: 1,
  8126. }
  8127. warehouseOutInfo.Count = delete_count
  8128. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8129. warehouseOutInfo.Price = stockInInfo.Price
  8130. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8131. if errOne != nil {
  8132. return errOne
  8133. }
  8134. // 删除出库完成后,要改变流水库存(有疑问)
  8135. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8136. fmt.Println("errOne", errOne)
  8137. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8138. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8139. //扣减出库数量
  8140. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8141. if errThree != nil {
  8142. return errThree
  8143. }
  8144. }
  8145. if good_yc.Count == 0 {
  8146. return nil
  8147. } else {
  8148. return errors.New("退库和出库数据不匹配")
  8149. }
  8150. }
  8151. func (this *DialysisAPIController) GetMobileScheduleList() {
  8152. limit, _ := this.GetInt64("limit")
  8153. page, _ := this.GetInt64("page")
  8154. type_options_visible, _ := this.GetInt64("type_options_visible")
  8155. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8156. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8157. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8158. }
  8159. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8160. newArr = make([]*models.HisPrescriptionProject, 0)
  8161. for i := 0; i < len(arr); i++ {
  8162. repeat := false
  8163. for j := i + 1; j < len(arr); j++ {
  8164. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8165. repeat = true
  8166. break
  8167. }
  8168. }
  8169. if !repeat {
  8170. newArr = append(newArr, arr[i])
  8171. }
  8172. }
  8173. return
  8174. }
  8175. func (this *DialysisAPIController) GetRoleList() {
  8176. admin_user_id, _ := this.GetInt64("admin_user_id")
  8177. orgid := this.GetMobileAdminUserInfo().Org.Id
  8178. list, err := service.GetRoleList(orgid, admin_user_id)
  8179. fmt.Println(err)
  8180. this.ServeSuccessJSON(map[string]interface{}{
  8181. "list": list,
  8182. })
  8183. return
  8184. }
  8185. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8186. // 先根据相关信息查询当天该耗材的出库信息
  8187. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8188. if err != nil {
  8189. return err
  8190. }
  8191. var delete_count int64 = 0
  8192. delete_count = warehouseOutInfos.Count - count
  8193. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8194. // 删除出库完成后,要增加对应批次的库存数量
  8195. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8196. if errThree != nil {
  8197. return errThree
  8198. }
  8199. //增加退库数量
  8200. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8201. //扣减出库数量
  8202. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8203. //查询剩余库存
  8204. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8205. var sum_count int64
  8206. for _, item := range goodList {
  8207. sum_count += item.StockCount
  8208. }
  8209. // 在出库记录表里记录退库详情
  8210. warehouseOutInfo := &models.WarehouseOutInfo{
  8211. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8212. WarehouseOutId: warehouseOut.ID,
  8213. Status: 1,
  8214. Ctime: time.Now().Unix(),
  8215. OrgId: orgID,
  8216. Type: 1,
  8217. IsSys: 1,
  8218. SysRecordTime: record_time,
  8219. GoodTypeId: good_yc.GoodTypeId,
  8220. GoodId: good_yc.GoodId,
  8221. PatientId: good_yc.PatientId,
  8222. ConsumableType: 2,
  8223. StorehouseId: houseConfig.StorehouseOutInfo,
  8224. IsCheck: 1,
  8225. OverCount: sum_count,
  8226. }
  8227. warehouseOutInfo.Count = count
  8228. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8229. warehouseOutInfo.Price = stockInInfo.Price
  8230. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8231. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8232. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8233. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8234. warehouseOutInfo.Number = warehouseOutInfos.Number
  8235. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8236. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8237. //查找当天是否存在出库记录
  8238. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8239. if errcod == gorm.ErrRecordNotFound {
  8240. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8241. //插入详情明细表
  8242. if errOne != nil {
  8243. return errOne
  8244. }
  8245. //插入详情明细表
  8246. stockFlow := models.VmStockFlow{
  8247. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8248. WarehouseOutId: warehouseOut.ID,
  8249. GoodId: good_yc.GoodId,
  8250. Number: warehouseOutInfos.Number,
  8251. ProductDate: stockInInfo.ProductDate,
  8252. ExpireDate: stockInInfo.ExpiryDate,
  8253. Count: count,
  8254. Price: stockInInfo.Price,
  8255. Status: 1,
  8256. Ctime: record_time,
  8257. UserOrgId: good_yc.OrgId,
  8258. Manufacturer: stockInInfo.Manufacturer,
  8259. Dealer: stockInInfo.Dealer,
  8260. LicenseNumber: stockInInfo.LicenseNumber,
  8261. IsEdit: 2,
  8262. Creator: creater,
  8263. SystemTime: record_time,
  8264. ConsumableType: 3,
  8265. WarehousingDetailId: 0,
  8266. IsSys: 1,
  8267. UpdateCreator: creater,
  8268. PatientId: patient_id,
  8269. StorehouseId: houseConfig.StorehouseOutInfo,
  8270. OverCount: sum_count,
  8271. ProjectId: good_yc.ProjectId,
  8272. }
  8273. err := service.CreateStockFlowOne(stockFlow)
  8274. fmt.Println("err", err)
  8275. } else if errcod == nil {
  8276. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8277. }
  8278. //创建退库单
  8279. operation_time := time.Now().Unix()
  8280. //创建退库单
  8281. timeStr := time.Now().Format("2006-01-02")
  8282. timeArr := strings.Split(timeStr, "-")
  8283. total, _ := service.FindAllCancelStockTotal(orgID)
  8284. total = total + 1
  8285. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8286. cancelStock := models.CancelStock{
  8287. OrderNumber: orderNumber,
  8288. OperaTime: operation_time,
  8289. OrgId: orgID,
  8290. Creater: warehouseOut.Creater,
  8291. Ctime: time.Now().Unix(),
  8292. Status: 1,
  8293. ReturnTime: record_time,
  8294. Type: 1,
  8295. StorehouseId: stockInInfo.StorehouseId,
  8296. IsCheck: 1,
  8297. }
  8298. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8299. if msgerrkonde == gorm.ErrRecordNotFound {
  8300. service.AddSigleCancelStock(&cancelStock)
  8301. }
  8302. cancel, _ := service.GetLastCancelStockById(orgID)
  8303. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8304. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8305. cancelStockInfo := models.CancelStockInfo{
  8306. GoodId: stockInInfo.GoodId,
  8307. CancelStockId: cancel.ID,
  8308. GoodTypeId: stockInInfo.GoodTypeId,
  8309. Count: delete_count,
  8310. Price: stockInInfo.PackingPrice,
  8311. Total: 0,
  8312. ProductDate: stockInInfo.ProductDate,
  8313. ExpiryDate: stockInInfo.ExpiryDate,
  8314. Ctime: record_time,
  8315. Status: 1,
  8316. OrgId: orgID,
  8317. OrderNumber: cancel.OrderNumber,
  8318. Type: 0,
  8319. Dealer: deaerler.DealerName,
  8320. Manufacturer: manufacturer.ManufacturerName,
  8321. Number: stockInInfo.Number,
  8322. RegisterAccount: "",
  8323. Remark: "",
  8324. WarehouseInfoId: stockInInfo.ID,
  8325. PatientId: patient_id,
  8326. RecordDate: record_time,
  8327. StorehouseId: stockInInfo.StorehouseId,
  8328. IsCheck: 1,
  8329. }
  8330. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8331. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8332. flow := models.VmStockFlow{
  8333. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8334. GoodId: good_yc.GoodId,
  8335. Number: warehouseOutInfos.Number,
  8336. LicenseNumber: stockInInfo.LicenseNumber,
  8337. Count: delete_count,
  8338. UserOrgId: orgID,
  8339. PatientId: patient_id,
  8340. SystemTime: record_time,
  8341. ConsumableType: 7,
  8342. IsSys: 0,
  8343. WarehousingOrder: "",
  8344. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8345. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8346. IsEdit: 0,
  8347. CancelStockId: cancel.ID,
  8348. CancelOrderNumber: cancel.OrderNumber,
  8349. Manufacturer: manufacturer.ID,
  8350. Dealer: 0,
  8351. Creator: warehouseOut.Creater,
  8352. UpdateCreator: 0,
  8353. Status: 1,
  8354. Ctime: record_time,
  8355. Mtime: 0,
  8356. Price: stockInInfo.Price,
  8357. WarehousingDetailId: stockInInfo.ID,
  8358. WarehouseOutDetailId: warehouseOutInfos.ID,
  8359. CancelOutDetailId: cancelInfo.ID,
  8360. ProductDate: stockInInfo.ProductDate,
  8361. ExpireDate: stockInInfo.ExpiryDate,
  8362. StorehouseId: houseConfig.StorehouseOutInfo,
  8363. OverCount: sum_count,
  8364. }
  8365. service.CreateStockFlowOne(flow)
  8366. //更改自动出库的表格
  8367. details := models.BloodAutomaticReduceDetail{
  8368. WarehouseOutId: warehouseOutInfo.ID,
  8369. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8370. PatientId: patient_id,
  8371. Ctime: time.Now().Unix(),
  8372. Mtime: time.Now().Unix(),
  8373. Status: 1,
  8374. RecordTime: record_time,
  8375. OrgId: orgID,
  8376. GoodId: good_yc.GoodId,
  8377. GoodTypeId: good_yc.GoodTypeId,
  8378. Count: count,
  8379. StorehouseId: houseConfig.StorehouseOutInfo,
  8380. }
  8381. //查询当天耗材是否已经存在数据
  8382. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8383. if errcode == gorm.ErrRecordNotFound {
  8384. errTwo := service.CreateAutoReduceRecord(&details)
  8385. if errTwo != nil {
  8386. return errTwo
  8387. }
  8388. } else if errcode == nil {
  8389. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8390. service.CreateAutoReduceRecord(&details)
  8391. }
  8392. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8393. //增加出库库存数量
  8394. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8395. if good_yc.Count == 0 {
  8396. return nil
  8397. } else {
  8398. return errors.New("退库和出库数据不匹配")
  8399. }
  8400. }
  8401. func (this *DialysisAPIController) SavePatientSign() {
  8402. adminUserInfo := this.GetMobileAdminUserInfo()
  8403. patient_id, _ := this.GetInt64("patient_id")
  8404. dialysis_date, _ := this.GetInt64("dialysis_date")
  8405. orgid := adminUserInfo.Org.Id
  8406. var esdata models.DialysisOrder
  8407. var err error
  8408. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8410. return
  8411. }
  8412. esdata.Hash = esdata.Hash
  8413. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8414. order := models.DialysisOrder{
  8415. Hash: esdata.Hash,
  8416. Url: esdata.Url,
  8417. }
  8418. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8419. redis := service.RedisClient()
  8420. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8421. redis.Set(key, "", time.Second)
  8422. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8423. //清空key 值
  8424. redis.Set(keyOne, "", time.Second)
  8425. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8426. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8427. //redis.Set(keyTwo, "", time.Second)
  8428. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8429. redis.Set(keyThree, "", time.Second)
  8430. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8431. redis.Set(keyFour, "", time.Second)
  8432. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8433. redis.Set(keyFive, "", time.Second)
  8434. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8435. redis.Set(keySix, "", time.Second)
  8436. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8437. redis.Set(keySeven, "", time.Second)
  8438. if err != nil {
  8439. fmt.Println(err)
  8440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8441. return
  8442. }
  8443. this.ServeSuccessJSON(map[string]interface{}{
  8444. "electronic_signature": esdata,
  8445. })
  8446. }
  8447. func (this *DialysisAPIController) GetPatientSign() {
  8448. patient_id, _ := this.GetInt64("patient_id")
  8449. dialysis_date, _ := this.GetInt64("dialysis_date")
  8450. adminUserInfo := this.GetMobileAdminUserInfo()
  8451. orgId := adminUserInfo.Org.Id
  8452. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8453. if err != nil {
  8454. fmt.Println(err)
  8455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8456. return
  8457. }
  8458. this.ServeSuccessJSON(map[string]interface{}{
  8459. "dialysisOrder": dialysisOrder,
  8460. })
  8461. }
  8462. func (this *DialysisAPIController) GetScheduleByPatient() {
  8463. patient_id, _ := this.GetInt64("patient_id")
  8464. schedule_date, _ := this.GetInt64("schedule_date")
  8465. orgid := this.GetMobileAdminUserInfo().Org.Id
  8466. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8467. this.ServeSuccessJSON(map[string]interface{}{
  8468. "schedule": schedule,
  8469. })
  8470. }
  8471. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8472. org_id := this.GetMobileAdminUserInfo().Org.Id
  8473. patient_id, _ := this.GetInt64("patient_id")
  8474. schedule_date, _ := this.GetInt64("schedule_date")
  8475. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8476. this.ServeSuccessJSON(map[string]interface{}{
  8477. "order": order,
  8478. })
  8479. }
  8480. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8481. org_id := this.GetMobileAdminUserInfo().Org.Id
  8482. schedule_date := this.GetString("schedule_date")
  8483. schedule_type, _ := this.GetInt64("schedule_type")
  8484. timeLayout := "2006-01-02"
  8485. loc, _ := time.LoadLocation("Local")
  8486. var startdateunix int64
  8487. if len(schedule_date) > 0 {
  8488. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8489. if err != nil {
  8490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8491. return
  8492. }
  8493. startdateunix = theTime.Unix()
  8494. }
  8495. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8496. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8497. devices, _ := service.GetAllDevicetByListSix(org_id)
  8498. for key, item := range scheduals {
  8499. // 床位信息
  8500. for _, device := range devices {
  8501. if item.BedId == device.ID {
  8502. scheduals[key].DeviceNumber = device
  8503. break
  8504. }
  8505. }
  8506. }
  8507. this.ServeSuccessJSON(map[string]interface{}{
  8508. "list": list,
  8509. "scheduals": scheduals,
  8510. })
  8511. }
  8512. func (this *DialysisAPIController) SavePatientPicture() {
  8513. patient_id, _ := this.GetInt64("patient_id")
  8514. dialysis_date, _ := this.GetInt64("schedule_date")
  8515. avatar := this.GetString("avatar")
  8516. fmt.Println("patient_id", patient_id)
  8517. orgId := this.GetMobileAdminUserInfo().Org.Id
  8518. order := models.DialysisOrder{
  8519. Url: avatar,
  8520. }
  8521. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8522. redis := service.RedisClient()
  8523. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8524. redis.Set(key, "", time.Second)
  8525. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8526. //清空key 值
  8527. redis.Set(keyOne, "", time.Second)
  8528. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8529. redis.Set(keyThree, "", time.Second)
  8530. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8531. redis.Set(keyFour, "", time.Second)
  8532. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8533. redis.Set(keyFive, "", time.Second)
  8534. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8535. redis.Set(keySix, "", time.Second)
  8536. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8537. redis.Set(keySeven, "", time.Second)
  8538. if err != nil {
  8539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8540. return
  8541. }
  8542. this.ServeSuccessJSON(map[string]interface{}{
  8543. "order": order,
  8544. })
  8545. }
  8546. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8547. ids := this.GetString("ids")
  8548. idSplit := strings.Split(ids, ",")
  8549. orgId := this.GetMobileAdminUserInfo().Org.Id
  8550. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8551. execution_time := this.GetString("exce_time")
  8552. timeLayout2 := "2006-01-02 15:04:05"
  8553. loc, _ := time.LoadLocation("Local")
  8554. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8555. if errs != nil {
  8556. utils.ErrorLog(errs.Error())
  8557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8558. return
  8559. }
  8560. //his客户
  8561. if config.IsOpen == 1 {
  8562. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8563. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8564. for _, item := range list {
  8565. for _, it := range adviceList {
  8566. if item.DrugId == it.DrugId {
  8567. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8568. }
  8569. }
  8570. }
  8571. for _, item := range list {
  8572. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8573. var sum_out_count int64
  8574. for _, itemThree := range item.ChildDoctorAdvice {
  8575. var prescribing_number int64
  8576. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8577. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8578. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8579. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8580. }
  8581. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8582. prescribing_number = parseIntPrescribingNumber
  8583. }
  8584. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8585. prescribing_number = parseIntPrescribingNumber
  8586. }
  8587. sum_out_count += prescribing_number
  8588. }
  8589. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8590. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8591. //库存不足
  8592. if sum_out_count > drugStockOut.FlushCount {
  8593. this.ServeSuccessJSON(map[string]interface{}{
  8594. "msg": "2",
  8595. "drug": medical,
  8596. "ids": ids,
  8597. })
  8598. return
  8599. }
  8600. }
  8601. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8602. //执行医嘱
  8603. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8604. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8605. for _, item := range advices {
  8606. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8607. redis := service.RedisClient()
  8608. //清空key 值
  8609. redis.Set(key, "", time.Second)
  8610. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8611. redis.Set(keyTwo, "", time.Second)
  8612. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8613. redis.Set(keyThree, "", time.Second)
  8614. recordDate := theTime.Format("2006-01-02")
  8615. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8616. redis.Set(keyFour, "", time.Second)
  8617. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8618. redis.Set(keyFive, "", time.Second)
  8619. defer redis.Close()
  8620. }
  8621. if errs == nil {
  8622. //药品管理信息
  8623. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8624. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8625. if drugStockConfig.IsOpen == 1 {
  8626. for _, item := range advices {
  8627. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8628. config, _ := service.GetDrugOpenConfigOne(orgId)
  8629. if config.IsOpen != 1 {
  8630. //查询该药品是否有库存
  8631. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8632. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8633. if medical.IsUse == 2 {
  8634. if config.IsOpen != 1 {
  8635. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8636. service.HisDrugsDelivery(orgId, creater, &advice)
  8637. if orgId == 3877 || orgId == 10265 {
  8638. //查询该药品是否有出库记录
  8639. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8640. if len(flowMap) == 0 {
  8641. errs := service.UpdateHisAdviceById(advice.ID)
  8642. if errs != nil {
  8643. drugError := models.XtDrugError{
  8644. UserOrgId: orgId,
  8645. DrugId: item.DrugId,
  8646. RecordDate: item.AdviceDate,
  8647. PatientId: item.PatientId,
  8648. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8649. Status: 1,
  8650. Ctime: time.Now().Unix(),
  8651. Mtime: 0,
  8652. SumCount: 0,
  8653. Prescribingnumber: advice.PrescribingNumber,
  8654. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8655. }
  8656. service.CreateDrugError(drugError)
  8657. }
  8658. this.ServeSuccessJSON(map[string]interface{}{
  8659. "msg": "2",
  8660. "drug": medical,
  8661. "ids": ids,
  8662. })
  8663. return
  8664. }
  8665. }
  8666. }
  8667. if pharmacyConfig.IsOpen != 1 {
  8668. service.HisDrugsDelivery(orgId, creater, &advice)
  8669. if orgId == 3877 || orgId == 10265 {
  8670. //查询该药品是否有出库记录
  8671. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8672. if len(flowMap) == 0 {
  8673. errs := service.UpdateHisAdviceById(advice.ID)
  8674. if errs != nil {
  8675. drugError := models.XtDrugError{
  8676. UserOrgId: orgId,
  8677. DrugId: item.DrugId,
  8678. RecordDate: item.AdviceDate,
  8679. PatientId: item.PatientId,
  8680. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8681. Status: 1,
  8682. Ctime: time.Now().Unix(),
  8683. Mtime: 0,
  8684. SumCount: 0,
  8685. Prescribingnumber: advice.PrescribingNumber,
  8686. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8687. }
  8688. service.CreateDrugError(drugError)
  8689. }
  8690. this.ServeSuccessJSON(map[string]interface{}{
  8691. "msg": "2",
  8692. "drug": medical,
  8693. "ids": ids,
  8694. })
  8695. return
  8696. }
  8697. }
  8698. }
  8699. //更新字典里面的库存
  8700. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8701. var sum_count int64
  8702. for _, its := range stockInfo {
  8703. if its.MaxUnit == medical.MaxUnit {
  8704. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8705. }
  8706. sum_count += its.StockMaxNumber + its.StockMinNumber
  8707. }
  8708. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8709. //剩余库存
  8710. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8711. }
  8712. }
  8713. }
  8714. }
  8715. }
  8716. this.ServeSuccessJSON(map[string]interface{}{
  8717. "msg": "1",
  8718. "ids": ids,
  8719. })
  8720. return
  8721. } else {
  8722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8723. }
  8724. }
  8725. //血透客户
  8726. if config.IsOpen == 2 || config.IsOpen == 0 {
  8727. //药品管理信息
  8728. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8729. if drugStockConfig.IsOpen == 1 {
  8730. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8731. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8732. for _, item := range list {
  8733. for _, it := range adviceList {
  8734. if item.DrugId == it.DrugId {
  8735. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8736. }
  8737. }
  8738. }
  8739. for _, item := range list {
  8740. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8741. var sum_out_count int64
  8742. for _, itemThree := range item.ChildDoctorAdvice {
  8743. var prescribing_number int64
  8744. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8745. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8746. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8747. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8748. }
  8749. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8750. prescribing_number = parseIntPrescribingNumber
  8751. }
  8752. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8753. prescribing_number = parseIntPrescribingNumber
  8754. }
  8755. sum_out_count += prescribing_number
  8756. }
  8757. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8758. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8759. //库存不足
  8760. if sum_out_count > drugStockOut.FlushCount {
  8761. this.ServeSuccessJSON(map[string]interface{}{
  8762. "msg": "2",
  8763. "drug": medical,
  8764. "ids": ids,
  8765. })
  8766. return
  8767. }
  8768. }
  8769. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8770. //执行医嘱
  8771. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8772. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8773. for _, item := range advices {
  8774. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8775. redis := service.RedisClient()
  8776. //清空key 值
  8777. redis.Set(key, "", time.Second)
  8778. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8779. redis.Set(keyTwo, "", time.Second)
  8780. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8781. redis.Set(keyThree, "", time.Second)
  8782. recordDate := theTime.Format("2006-01-02")
  8783. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8784. redis.Set(keyFour, "", time.Second)
  8785. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8786. redis.Set(keyFive, "", time.Second)
  8787. defer redis.Close()
  8788. }
  8789. if errs == nil {
  8790. for _, item := range advices {
  8791. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8792. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8793. //查询是否出库按钮开启
  8794. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8795. if adviceSetting.IsAdviceOpen == 1 {
  8796. //查询是否出库按钮开启
  8797. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8798. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8799. if prescriptionConfig.IsOpen == 1 {
  8800. if medical.IsUse == 2 {
  8801. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8802. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8803. }
  8804. if pharmacyConfig.IsOpen != 1 {
  8805. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8806. }
  8807. //更新字典里面的库存
  8808. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8809. var sum_count int64
  8810. for _, its := range stockInfo {
  8811. if its.MaxUnit == medical.MaxUnit {
  8812. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8813. }
  8814. sum_count += its.StockMaxNumber + its.StockMinNumber
  8815. }
  8816. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8817. //剩余库存
  8818. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8819. }
  8820. }
  8821. } else {
  8822. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8823. if medical.IsUse == 2 {
  8824. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8825. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8826. }
  8827. if pharmacyConfig.IsOpen != 1 {
  8828. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8829. }
  8830. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8831. var sum_count int64
  8832. for _, its := range stockInfo {
  8833. if its.MaxUnit == medical.MaxUnit {
  8834. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8835. }
  8836. sum_count += its.StockMaxNumber + its.StockMinNumber
  8837. }
  8838. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8839. //剩余库存
  8840. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8841. }
  8842. }
  8843. }
  8844. }
  8845. this.ServeSuccessJSON(map[string]interface{}{
  8846. "msg": "1",
  8847. "ids": ids,
  8848. })
  8849. return
  8850. } else {
  8851. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8852. //执行医嘱
  8853. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8854. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8855. for _, item := range advices {
  8856. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8857. redis := service.RedisClient()
  8858. //清空key 值
  8859. redis.Set(key, "", time.Second)
  8860. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8861. redis.Set(keyTwo, "", time.Second)
  8862. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8863. redis.Set(keyThree, "", time.Second)
  8864. recordDate := theTime.Format("2006-01-02")
  8865. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8866. redis.Set(keyFour, "", time.Second)
  8867. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8868. redis.Set(keyFive, "", time.Second)
  8869. defer redis.Close()
  8870. }
  8871. this.ServeSuccessJSON(map[string]interface{}{
  8872. "msg": "1",
  8873. "ids": ids,
  8874. })
  8875. return
  8876. }
  8877. }
  8878. }
  8879. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8880. ids := this.GetString("ids")
  8881. idSplit := strings.Split(ids, ",")
  8882. orgId := this.GetMobileAdminUserInfo().Org.Id
  8883. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8884. if config.IsOpen == 1 {
  8885. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8886. this.ServeSuccessJSON(map[string]interface{}{
  8887. "msg": "1",
  8888. "ids": ids,
  8889. })
  8890. return
  8891. }
  8892. if config.IsOpen == 0 || config.IsOpen == 2 {
  8893. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8894. this.ServeSuccessJSON(map[string]interface{}{
  8895. "msg": "1",
  8896. "ids": ids,
  8897. })
  8898. return
  8899. }
  8900. }
  8901. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8902. ids := this.GetString("ids")
  8903. idSplit := strings.Split(ids, ",")
  8904. orgId := this.GetMobileAdminUserInfo().Org.Id
  8905. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8906. //his
  8907. if config.IsOpen == 1 {
  8908. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8909. theTime := time.Now()
  8910. advices := models.HisDoctorAdviceThirty{
  8911. CheckTime: theTime.Unix(),
  8912. Checker: checker,
  8913. UpdatedTime: time.Now().Unix(),
  8914. }
  8915. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8916. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8917. for _, item := range list {
  8918. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8919. redis := service.RedisClient()
  8920. //清空key 值
  8921. redis.Set(key, "", time.Second)
  8922. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8923. redis.Set(keyTwo, "", time.Second)
  8924. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8925. redis.Set(keyThree, "", time.Second)
  8926. recordDate := theTime.Format("2006-01-02")
  8927. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8928. redis.Set(keyFour, "", time.Second)
  8929. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8930. redis.Set(keyFive, "", time.Second)
  8931. defer redis.Close()
  8932. }
  8933. this.ServeSuccessJSON(map[string]interface{}{
  8934. "msg": "1",
  8935. "ids": ids,
  8936. })
  8937. return
  8938. }
  8939. //血透
  8940. if config.IsOpen == 0 || config.IsOpen == 2 {
  8941. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8942. theTime := time.Now()
  8943. advices := models.DoctorAdvice{
  8944. CheckTime: theTime.Unix(),
  8945. Checker: checker,
  8946. UpdatedTime: time.Now().Unix(),
  8947. }
  8948. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8949. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8950. for _, item := range list {
  8951. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8952. redis := service.RedisClient()
  8953. //清空key 值
  8954. redis.Set(key, "", time.Second)
  8955. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8956. redis.Set(keyTwo, "", time.Second)
  8957. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8958. redis.Set(keyThree, "", time.Second)
  8959. recordDate := theTime.Format("2006-01-02")
  8960. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8961. redis.Set(keyFour, "", time.Second)
  8962. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8963. redis.Set(keyFive, "", time.Second)
  8964. defer redis.Close()
  8965. }
  8966. this.ServeSuccessJSON(map[string]interface{}{
  8967. "msg": "1",
  8968. "ids": ids,
  8969. })
  8970. return
  8971. }
  8972. }
  8973. func (this *DialysisAPIController) CheckSchedule() {
  8974. patientID, _ := this.GetInt64("patient_id")
  8975. recordDateStr := this.GetString("record_date")
  8976. nurseID, _ := this.GetInt64("start_nurse")
  8977. schedual_type, _ := this.GetInt64("schedual_type")
  8978. bedID, _ := this.GetInt64("bed")
  8979. start_time := this.GetString("start_time")
  8980. fmt.Println("patientID", patientID)
  8981. fmt.Println("recordDateStr", recordDateStr)
  8982. fmt.Println("nurseID", nurseID)
  8983. fmt.Println("schedual_type------", schedual_type)
  8984. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8986. return
  8987. }
  8988. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8989. if parseStartDateErr != nil {
  8990. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8992. return
  8993. }
  8994. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8995. if parseErr != nil {
  8996. this.ErrorLog("时间解析失败:%v", parseErr)
  8997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8998. return
  8999. }
  9000. adminUserInfo := this.GetMobileAdminUserInfo()
  9001. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9002. if getPatientErr != nil {
  9003. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9004. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9005. return
  9006. } else if patient == nil {
  9007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9008. return
  9009. }
  9010. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9011. if getNurseErr != nil {
  9012. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9014. return
  9015. } else if nurse == nil {
  9016. this.ErrorLog("护士不存在")
  9017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9018. return
  9019. }
  9020. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9021. if getDeviceNumberErr != nil {
  9022. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9024. return
  9025. } else if deviceNumber == nil {
  9026. this.ErrorLog("床位号不存在")
  9027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9028. return
  9029. }
  9030. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9031. if getRecordErr != nil {
  9032. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9034. return
  9035. } else if dialysisRecord != nil {
  9036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9037. return
  9038. }
  9039. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9040. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9041. timeLayout := "2006-01-02 15:04:05"
  9042. loc, _ := time.LoadLocation("Local")
  9043. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9044. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9045. schedulestartTime := theStartTime.Unix()
  9046. scheduleendTime := theEndTime.Unix()
  9047. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9048. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9049. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9050. //查询该床位是否有人用了
  9051. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9052. if err == nil {
  9053. if schedule.ID == 0 {
  9054. this.ServeSuccessJSON(map[string]interface{}{
  9055. "status": 0,
  9056. "msg": "请求失败",
  9057. })
  9058. } else {
  9059. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9060. if order.ID > 0 { //该机位被其他人占用了
  9061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9062. return
  9063. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9064. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9065. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9066. this.ServeSuccessJSON(map[string]interface{}{
  9067. "status": 1,
  9068. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9069. })
  9070. return
  9071. } else {
  9072. this.ServeSuccessJSON(map[string]interface{}{
  9073. "status": 0,
  9074. "msg": "",
  9075. })
  9076. }
  9077. }
  9078. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9079. this.ServeSuccessJSON(map[string]interface{}{
  9080. "status": 2,
  9081. "msg": "当前机位已有患者在使用,请重新选择!",
  9082. })
  9083. }
  9084. }
  9085. } else {
  9086. this.ServeSuccessJSON(map[string]interface{}{
  9087. "status": 0,
  9088. "msg": "",
  9089. })
  9090. }
  9091. }
  9092. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9093. orgId := this.GetMobileAdminUserInfo().Org.Id
  9094. schedule_type, _ := this.GetInt64("schedule_type")
  9095. partion_type, _ := this.GetInt64("partion_type")
  9096. start_time := this.GetString("start_time")
  9097. timeLayout := "2006-01-02"
  9098. loc, _ := time.LoadLocation("Local")
  9099. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9100. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9101. _, config := service.FindXTHisRecordByOrgId(orgId)
  9102. appId := this.GetMobileAdminUserInfo().App.Id
  9103. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9104. if err == nil {
  9105. this.ServeSuccessJSON(map[string]interface{}{
  9106. "list": list,
  9107. "config": config,
  9108. "doctorList": doctorList,
  9109. })
  9110. return
  9111. } else {
  9112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9113. return
  9114. }
  9115. }
  9116. func (this *DialysisAPIController) SaveMobileInformation() {
  9117. patient_id, _ := this.GetInt64("patient_id")
  9118. record_date, _ := this.GetInt64("record_date")
  9119. startTime := this.GetString("start_time")
  9120. module, _ := this.GetInt64("module")
  9121. remark := this.GetString("remark")
  9122. timeLayout := "2006-01-02 15:04"
  9123. loc, _ := time.LoadLocation("Local")
  9124. if len(startTime) == 0 {
  9125. utils.ErrorLog("len(start_time) == 0")
  9126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9127. return
  9128. }
  9129. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9130. if err != nil {
  9131. utils.ErrorLog(err.Error())
  9132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9133. return
  9134. }
  9135. StartTime := theTime.Unix()
  9136. fmt.Println("startime-------------", StartTime)
  9137. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9138. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9139. information := models.XtDialysisInformation{
  9140. Module: module,
  9141. PatientId: patient_id,
  9142. RecordDate: record_date,
  9143. ApplicationDate: StartTime,
  9144. Creater: creater,
  9145. ApplicationStatus: 2,
  9146. Checker: 0,
  9147. CheckTime: 0,
  9148. Remark: remark,
  9149. UserOrgId: user_org_id,
  9150. Ctime: time.Now().Unix(),
  9151. Status: 1,
  9152. Mtime: 0,
  9153. }
  9154. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9155. if infor.ID == 0 {
  9156. service.SaveDialysisInformation(information)
  9157. }
  9158. if infor.ID > 0 {
  9159. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9160. }
  9161. this.ServeSuccessJSON(map[string]interface{}{
  9162. "information": information,
  9163. })
  9164. return
  9165. }
  9166. func (this *DialysisAPIController) GetMobileInformation() {
  9167. limit, _ := this.GetInt64("limit")
  9168. page, _ := this.GetInt64("page")
  9169. orgid := this.GetMobileAdminUserInfo().Org.Id
  9170. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9171. appid := this.GetMobileAdminUserInfo().App.Id
  9172. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9173. patients, _ := service.GetAllpatientThirty(orgid)
  9174. this.ServeSuccessJSON(map[string]interface{}{
  9175. "information": information,
  9176. "total": total,
  9177. "doclist": doclist,
  9178. "patients": patients,
  9179. })
  9180. return
  9181. }
  9182. func (this *DialysisAPIController) GetMobileInformationOne() {
  9183. limit, _ := this.GetInt64("limit")
  9184. page, _ := this.GetInt64("page")
  9185. orgid := this.GetMobileAdminUserInfo().Org.Id
  9186. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9187. appid := this.GetMobileAdminUserInfo().App.Id
  9188. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9189. patients, _ := service.GetAllpatientThirty(orgid)
  9190. this.ServeSuccessJSON(map[string]interface{}{
  9191. "information": information,
  9192. "total": total,
  9193. "doclist": doclist,
  9194. "patients": patients,
  9195. })
  9196. return
  9197. }
  9198. func (this *DialysisAPIController) CheckMobileInformation() {
  9199. id, _ := this.GetInt64("id")
  9200. application_status, _ := this.GetInt64("application_status")
  9201. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9202. checktime := time.Now().Unix()
  9203. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9204. if err == nil {
  9205. this.ServeSuccessJSON(map[string]interface{}{
  9206. "msg": "ok",
  9207. })
  9208. return
  9209. }
  9210. }
  9211. func (c *DialysisAPIController) GetControlMonitorList() {
  9212. partition, _ := c.GetInt64("partition")
  9213. monitorDate := c.GetString("date")
  9214. patient_id, _ := c.GetInt64("patient_id")
  9215. pat_type, _ := c.GetInt64("pat_type")
  9216. timeLayout := "2006-01-02"
  9217. loc, _ := time.LoadLocation("Local")
  9218. var theStartTime int64
  9219. if len(monitorDate) > 0 {
  9220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9221. if err != nil {
  9222. theStartTime = 0
  9223. }
  9224. theStartTime = theTime.Unix()
  9225. }
  9226. adminInfo := c.GetMobileAdminUserInfo()
  9227. orgID := adminInfo.Org.Id
  9228. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9229. if err != nil {
  9230. c.ErrorLog("获取排班信息失败:%v", err)
  9231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9232. } else {
  9233. if len(monitor) > 0 {
  9234. //获取所有床位
  9235. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9236. //获取所有分区
  9237. zoneList, _ := service.GetAllZoneByList(orgID)
  9238. //获取透析处方
  9239. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9240. //获取透前评估
  9241. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9242. //获取上机
  9243. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9244. //获取透后
  9245. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9246. //获取透后监测
  9247. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9248. //获取所有的患者
  9249. patients, _ := service.GetAllPatientListByListOne(orgID)
  9250. //获取所有透析模式
  9251. treatments, _ := service.GetAllTreatModeByList(orgID)
  9252. //获取所有医嘱
  9253. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9254. //获取双人核对
  9255. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9256. //治疗小结
  9257. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9258. //待消毒
  9259. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9260. for key, item := range monitor {
  9261. // 获取床位信息
  9262. for _, it := range numberList {
  9263. if item.BedId == it.ID {
  9264. monitor[key].DeviceNumber = it
  9265. break
  9266. }
  9267. }
  9268. //获取分区信息
  9269. for _, it := range zoneList {
  9270. if item.PartitionId == it.ID {
  9271. monitor[key].DeviceZone = it
  9272. }
  9273. }
  9274. for _, prescription := range prescriptions {
  9275. if item.PatientId == prescription.PatientId {
  9276. monitor[key].Prescription = prescription
  9277. break
  9278. }
  9279. }
  9280. for _, it := range checkList {
  9281. if item.PatientId == it.PatientId {
  9282. monitor[key].DoubleCheck = it
  9283. break
  9284. }
  9285. }
  9286. for _, it := range summaryList {
  9287. if item.PatientId == it.PatientId {
  9288. monitor[key].TreatmentSummaryForList = it
  9289. break
  9290. }
  9291. }
  9292. // 透前评估
  9293. for _, assessmentBefore := range assessmentBefores {
  9294. if item.PatientId == assessmentBefore.PatientId {
  9295. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9296. break
  9297. }
  9298. }
  9299. // 透析上下机
  9300. for _, dialysisOrder := range dialysisOrders {
  9301. if item.PatientId == dialysisOrder.PatientId {
  9302. monitor[key].DialysisOrder = dialysisOrder
  9303. break
  9304. }
  9305. }
  9306. // 治疗小节
  9307. for _, afterDislysis := range AssessmentAfterDislysis {
  9308. if item.PatientId == afterDislysis.PatientId {
  9309. monitor[key].AssessmentAfterDislysis = afterDislysis
  9310. break
  9311. }
  9312. }
  9313. for _, it := range monitorlist {
  9314. if item.PatientId == it.PatientId {
  9315. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9316. }
  9317. }
  9318. for _, it := range adviceList {
  9319. if item.PatientId == it.PatientId {
  9320. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9321. }
  9322. }
  9323. for _, patient := range patients {
  9324. if item.PatientId == patient.ID {
  9325. monitor[key].MonitorPatients = patient
  9326. break
  9327. }
  9328. }
  9329. for _, treatment := range treatments {
  9330. if item.ModeId == treatment.ID {
  9331. monitor[key].TreatmentMode = treatment
  9332. break
  9333. }
  9334. }
  9335. for _, infor := range informationList {
  9336. if item.PatientId == infor.PatientId {
  9337. monitor[key].NewDeviceInformation = infor
  9338. break
  9339. }
  9340. }
  9341. }
  9342. }
  9343. }
  9344. patients, err := service.GetAllpatientFourty(orgID)
  9345. var mds []*models.NewMonitorDialysisScheduleList
  9346. if pat_type == 0 {
  9347. for _, item := range monitor {
  9348. mds = append(mds, item)
  9349. }
  9350. }
  9351. //待医嘱核对
  9352. if pat_type == 1 {
  9353. for _, item := range monitor {
  9354. if len(item.AdviceList) > 0 {
  9355. mds = append(mds, item)
  9356. }
  9357. }
  9358. }
  9359. //待开小结
  9360. if pat_type == 2 {
  9361. for _, item := range monitor {
  9362. if item.TreatmentSummaryForList == nil {
  9363. mds = append(mds, item)
  9364. }
  9365. }
  9366. }
  9367. //待下机
  9368. if pat_type == 3 {
  9369. for _, item := range monitor {
  9370. if item.DialysisOrder != nil {
  9371. if item.DialysisOrder.ID > 0 {
  9372. mds = append(mds, item)
  9373. }
  9374. }
  9375. }
  9376. }
  9377. //待消毒
  9378. if pat_type == 4 {
  9379. for _, item := range monitor {
  9380. if item.NewDeviceInformation == nil {
  9381. mds = append(mds, item)
  9382. }
  9383. }
  9384. }
  9385. //待双人核对
  9386. if pat_type == 5 {
  9387. for _, item := range monitor {
  9388. if item.DoubleCheck == nil {
  9389. mds = append(mds, item)
  9390. }
  9391. }
  9392. }
  9393. //医嘱未执行
  9394. if pat_type == 6 {
  9395. for _, item := range monitor {
  9396. if len(item.AdviceList) > 0 {
  9397. mds = append(mds, item)
  9398. }
  9399. }
  9400. }
  9401. //患者未签名
  9402. if pat_type == 7 {
  9403. for _, item := range monitor {
  9404. if item.DialysisOrder != nil {
  9405. if item.DialysisOrder.ID > 0 {
  9406. mds = append(mds, item)
  9407. }
  9408. }
  9409. }
  9410. }
  9411. //目标超滤于实际超滤不同
  9412. if pat_type == 8 {
  9413. for _, item := range monitor {
  9414. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9415. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9416. mds = append(mds, item)
  9417. }
  9418. }
  9419. }
  9420. }
  9421. //血压少于5次
  9422. if pat_type == 9 {
  9423. for _, item := range monitor {
  9424. if len(item.MonitoringRecord) < 5 {
  9425. mds = append(mds, item)
  9426. }
  9427. }
  9428. }
  9429. if pat_type == 10 {
  9430. for _, item := range monitor {
  9431. if len(item.MonitoringRecord) == 0 {
  9432. mds = append(mds, item)
  9433. }
  9434. }
  9435. }
  9436. if pat_type == 11 {
  9437. for _, item := range monitor {
  9438. if len(item.MonitoringRecord) > 0 {
  9439. mds = append(mds, item)
  9440. }
  9441. }
  9442. }
  9443. if pat_type == 12 {
  9444. for _, item := range monitor {
  9445. if len(item.MonitoringRecord) > 0 {
  9446. mds = append(mds, item)
  9447. }
  9448. }
  9449. }
  9450. if err == nil {
  9451. c.ServeSuccessJSON(map[string]interface{}{
  9452. "monitor": mds,
  9453. "patients": patients,
  9454. })
  9455. } else {
  9456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9457. }
  9458. }
  9459. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9460. admin_user_id, _ := c.GetInt64("admin_user_id")
  9461. timeStr := time.Now().Format("2006-01-02")
  9462. timeLayout := "2006-01-02 15:04:05"
  9463. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9464. timenow := timeStringToTime.Unix()
  9465. orgId := c.GetMobileAdminUserInfo().Org.Id
  9466. //查询当前护士的患者
  9467. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9468. var patientIds []int64
  9469. for _, item := range orderList {
  9470. patientIds = append(patientIds, item.PatientId)
  9471. }
  9472. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9473. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9474. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9475. //药品管理信息
  9476. _, drugStockConfig := service.FindHisConfig(orgId)
  9477. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9478. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9479. c.ServeSuccessJSON(map[string]interface{}{
  9480. "adviceList": adviceList,
  9481. "hisAdviceList": hisAdviceList,
  9482. "projectList": projectList,
  9483. "drugStockConfig": drugStockConfig,
  9484. "patientList": patientList,
  9485. "projectConfig": projectConfig,
  9486. })
  9487. }
  9488. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9489. patient_id, _ := c.GetInt64("patient_id")
  9490. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "recrods": recrods,
  9493. })
  9494. }
  9495. func (c *DialysisAPIController) ExMobileChangeSch() {
  9496. id_one, _ := c.GetInt64("id_one")
  9497. id_two, _ := c.GetInt64("id_two")
  9498. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9499. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9500. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9501. //if order2.ID > 0 {
  9502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9503. // return
  9504. //}
  9505. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9506. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9507. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9508. if count > 0 {
  9509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9510. return
  9511. }
  9512. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9513. if count1 > 0 {
  9514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9515. return
  9516. }
  9517. }
  9518. err := service.UpdateScheduleThree(sch, sch_two)
  9519. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9520. if order.ID > 0 {
  9521. //查询该患者的排班机位
  9522. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9523. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9524. redis := service.RedisClient()
  9525. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9526. redis.Set(key, "", time.Second)
  9527. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9528. //清空key 值
  9529. redis.Set(keyOne, "", time.Second)
  9530. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9531. //return
  9532. }
  9533. if err == nil {
  9534. //去除当天患者排班中重复数据,保留最后一条数据
  9535. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9536. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9537. c.ServeSuccessJSON(map[string]interface{}{
  9538. "msg": "交换成功",
  9539. })
  9540. } else {
  9541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9542. return
  9543. }
  9544. }
  9545. func (c *DialysisAPIController) MobileCoverSch() {
  9546. id_one, _ := c.GetInt64("id_one")
  9547. id_two, _ := c.GetInt64("id_two")
  9548. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9549. //针对凤凰医院
  9550. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9551. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9552. if len(advice) > 0 {
  9553. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9554. }
  9555. }
  9556. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9557. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9558. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9559. if len(hisAdvice) > 0 {
  9560. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9561. }
  9562. if len(project) > 0 {
  9563. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9564. }
  9565. }
  9566. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9567. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9568. if order.ID > 0 {
  9569. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9570. redis := service.RedisClient()
  9571. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9572. redis.Set(key, "", time.Second)
  9573. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9574. //清空key 值
  9575. redis.Set(keyOne, "", time.Second)
  9576. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9577. //return
  9578. }
  9579. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9580. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9581. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9582. if count > 0 {
  9583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9584. return
  9585. }
  9586. }
  9587. var new_sch models.Schedule
  9588. new_sch = sch
  9589. new_sch.BedId = sch_two.BedId
  9590. new_sch.ScheduleDate = sch_two.ScheduleDate
  9591. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9592. new_sch.PartitionId = sch_two.PartitionId
  9593. new_sch.ScheduleType = sch_two.ScheduleType
  9594. new_sch.ID = 0
  9595. //删除原来的排班
  9596. err := service.SaveSchTwo(sch, sch_two)
  9597. //生成新的排班
  9598. if err == nil {
  9599. err2 := service.SaveSch(&new_sch)
  9600. if err2 == nil {
  9601. //去除当天患者排班中重复数据,保留最后一条数据
  9602. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9603. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9604. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9605. c.ServeSuccessJSON(map[string]interface{}{
  9606. "msg": "覆盖成功",
  9607. "new_sch": new_sch,
  9608. })
  9609. } else {
  9610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9611. return
  9612. }
  9613. } else {
  9614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9615. return
  9616. }
  9617. }
  9618. func (c *DialysisAPIController) BatchCheckAdvice() {
  9619. patient_id, _ := c.GetInt64("patient_id")
  9620. advice_date, _ := c.GetInt64("advice_date")
  9621. org_id := c.GetMobileAdminUserInfo().Org.Id
  9622. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9623. //查询是his系统还是血透系统
  9624. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9625. //his客户
  9626. if configs.IsOpen == 1 {
  9627. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9628. for _, item := range adviceList {
  9629. service.BatchCheckHisAdvice(item.ID, creater)
  9630. }
  9631. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9632. for _, item := range projectList {
  9633. service.BatchCheckProject(item.ID, creater)
  9634. }
  9635. c.ServeSuccessJSON(map[string]interface{}{
  9636. "adviceList": adviceList,
  9637. "projectList": projectList,
  9638. })
  9639. }
  9640. if configs.IsOpen != 1 {
  9641. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9642. for _, item := range adviceList {
  9643. service.BatchAdviceList(item.ID, creater)
  9644. }
  9645. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9646. for _, item := range projectList {
  9647. service.BatchCheckProject(item.ID, creater)
  9648. }
  9649. c.ServeSuccessJSON(map[string]interface{}{
  9650. "adviceList": adviceList,
  9651. "projectList": projectList,
  9652. })
  9653. }
  9654. return
  9655. }
  9656. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9657. org_id := c.GetMobileAdminUserInfo().Org.Id
  9658. drugList, _ := service.GetAllDrugList(org_id)
  9659. c.ServeSuccessJSON(map[string]interface{}{
  9660. "drugList": drugList,
  9661. })
  9662. }
  9663. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9664. org_id := c.GetMobileAdminUserInfo().Org.Id
  9665. dataBody := make(map[string]interface{}, 0)
  9666. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9667. if err != nil {
  9668. utils.ErrorLog(err.Error())
  9669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9670. return
  9671. }
  9672. timeLayout := "2006-01-02"
  9673. loc, _ := time.LoadLocation("Local")
  9674. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9675. utils.ErrorLog("advice_type")
  9676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9677. return
  9678. }
  9679. adviceType := int64(dataBody["advice_type"].(float64))
  9680. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9681. utils.ErrorLog("start_time")
  9682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9683. return
  9684. }
  9685. startTime2, _ := dataBody["start_time"].(string)
  9686. time_arr := strings.Split(startTime2, " ")
  9687. if len(time_arr) > 0 {
  9688. startTime2 = time_arr[0]
  9689. }
  9690. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9691. utils.ErrorLog("advice_date")
  9692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9693. return
  9694. }
  9695. advice_date, _ := dataBody["advice_date"].(string)
  9696. var advicedateunix int64
  9697. if len(advice_date) > 0 {
  9698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9699. if err != nil {
  9700. fmt.Println(err)
  9701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9702. return
  9703. }
  9704. advicedateunix = theTime.Unix()
  9705. }
  9706. adviceDate := startTime2
  9707. if len(adviceDate) == 0 {
  9708. utils.ErrorLog("len(adviceDate) == 0")
  9709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9710. return
  9711. }
  9712. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9713. if err != nil {
  9714. utils.ErrorLog(err.Error())
  9715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9716. return
  9717. }
  9718. AdviceDate := advicedateunix
  9719. RecordDate := advicedateunix
  9720. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9721. utils.ErrorLog("start_time")
  9722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9723. return
  9724. }
  9725. startTime, _ := dataBody["start_time"].(string)
  9726. if len(startTime) == 0 {
  9727. utils.ErrorLog("len(start_time) == 0")
  9728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9729. return
  9730. }
  9731. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9732. if err != nil {
  9733. utils.ErrorLog(err.Error())
  9734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9735. return
  9736. }
  9737. StartTime := theTime.Unix()
  9738. advice_name, _ := dataBody["advice_name"].(string)
  9739. advice_desc, _ := dataBody["advice_desc"].(string)
  9740. delivery_way, _ := dataBody["delivery_way"].(string)
  9741. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9742. frequency_type := int64(dataBody["frequency_type"].(float64))
  9743. frequency_week, _ := dataBody["frequency_week"].(string)
  9744. prescribing_number := dataBody["prescribing_number"].(float64)
  9745. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9746. remark := dataBody["remark"].(string)
  9747. single_dose := dataBody["single_dose"].(float64)
  9748. single_dose_unit := dataBody["single_dose_unit"].(string)
  9749. patient_id := int64(dataBody["patient_id"].(float64))
  9750. day_count := int64(dataBody["day_count"].(float64))
  9751. groupNo := int64(dataBody["group_no"].(float64))
  9752. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9753. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9754. if groupNo <= 0 {
  9755. group := service.GetMaxAdviceGroupID(org_id)
  9756. groupNo = group + 1
  9757. }
  9758. var template_id = ""
  9759. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9760. template_id = "M" + adviceLastId
  9761. advice := models.DoctorAdvice{
  9762. UserOrgId: org_id,
  9763. PatientId: patient_id,
  9764. AdviceType: adviceType,
  9765. AdviceDate: AdviceDate,
  9766. StartTime: StartTime,
  9767. AdviceName: advice_name,
  9768. AdviceDesc: advice_desc,
  9769. ReminderDate: 0,
  9770. SingleDose: single_dose,
  9771. SingleDoseUnit: single_dose_unit,
  9772. DrugSpec: 0,
  9773. DrugSpecUnit: "",
  9774. PrescribingNumber: prescribing_number,
  9775. PrescribingNumberUnit: prescribing_number_unit,
  9776. DeliveryWay: delivery_way,
  9777. ExecutionFrequency: execution_frequency,
  9778. AdviceDoctor: advice_doctor,
  9779. Status: 1,
  9780. CreatedTime: time.Now().Unix(),
  9781. UpdatedTime: 0,
  9782. AdviceAffirm: "",
  9783. Remark: remark,
  9784. StopTime: 0,
  9785. StopReason: "",
  9786. StopDoctor: 0,
  9787. StopState: 0,
  9788. ParentId: 0,
  9789. ExecutionTime: 0,
  9790. ExecutionStaff: 0,
  9791. ExecutionState: 0,
  9792. Checker: 0,
  9793. RecordDate: RecordDate,
  9794. DialysisOrderId: 0,
  9795. CheckTime: 0,
  9796. CheckState: 0,
  9797. AdviceId: 0,
  9798. RemindType: 0,
  9799. FrequencyType: frequency_type,
  9800. DayCount: day_count,
  9801. WeekDay: frequency_week,
  9802. ChildDoctorAdvice: nil,
  9803. TemplateId: template_id,
  9804. Modifier: 0,
  9805. IsCheck: 0,
  9806. Way: 0,
  9807. DrugId: 0,
  9808. DrugNameId: 0,
  9809. IsMedicine: 0,
  9810. PushStartTime: 0,
  9811. IsSettle: 0,
  9812. IsPrescription: 0,
  9813. GroupNo: groupNo,
  9814. }
  9815. service.CreateMobileAdivce(advice)
  9816. c.ServeSuccessJSON(map[string]interface{}{
  9817. "msg": "保存成功!",
  9818. })
  9819. }
  9820. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9821. patient_id, _ := c.GetInt64("patient_id")
  9822. org_id := c.GetMobileAdminUserInfo().Org.Id
  9823. app_id := c.GetMobileAdminUserInfo().App.Id
  9824. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9825. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9826. c.ServeSuccessJSON(map[string]interface{}{
  9827. "adviceList": adviceList,
  9828. "adminRoles": adminRoles,
  9829. })
  9830. }
  9831. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9832. org_id := c.GetMobileAdminUserInfo().Org.Id
  9833. dataBody := make(map[string]interface{}, 0)
  9834. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9835. if err != nil {
  9836. utils.ErrorLog(err.Error())
  9837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9838. return
  9839. }
  9840. timeLayout := "2006-01-02"
  9841. loc, _ := time.LoadLocation("Local")
  9842. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9843. utils.ErrorLog("start_time")
  9844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9845. return
  9846. }
  9847. startTime2, _ := dataBody["start_time"].(string)
  9848. time_arr := strings.Split(startTime2, " ")
  9849. if len(time_arr) > 0 {
  9850. startTime2 = time_arr[0]
  9851. }
  9852. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9853. utils.ErrorLog("advice_date")
  9854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9855. return
  9856. }
  9857. advice_date, _ := dataBody["advice_date"].(string)
  9858. var advicedateunix int64
  9859. if len(advice_date) > 0 {
  9860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9861. if err != nil {
  9862. fmt.Println(err)
  9863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9864. return
  9865. }
  9866. advicedateunix = theTime.Unix()
  9867. }
  9868. adviceDate := startTime2
  9869. if len(adviceDate) == 0 {
  9870. utils.ErrorLog("len(adviceDate) == 0")
  9871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9872. return
  9873. }
  9874. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9875. if err != nil {
  9876. utils.ErrorLog(err.Error())
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9878. return
  9879. }
  9880. AdviceDate := advicedateunix
  9881. RecordDate := advicedateunix
  9882. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9883. utils.ErrorLog("start_time")
  9884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9885. return
  9886. }
  9887. startTime, _ := dataBody["start_time"].(string)
  9888. if len(startTime) == 0 {
  9889. utils.ErrorLog("len(start_time) == 0")
  9890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9891. return
  9892. }
  9893. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9894. if err != nil {
  9895. utils.ErrorLog(err.Error())
  9896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9897. return
  9898. }
  9899. StartTime := theTime.Unix()
  9900. advice_name, _ := dataBody["advice_name"].(string)
  9901. advice_desc, _ := dataBody["advice_desc"].(string)
  9902. delivery_way, _ := dataBody["delivery_way"].(string)
  9903. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9904. prescribing_number := dataBody["prescribing_number"].(float64)
  9905. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9906. remark := dataBody["remark"].(string)
  9907. single_dose := dataBody["single_dose"].(float64)
  9908. single_dose_unit := dataBody["single_dose_unit"].(string)
  9909. patient_id := int64(dataBody["patient_id"].(float64))
  9910. groupNo := int64(dataBody["group_no"].(float64))
  9911. parent_id := int64(dataBody["parent_id"].(float64))
  9912. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9913. advice := models.XtDoctorAdviceOne{
  9914. UserOrgId: org_id,
  9915. PatientId: patient_id,
  9916. AdviceType: 1,
  9917. AdviceDate: AdviceDate,
  9918. StartTime: StartTime,
  9919. AdviceName: advice_name,
  9920. AdviceDesc: advice_desc,
  9921. ReminderDate: 0,
  9922. SingleDose: single_dose,
  9923. SingleDoseUnit: single_dose_unit,
  9924. PrescribingNumber: prescribing_number,
  9925. PrescribingNumberUnit: prescribing_number_unit,
  9926. DeliveryWay: delivery_way,
  9927. ExecutionFrequency: execution_frequency,
  9928. AdviceDoctor: advice_doctor,
  9929. Status: 1,
  9930. CreatedTime: time.Now().Unix(),
  9931. UpdatedTime: time.Now().Unix(),
  9932. AdviceAffirm: "",
  9933. Remark: remark,
  9934. StopTime: 0,
  9935. StopReason: "",
  9936. StopDoctor: 0,
  9937. StopState: 0,
  9938. ParentId: parent_id,
  9939. ExecutionTime: 0,
  9940. ExecutionStaff: 0,
  9941. ExecutionState: 0,
  9942. Checker: 0,
  9943. RecordDate: RecordDate,
  9944. DialysisOrderId: 0,
  9945. CheckTime: 0,
  9946. CheckState: 0,
  9947. DrugSpec: 0,
  9948. DrugSpecUnit: "",
  9949. Groupno: groupNo,
  9950. RemindType: 0,
  9951. FrequencyType: 0,
  9952. DayCount: 0,
  9953. WeekDay: "",
  9954. TemplateId: "",
  9955. Modifier: 0,
  9956. }
  9957. service.CreateMobileAdivceOne(advice)
  9958. c.ServeSuccessJSON(map[string]interface{}{
  9959. "msg": "保存成功!",
  9960. })
  9961. }
  9962. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9963. id, _ := c.GetInt64("id")
  9964. service.DeleteSelfAdviceSubAdvice(id)
  9965. c.ServeSuccessJSON(map[string]interface{}{
  9966. "msg": "保存成功!",
  9967. })
  9968. }
  9969. func (c *DialysisAPIController) GetEditAdviceAction() {
  9970. id, _ := c.GetInt64("id")
  9971. org_id := c.GetMobileAdminUserInfo().Org.Id
  9972. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9973. drugList, _ := service.GetAllDrugList(org_id)
  9974. c.ServeSuccessJSON(map[string]interface{}{
  9975. "advice": advice,
  9976. "drugList": drugList,
  9977. })
  9978. }
  9979. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9980. dataBody := make(map[string]interface{}, 0)
  9981. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9982. if err != nil {
  9983. utils.ErrorLog(err.Error())
  9984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9985. return
  9986. }
  9987. timeLayout := "2006-01-02"
  9988. loc, _ := time.LoadLocation("Local")
  9989. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9990. utils.ErrorLog("start_time")
  9991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9992. return
  9993. }
  9994. startTime2, _ := dataBody["start_time"].(string)
  9995. time_arr := strings.Split(startTime2, " ")
  9996. if len(time_arr) > 0 {
  9997. startTime2 = time_arr[0]
  9998. }
  9999. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10000. utils.ErrorLog("advice_date")
  10001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10002. return
  10003. }
  10004. advice_date, _ := dataBody["advice_date"].(string)
  10005. var advicedateunix int64
  10006. if len(advice_date) > 0 {
  10007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10008. if err != nil {
  10009. fmt.Println(err)
  10010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10011. return
  10012. }
  10013. advicedateunix = theTime.Unix()
  10014. }
  10015. adviceDate := startTime2
  10016. if len(adviceDate) == 0 {
  10017. utils.ErrorLog("len(adviceDate) == 0")
  10018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10019. return
  10020. }
  10021. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10022. if err != nil {
  10023. utils.ErrorLog(err.Error())
  10024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10025. return
  10026. }
  10027. AdviceDate := advicedateunix
  10028. RecordDate := advicedateunix
  10029. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10030. utils.ErrorLog("start_time")
  10031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10032. return
  10033. }
  10034. startTime, _ := dataBody["start_time"].(string)
  10035. if len(startTime) == 0 {
  10036. utils.ErrorLog("len(start_time) == 0")
  10037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10038. return
  10039. }
  10040. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10041. if err != nil {
  10042. utils.ErrorLog(err.Error())
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10044. return
  10045. }
  10046. StartTime := theTime.Unix()
  10047. advice_name, _ := dataBody["advice_name"].(string)
  10048. advice_desc, _ := dataBody["advice_desc"].(string)
  10049. delivery_way, _ := dataBody["delivery_way"].(string)
  10050. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10051. prescribing_number := dataBody["prescribing_number"].(float64)
  10052. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10053. remark := dataBody["remark"].(string)
  10054. single_dose := dataBody["single_dose"].(float64)
  10055. single_dose_unit := dataBody["single_dose_unit"].(string)
  10056. id := int64(dataBody["id"].(float64))
  10057. frequency_type := int64(dataBody["frequency_type"].(float64))
  10058. frequency_week, _ := dataBody["frequency_week"].(string)
  10059. day_count := int64(dataBody["day_count"].(float64))
  10060. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10061. advice := models.XtDoctorAdviceOne{
  10062. AdviceDate: AdviceDate,
  10063. StartTime: StartTime,
  10064. AdviceName: advice_name,
  10065. AdviceDesc: advice_desc,
  10066. SingleDose: single_dose,
  10067. SingleDoseUnit: single_dose_unit,
  10068. PrescribingNumber: prescribing_number,
  10069. PrescribingNumberUnit: prescribing_number_unit,
  10070. DeliveryWay: delivery_way,
  10071. ExecutionFrequency: execution_frequency,
  10072. AdviceDoctor: advice_doctor,
  10073. Remark: remark,
  10074. RecordDate: RecordDate,
  10075. FrequencyType: frequency_type,
  10076. DayCount: day_count,
  10077. WeekDay: frequency_week,
  10078. }
  10079. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10080. c.ServeSuccessJSON(map[string]interface{}{
  10081. "advice": advice,
  10082. })
  10083. }
  10084. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10085. dataBody := make(map[string]interface{}, 0)
  10086. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10087. if err != nil {
  10088. utils.ErrorLog(err.Error())
  10089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10090. return
  10091. }
  10092. timeLayout := "2006-01-02"
  10093. loc, _ := time.LoadLocation("Local")
  10094. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10095. utils.ErrorLog("start_time")
  10096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10097. return
  10098. }
  10099. startTime2, _ := dataBody["start_time"].(string)
  10100. time_arr := strings.Split(startTime2, " ")
  10101. if len(time_arr) > 0 {
  10102. startTime2 = time_arr[0]
  10103. }
  10104. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10105. utils.ErrorLog("advice_date")
  10106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10107. return
  10108. }
  10109. advice_date, _ := dataBody["advice_date"].(string)
  10110. var advicedateunix int64
  10111. if len(advice_date) > 0 {
  10112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10113. if err != nil {
  10114. fmt.Println(err)
  10115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10116. return
  10117. }
  10118. advicedateunix = theTime.Unix()
  10119. }
  10120. adviceDate := startTime2
  10121. if len(adviceDate) == 0 {
  10122. utils.ErrorLog("len(adviceDate) == 0")
  10123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10124. return
  10125. }
  10126. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10127. if err != nil {
  10128. utils.ErrorLog(err.Error())
  10129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10130. return
  10131. }
  10132. AdviceDate := advicedateunix
  10133. RecordDate := advicedateunix
  10134. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10135. utils.ErrorLog("start_time")
  10136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10137. return
  10138. }
  10139. startTime, _ := dataBody["start_time"].(string)
  10140. if len(startTime) == 0 {
  10141. utils.ErrorLog("len(start_time) == 0")
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10146. if err != nil {
  10147. utils.ErrorLog(err.Error())
  10148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10149. return
  10150. }
  10151. StartTime := theTime.Unix()
  10152. advice_name, _ := dataBody["advice_name"].(string)
  10153. advice_desc, _ := dataBody["advice_desc"].(string)
  10154. delivery_way, _ := dataBody["delivery_way"].(string)
  10155. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10156. prescribing_number := dataBody["prescribing_number"].(float64)
  10157. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10158. remark := dataBody["remark"].(string)
  10159. single_dose := dataBody["single_dose"].(float64)
  10160. single_dose_unit := dataBody["single_dose_unit"].(string)
  10161. id := int64(dataBody["id"].(float64))
  10162. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10163. advice := models.XtDoctorAdviceOne{
  10164. AdviceDate: AdviceDate,
  10165. StartTime: StartTime,
  10166. AdviceName: advice_name,
  10167. AdviceDesc: advice_desc,
  10168. SingleDose: single_dose,
  10169. SingleDoseUnit: single_dose_unit,
  10170. PrescribingNumber: prescribing_number,
  10171. PrescribingNumberUnit: prescribing_number_unit,
  10172. DeliveryWay: delivery_way,
  10173. ExecutionFrequency: execution_frequency,
  10174. AdviceDoctor: advice_doctor,
  10175. Remark: remark,
  10176. RecordDate: RecordDate,
  10177. }
  10178. service.UpdateMobileDoctorAdviceById(id, advice)
  10179. c.ServeSuccessJSON(map[string]interface{}{
  10180. "advice": advice,
  10181. })
  10182. }
  10183. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10184. dataBody := make(map[string]interface{}, 0)
  10185. timeLayout := "2006-01-02"
  10186. loc, _ := time.LoadLocation("Local")
  10187. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10188. if err != nil {
  10189. utils.ErrorLog(err.Error())
  10190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10191. return
  10192. }
  10193. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10194. utils.ErrorLog("start_time")
  10195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10196. return
  10197. }
  10198. startTime2, _ := dataBody["start_time"].(string)
  10199. time_arr := strings.Split(startTime2, " ")
  10200. if len(time_arr) > 0 {
  10201. startTime2 = time_arr[0]
  10202. }
  10203. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10204. utils.ErrorLog("advice_date")
  10205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10206. return
  10207. }
  10208. advice_date, _ := dataBody["advice_date"].(string)
  10209. var advicedateunix int64
  10210. if len(advice_date) > 0 {
  10211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10212. if err != nil {
  10213. fmt.Println(err)
  10214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10215. return
  10216. }
  10217. advicedateunix = theTime.Unix()
  10218. }
  10219. adviceDate := startTime2
  10220. if len(adviceDate) == 0 {
  10221. utils.ErrorLog("len(adviceDate) == 0")
  10222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10223. return
  10224. }
  10225. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10226. if err != nil {
  10227. utils.ErrorLog(err.Error())
  10228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10229. return
  10230. }
  10231. RecordDate := advicedateunix
  10232. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10233. utils.ErrorLog("start_time")
  10234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10235. return
  10236. }
  10237. startTime, _ := dataBody["start_time"].(string)
  10238. if len(startTime) == 0 {
  10239. utils.ErrorLog("len(start_time) == 0")
  10240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10241. return
  10242. }
  10243. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10244. if err != nil {
  10245. utils.ErrorLog(err.Error())
  10246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10247. return
  10248. }
  10249. StartTime := theTime.Unix()
  10250. patient_id := int64(dataBody["patient_id"].(float64))
  10251. group_no := int64(dataBody["group_no"].(float64))
  10252. org_id := c.GetMobileAdminUserInfo().Org.Id
  10253. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10254. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10255. utils.ErrorLog("advices")
  10256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10257. return
  10258. }
  10259. adviceNames := dataBody["advices"].([]interface{})
  10260. var advices []*models.GroupAdvice
  10261. for _, adviceNameMap := range adviceNames {
  10262. var advice models.GroupAdvice
  10263. adviceNameM := adviceNameMap.(map[string]interface{})
  10264. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10265. utils.ErrorLog("advice_name")
  10266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10267. return
  10268. }
  10269. adviceName, _ := adviceNameM["advice_name"].(string)
  10270. if len(adviceName) == 0 {
  10271. utils.ErrorLog("len(advice_name) == 0")
  10272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10273. return
  10274. }
  10275. advice.AdviceName = adviceName
  10276. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10277. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10278. advice.DrugSpec = drugSpec
  10279. }
  10280. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10281. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10282. advice.AdviceDesc = adviceDesc
  10283. }
  10284. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10285. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10286. advice.DrugSpecUnit = drugSpecUnit
  10287. }
  10288. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10289. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10290. advice.SingleDose = singleDose
  10291. }
  10292. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10293. singleDose := adviceNameM["single_dose"].(float64)
  10294. advice.SingleDose = singleDose
  10295. }
  10296. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10297. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10298. advice.SingleDoseUnit = singleDoseUnit
  10299. }
  10300. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10301. tmp := adviceNameM["single_dose_unit"].(float64)
  10302. singleDoseUnit := service.TypeConversion(tmp)
  10303. advice.SingleDoseUnit = singleDoseUnit
  10304. }
  10305. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10306. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10307. advice.PrescribingNumber = prescribingNumber
  10308. }
  10309. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10310. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10311. advice.PrescribingNumber = prescribingNumber
  10312. }
  10313. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10314. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10315. advice.PrescribingNumberUnit = prescribingNumberUnit
  10316. }
  10317. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10318. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10319. advice.DeliveryWay = deliveryWay
  10320. }
  10321. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10322. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10323. advice.ExecutionFrequency = executionFrequency
  10324. }
  10325. remark, _ := adviceNameM["remark"].(string)
  10326. advice.Remark = remark
  10327. advice.AdviceType = 1
  10328. advice.StartTime = StartTime
  10329. advice.RecordDate = RecordDate
  10330. advice.PatientId = patient_id
  10331. advice.UserOrgId = org_id
  10332. advice.AdviceDoctor = advice_doctor
  10333. advices = append(advices, &advice)
  10334. }
  10335. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10336. c.ServeSuccessJSON(map[string]interface{}{
  10337. "advice": newAdvices,
  10338. })
  10339. }