dialysis_api_controller.go 428KB

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