dialysis_api_controller.go 408KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  891. redis := service.RedisClient()
  892. //清空key 值
  893. redis.Set(key, "", time.Second)
  894. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  895. redis.Set(keyOne, "", time.Second)
  896. defer redis.Close()
  897. if err == nil {
  898. c.ServeSuccessJSON(map[string]interface{}{
  899. "doubleCheck": &doubleCheck,
  900. })
  901. }
  902. } else { //修改
  903. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  904. if infor.ID > 0 {
  905. var cha_time int64
  906. timeNowStr := time.Now().Format("2006-01-02")
  907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  908. //今日的日期减去设置的日期
  909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  910. if cha_time >= recordDate.Unix() {
  911. //查询审核是否允许
  912. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  913. //申请状态不允许的情况 拒绝修改
  914. if infor.ApplicationStatus != 1 {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  916. return
  917. }
  918. }
  919. }
  920. doubleCheck.FirstCheckTime = firstCheckDate
  921. doubleCheck.CheckTime = checkDate
  922. doubleCheck.Creater = creater
  923. doubleCheck.Modifier = modifier
  924. doubleCheck.CreatedTime = check.CreatedTime
  925. doubleCheck.ID = check.ID
  926. doubleCheck.EmployeeNumber = employee_number
  927. doubleCheck.NeedleBatchNumber = needle_batch_number
  928. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  929. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  930. //查询未核对的医嘱
  931. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  932. for _, advice := range doctorList {
  933. if advice.ExecutionStaff == modifier {
  934. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  935. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  936. return
  937. }
  938. }
  939. }
  940. err := service.UpdateDoubleCheck(&doubleCheck)
  941. //针对长沙南雅
  942. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  943. //查询未核对的医嘱
  944. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  945. if len(doctorList) > 0 && modifier > 0 {
  946. for _, advice := range doctorList {
  947. service.UpdateDoctorAdviceList(advice.ID, modifier)
  948. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  949. redis := service.RedisClient()
  950. //清空key 值
  951. redis.Set(key, "", time.Second)
  952. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  953. redis.Set(keyTwo, "", time.Second)
  954. theTime := time.Now()
  955. recordDate := theTime.Format("2006-01-02")
  956. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  957. redis.Set(keyFour, "", time.Second)
  958. defer redis.Close()
  959. }
  960. }
  961. }
  962. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  963. redis := service.RedisClient()
  964. //清空key 值
  965. redis.Set(key, "", time.Second)
  966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  967. redis.Set(keyOne, "", time.Second)
  968. defer redis.Close()
  969. if err == nil {
  970. c.ServeSuccessJSON(map[string]interface{}{
  971. "doubleCheck": &doubleCheck,
  972. "msg": "1",
  973. })
  974. }
  975. }
  976. }
  977. func (c *DialysisAPIController) PostAcceptsAssessment() {
  978. id, _ := c.GetInt64("patient", 0)
  979. recordDateStr := c.GetString("record_date")
  980. way, _ := c.GetInt64("way", 0)
  981. consciousness, _ := c.GetInt64("consciousness", 0)
  982. appetite, _ := c.GetInt64("appetite", 0)
  983. condition, _ := c.GetInt64("condition", 0)
  984. posture, _ := c.GetInt64("posture")
  985. sick_condition, _ := c.GetInt64("sick_condition", 0)
  986. danger_level, _ := c.GetInt64("danger_level", 0)
  987. intake, _ := c.GetInt64("intake", 0)
  988. nutrition, _ := c.GetInt64("nutrition", 0)
  989. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  990. psychological_assessment_other := c.GetString("psychological_assessment_other")
  991. score := c.GetString("score")
  992. sick_condition_other := c.GetString("sick_condition_other")
  993. //precaution, _ := c.GetInt64("precaution", 0)
  994. precaution := c.GetString("precaution")
  995. precaution_other := c.GetString("precaution_other")
  996. psychological_other := c.GetString("psychological_other")
  997. admission_number := c.GetString("admission_number")
  998. tumble, _ := c.GetInt64("tumble")
  999. diacrisis := c.GetString("diacrisis")
  1000. his_department := c.GetString("his_department")
  1001. his_bed := c.GetString("his_bed")
  1002. if id <= 0 {
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. adminUserInfo := c.GetMobileAdminUserInfo()
  1007. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1008. if patient.ID == 0 {
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1010. return
  1011. }
  1012. //now := time.Now()
  1013. //year, month, day := now.Date()
  1014. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1015. //todayTimeStamp := today_time.Unix()
  1016. if len(recordDateStr) == 0 {
  1017. recordDateStr = time.Now().Format("2006-01-02")
  1018. }
  1019. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1020. if parseDateErr != nil {
  1021. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. // 查询信息规挡的设置天数
  1026. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1027. if infor.ID > 0 && infor.WeekDay > 0 {
  1028. var cha_time int64
  1029. timeNowStr := time.Now().Format("2006-01-02")
  1030. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1031. //今日的日期减去设置的日期
  1032. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1033. if cha_time >= recordDate.Unix() {
  1034. //查询审核是否允许
  1035. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1036. //申请状态不允许的情况 拒绝修改
  1037. if infor.ApplicationStatus != 1 {
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1039. return
  1040. }
  1041. }
  1042. }
  1043. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1044. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1045. UserOrgId: adminUserInfo.Org.Id,
  1046. PatientId: id,
  1047. RecordDate: recordDate.Unix(),
  1048. Way: way,
  1049. Consciousness: consciousness,
  1050. Appetite: appetite,
  1051. Condition: condition,
  1052. SickCondition: sick_condition,
  1053. DangerLevel: danger_level,
  1054. Intake: intake,
  1055. Nutrition: nutrition,
  1056. PsychologicalAssessment: psychological_assessment,
  1057. PsychologicalAssessmentOther: psychological_assessment_other,
  1058. SickConditionOther: sick_condition_other,
  1059. Posture: posture,
  1060. CreatedTime: time.Now().Unix(),
  1061. UpdateTime: time.Now().Unix(),
  1062. Status: 1,
  1063. Score: score,
  1064. Precaution: precaution,
  1065. PrecautionOther: precaution_other,
  1066. PsychologicalOther: psychological_other,
  1067. AdmissionNumber: admission_number,
  1068. Tumble: tumble,
  1069. Diacrisis: diacrisis,
  1070. HisBed: his_bed,
  1071. HisDepartment: his_department,
  1072. }
  1073. if receiveTreatment.ID == 0 { //新增
  1074. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1075. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1076. finish := models.XtDialysisFinish{
  1077. IsFinish: 1,
  1078. UserOrgId: adminUserInfo.Org.Id,
  1079. Status: 1,
  1080. Ctime: time.Now().Unix(),
  1081. Mtime: 0,
  1082. Module: 2,
  1083. RecordDate: recordDate.Unix(),
  1084. Sourse: 1,
  1085. PatientId: id,
  1086. }
  1087. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1088. if dialysisFinish.ID == 0 {
  1089. service.CreateDialysisFinish(finish)
  1090. }
  1091. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1092. redis := service.RedisClient()
  1093. defer redis.Close()
  1094. //清空key 值
  1095. redis.Set(key, "", time.Second)
  1096. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1097. redis.Set(keyOne, "", time.Second)
  1098. if err == nil {
  1099. c.ServeSuccessJSON(map[string]interface{}{
  1100. "receiveTreatmentAsses": receiveTreatmentAsses,
  1101. })
  1102. }
  1103. } else { //修改
  1104. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1105. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1106. // if getPermissionErr != nil {
  1107. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. // return
  1109. // } else if headNursePermission == nil {
  1110. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1111. // return
  1112. // }
  1113. //}
  1114. // 查询信息规挡的设置天数
  1115. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1116. if infor.ID > 0 && infor.WeekDay > 0 {
  1117. var cha_time int64
  1118. timeNowStr := time.Now().Format("2006-01-02")
  1119. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1120. //今日的日期减去设置的日期
  1121. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1122. if cha_time >= recordDate.Unix() {
  1123. //查询审核是否允许
  1124. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1125. //申请状态不允许的情况 拒绝修改
  1126. if infor.ApplicationStatus != 1 {
  1127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1128. return
  1129. }
  1130. }
  1131. }
  1132. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1133. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1134. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1135. receiveTreatmentAsses.ID = receiveTreatment.ID
  1136. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1137. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1138. redis := service.RedisClient()
  1139. defer redis.Close()
  1140. //清空key 值
  1141. redis.Set(key, "", time.Second)
  1142. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1143. redis.Set(keyOne, "", time.Second)
  1144. if err == nil {
  1145. c.ServeSuccessJSON(map[string]interface{}{
  1146. "receiveTreatmentAsses": receiveTreatmentAsses,
  1147. })
  1148. }
  1149. }
  1150. }
  1151. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1152. id, _ := c.GetInt64("patient", 0)
  1153. recordDateStr := c.GetString("record_date")
  1154. weightAfter, _ := c.GetFloat("weight_after", 0)
  1155. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1156. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1157. fmt.Println("weight_loss", weightReduce)
  1158. temperature, _ := c.GetFloat("temperature", 0)
  1159. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1160. breathing_rate := c.GetString("breathing_rate")
  1161. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1162. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1163. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1164. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1165. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1166. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1167. cruor := c.GetString("cruor")
  1168. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1169. internalFistula := c.GetString("internal_fistula")
  1170. catheter := c.GetString("catheter")
  1171. complications := c.GetString("complication")
  1172. remark := c.GetString("remark")
  1173. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1174. dialysis_intakes := c.GetString("dialysis_intakes")
  1175. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1176. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1177. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1178. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1179. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1180. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1181. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1182. patientGose, _ := c.GetInt64("patient_gose", 0)
  1183. inpatientDepartment := c.GetString("inpatient_department")
  1184. observationContent := c.GetString("observation_content")
  1185. observationContentOther := c.GetString("observation_content_other")
  1186. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1187. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1188. in_advance_reason := c.GetString("in_advance_reason")
  1189. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1190. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1191. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1192. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1193. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1194. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1195. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1196. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1197. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1198. is_eat, _ := c.GetInt64("is_eat", 0)
  1199. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1200. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1201. channels, _ := c.GetInt64("channel", 0)
  1202. return_blood, _ := c.GetInt64("return_blood", 0)
  1203. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1204. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1205. dialysis_during, _ := c.GetFloat("dialysis_during")
  1206. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1207. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1208. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1209. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1210. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1211. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1212. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1213. setting_pressure := c.GetString("setting_pressure")
  1214. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1215. diastolic_pressure := c.GetString("diastolic_pressure")
  1216. other_complication := c.GetString("other_complication")
  1217. ktv := c.GetString("ktv")
  1218. urr := c.GetString("urr")
  1219. hypertenison, _ := c.GetInt64("hypertenison")
  1220. hypopiesia, _ := c.GetInt64("hypopiesia")
  1221. leave_office_method, _ := c.GetInt64("leave_office_method")
  1222. lapse, _ := c.GetInt64("lapse")
  1223. consciousness, _ := c.GetInt64("consciousness")
  1224. fallrisk, _ := c.GetInt64("fallrisk")
  1225. machine_run := c.GetString("machine_run")
  1226. after_urea := c.GetString("after_urea")
  1227. pip_coagulation := c.GetString("pip_coagulation")
  1228. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1229. transfusion_volume := c.GetString("transfusion_volume")
  1230. last_after_weight := c.GetString("last_after_weight")
  1231. displace_liqui_value := c.GetString("displace_liqui_value")
  1232. if id <= 0 {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. adminUserInfo := c.GetMobileAdminUserInfo()
  1237. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1238. if patient.ID == 0 {
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1240. return
  1241. }
  1242. if len(recordDateStr) == 0 {
  1243. recordDateStr = time.Now().Format("2006-01-02")
  1244. }
  1245. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1246. fmt.Println("parseDateErr", parseDateErr)
  1247. if parseDateErr != nil {
  1248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. //now := time.Now()
  1253. //year, month, day := now.Date()
  1254. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1255. //todayTimeStamp := today_time.Unix()
  1256. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1257. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1258. UserOrgId: adminUserInfo.Org.Id,
  1259. PatientId: id,
  1260. AssessmentDate: recordDate.Unix(),
  1261. Temperature: temperature,
  1262. PulseFrequency: pulse_frequency,
  1263. BreathingRate: breathing_rate,
  1264. SystolicBloodPressure: systolic_blood_pressure,
  1265. DiastolicBloodPressure: diastolic_blood_pressure,
  1266. ActualUltrafiltration: actual_ultrafiltration,
  1267. ActualDisplacement: actual_displacement,
  1268. ActualTreatmentHour: actualtreatHour,
  1269. ActualTreatmentMinute: actualtreatmin,
  1270. WeightAfter: weightAfter,
  1271. AdditionalWeight: additionalWeight,
  1272. WeightLoss: weightReduce,
  1273. Cruor: cruor,
  1274. SymptomAfterDialysis: symptomsAfterDialysi,
  1275. InternalFistula: internalFistula,
  1276. Catheter: catheter,
  1277. Complication: complications,
  1278. DialysisIntakes: dialysateVolume,
  1279. CreatedTime: time.Now().Unix(),
  1280. UpdatedTime: time.Now().Unix(),
  1281. Status: 1,
  1282. Remark: remark,
  1283. BloodAccessPartId: blood_access_part_id,
  1284. BloodAccessPartOperaId: blood_access_part_opera_id,
  1285. DialysisIntakesUnit: dialysis_intakes_unit,
  1286. PuncturePointOozingBlood: puncturePointOozingBlood,
  1287. PuncturePointHaematoma: puncturePointHaematoma,
  1288. InternalFistulaTremorAc: internalFistulaTremorAc,
  1289. PatientGose: patientGose,
  1290. InpatientDepartment: inpatientDepartment,
  1291. ObservationContent: observationContent,
  1292. ObservationContentOther: observationContentOther,
  1293. DialysisProcess: dialysis_process,
  1294. InAdvanceMinute: in_advance_minute,
  1295. InAdvanceReason: in_advance_reason,
  1296. HemostasisMinute: hemostasis_minute,
  1297. HemostasisOpera: hemostasis_opera,
  1298. TremorNoise: tremor_noise,
  1299. DisequilibriumSyndrome: disequilibrium_syndrome,
  1300. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1301. ArterialTube: arterial_tube,
  1302. IntravenousTube: intravenous_tube,
  1303. Dialyzer: dialyzer,
  1304. InAdvanceReasonOther: in_advance_reason_other,
  1305. IsEat: is_eat,
  1306. CvcA: cvc_a,
  1307. CvcV: cvc_v,
  1308. Channel: channels,
  1309. ReturnBlood: return_blood,
  1310. RehydrationVolume: rehydration_volume,
  1311. DialysisDuring: dialysis_during,
  1312. StrokeVolume: stroke_volume,
  1313. BloodFlow: blood_flow,
  1314. SealingFluidDispose: sealing_fluid_dispose,
  1315. SealingFluidSpecial: sealing_fluid_special,
  1316. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1317. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1318. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1319. SettingPressure: setting_pressure,
  1320. DiastolicPressure: diastolic_pressure,
  1321. OtherComplication: other_complication,
  1322. Ktv: ktv,
  1323. Urr: urr,
  1324. Hypopiesia: hypopiesia,
  1325. Hypertenison: hypertenison,
  1326. Lapse: lapse,
  1327. LeaveOfficeMethod: leave_office_method,
  1328. Consciousness: consciousness,
  1329. Fallrisk: fallrisk,
  1330. MachineRun: machine_run,
  1331. AfterUrea: after_urea,
  1332. PipCoagulation: pip_coagulation,
  1333. AccumulatedBloodVolume: accumulated_blood_volume,
  1334. TransfusionVolume: transfusion_volume,
  1335. LastAfterWeight: last_after_weight,
  1336. DisplaceLiquiValue: displace_liqui_value,
  1337. }
  1338. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1339. // 查询信息规挡的设置天数
  1340. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1341. if infor.ID > 0 && infor.WeekDay > 0 {
  1342. var cha_time int64
  1343. timeNowStr := time.Now().Format("2006-01-02")
  1344. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1345. //今日的日期减去设置的日期
  1346. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1347. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1348. if cha_time >= recordDate.Unix() {
  1349. //查询审核是否允许
  1350. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1351. //申请状态不允许的情况 拒绝修改
  1352. if infor.ApplicationStatus != 1 {
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1354. return
  1355. }
  1356. }
  1357. }
  1358. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1359. if assessmentAfter.ID == 0 { //新增
  1360. if appRole.UserType == 2 || appRole.UserType == 1 {
  1361. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1362. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1363. } else {
  1364. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1365. }
  1366. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1367. if assessmentAfterDislysis.UserOrgId != 10340 {
  1368. if assessmentAfterDislysis.WeightAfter == 0 {
  1369. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1370. }
  1371. }
  1372. //孝康
  1373. //孝康
  1374. if adminUserInfo.Org.Id == 10693 {
  1375. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1376. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1377. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1378. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1379. }
  1380. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1381. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1382. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1383. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1384. }
  1385. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1386. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1387. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1388. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1389. }
  1390. if assessmentAfterDislysis.PulseFrequency == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1393. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1394. }
  1395. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1398. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1399. }
  1400. }
  1401. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1402. //记录日志
  1403. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1404. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1405. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1406. PatientId: assessmentAfterDislysis.PatientId,
  1407. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1408. Status: 1,
  1409. ErrLog: string(byterequest),
  1410. AdminUserId: adminUserInfo.AdminUser.Id,
  1411. Ctime: 0,
  1412. Mtime: 0,
  1413. Source: "手机端保存透后评估",
  1414. }
  1415. service.CreateAfterDialysisLog(afterDialysisLog)
  1416. finish := models.XtDialysisFinish{
  1417. IsFinish: 1,
  1418. UserOrgId: adminUserInfo.Org.Id,
  1419. Status: 1,
  1420. Ctime: time.Now().Unix(),
  1421. Mtime: 0,
  1422. Module: 9,
  1423. RecordDate: recordDate.Unix(),
  1424. Sourse: 1,
  1425. PatientId: id,
  1426. }
  1427. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1428. if dialysisFinish.ID == 0 {
  1429. service.CreateDialysisFinish(finish)
  1430. }
  1431. redis := service.RedisClient()
  1432. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1433. redis.Set(keyTwo, "", time.Second)
  1434. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1435. //清空key 值
  1436. redis.Set(key, "", time.Second)
  1437. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1438. redis.Set(keyOne, "", time.Second)
  1439. defer redis.Close()
  1440. if err == nil {
  1441. c.ServeSuccessJSON(map[string]interface{}{
  1442. "assessmentAfterDislysis": assessmentAfterDislysis,
  1443. })
  1444. }
  1445. return
  1446. } else { //修改
  1447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1448. if infor.ID > 0 && infor.WeekDay > 0 {
  1449. var cha_time int64
  1450. timeNowStr := time.Now().Format("2006-01-02")
  1451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1452. //今日的日期减去设置的日期
  1453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1454. if cha_time >= recordDate.Unix() {
  1455. //查询审核是否允许
  1456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1457. //申请状态不允许的情况 拒绝修改
  1458. if infor.ApplicationStatus != 1 {
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1460. return
  1461. }
  1462. }
  1463. }
  1464. if appRole.UserType == 2 || appRole.UserType == 1 {
  1465. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1466. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1467. } else {
  1468. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1469. if assessmentAfterDislysis.Creater == 0 {
  1470. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1471. }
  1472. }
  1473. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1474. assessmentAfterDislysis.ID = assessmentAfter.ID
  1475. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1476. if assessmentAfterDislysis.UserOrgId != 10340 {
  1477. if assessmentAfterDislysis.WeightAfter == 0 {
  1478. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1479. }
  1480. }
  1481. //孝康
  1482. if adminUserInfo.Org.Id == 10693 {
  1483. fmt.Println("adminUserInfo.Org.Id", assessmentAfterDislysis.ActualUltrafiltration)
  1484. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1485. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1486. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1487. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1488. }
  1489. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1490. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1491. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1492. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1493. }
  1494. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1495. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1496. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1497. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1498. }
  1499. if assessmentAfterDislysis.PulseFrequency == 0 {
  1500. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1501. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1502. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1503. }
  1504. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1505. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1506. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1507. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1508. }
  1509. }
  1510. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1511. //记录日志
  1512. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1513. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1514. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1515. PatientId: assessmentAfterDislysis.PatientId,
  1516. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1517. Status: 1,
  1518. ErrLog: string(byterequest),
  1519. AdminUserId: adminUserInfo.AdminUser.Id,
  1520. Ctime: time.Now().Unix(),
  1521. Mtime: 0,
  1522. Source: "手机端修改保存透后评估",
  1523. }
  1524. service.CreateAfterDialysisLog(afterDialysisLog)
  1525. redis := service.RedisClient()
  1526. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1527. redis.Set(keyTwo, "", time.Second)
  1528. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1529. //清空key 值
  1530. redis.Set(key, "", time.Second)
  1531. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1532. redis.Set(keyOne, "", time.Second)
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. return
  1538. }
  1539. }
  1540. return
  1541. }
  1542. func (c *DialysisAPIController) PostDialysisPrescription() {
  1543. id, _ := c.GetInt64("patient", 0)
  1544. recordDateStr := c.GetString("record_date")
  1545. if id <= 0 {
  1546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1547. return
  1548. }
  1549. adminUserInfo := c.GetMobileAdminUserInfo()
  1550. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1551. if patient.ID == 0 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1553. return
  1554. }
  1555. if len(recordDateStr) == 0 {
  1556. recordDateStr = time.Now().Format("2006-01-02")
  1557. }
  1558. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1559. if parseDateErr != nil {
  1560. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1562. return
  1563. }
  1564. mode_id, _ := c.GetInt64("mode_id", 0)
  1565. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1566. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1567. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1568. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1569. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1570. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1571. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1572. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1573. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1574. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1575. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1576. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1577. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1578. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1579. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1580. kalium, _ := c.GetFloat("kalium", 0)
  1581. sodium, _ := c.GetFloat("sodium", 0)
  1582. calcium, _ := c.GetFloat("calcium", 0)
  1583. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1584. glucose, _ := c.GetFloat("glucose", 0)
  1585. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1586. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1587. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1588. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1589. conductivity, _ := c.GetFloat("conductivity", 0)
  1590. remark := c.GetString("remark")
  1591. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1592. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1593. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1594. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1595. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1596. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1597. special_medicine_other := c.GetString("special_medicine_other")
  1598. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1599. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1600. blood_access, _ := c.GetInt64("blood_access", 0)
  1601. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1602. body_fluid_other := c.GetString("body_fluid_other")
  1603. niprocart, _ := c.GetInt64("niprocart", 0)
  1604. jms, _ := c.GetInt64("jms", 0)
  1605. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1606. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1607. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1608. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1609. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1610. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1611. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1612. injector, _ := c.GetInt64("injector", 0)
  1613. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1614. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1615. safe_package, _ := c.GetInt64("package", 0)
  1616. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1617. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1618. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1619. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1620. blood := c.GetString("blood")
  1621. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1622. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1623. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1624. displace_speed := c.GetString("displace_speed")
  1625. illness, _ := c.GetInt64("illness")
  1626. amylaceum := c.GetString("amylaceum")
  1627. single_time := c.GetString("single_time")
  1628. single_water := c.GetString("single_water")
  1629. replacement_flow := c.GetString("replacement_flow")
  1630. plasma_separator := c.GetString("plasma_separator")
  1631. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1632. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1633. oxygen_flow := c.GetString("oxygen_flow")
  1634. oxygen_time := c.GetString("oxygen_time")
  1635. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1636. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1637. puncture_needle := c.GetString("puncture_needle")
  1638. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1639. epo := c.GetString("epo")
  1640. epo_count, _ := c.GetFloat("epo_count", 0)
  1641. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1642. admin_user_id, _ := c.GetInt64("admin_user_id")
  1643. is_water := c.GetString("is_water")
  1644. var is_war int64
  1645. if is_water == "是" {
  1646. is_war = 1
  1647. }
  1648. if is_water == "否" {
  1649. is_war = 2
  1650. }
  1651. if is_water == "请选择" {
  1652. is_war = 0
  1653. }
  1654. drhy_water := c.GetString("drhy_water")
  1655. dry_water_hour := c.GetString("dry_water_hour")
  1656. water_machine := c.GetString("water_machine")
  1657. add_amount, _ := c.GetFloat("add_amount")
  1658. reduce_amount, _ := c.GetFloat("reduce_amount")
  1659. dialysis_remark := c.GetString("dialysis_remark")
  1660. prescribing_number, _ := c.GetFloat("prescribing_number")
  1661. prescription_sodium := c.GetString("prescription_sodium")
  1662. start_sodium := c.GetString("start_sodium")
  1663. sodium_curve := c.GetString("sodium_curve")
  1664. treatment_remark := c.GetString("treatment_remark")
  1665. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1666. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1667. prescription_water, _ := c.GetFloat("prescription_water")
  1668. dialysis_strainer := c.GetString("dialysis_strainer")
  1669. chaptalization := c.GetString("chaptalization")
  1670. washing_time := c.GetString("washing_time")
  1671. warsh_count := c.GetString("warsh_count")
  1672. blood_access_part_id := c.GetString("blood_access_part_id")
  1673. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1674. dialyzate := c.GetString("dialyzate")
  1675. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1676. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1677. //
  1678. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1679. // if appRole.UserType == 3 {
  1680. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1681. // if getPermissionErr != nil {
  1682. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1683. // return
  1684. // } else if headNursePermission == nil {
  1685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1686. // return
  1687. // }
  1688. // }
  1689. //}
  1690. // 查询信息规挡的设置天数
  1691. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1692. if infor.ID > 0 && infor.WeekDay > 0 {
  1693. var cha_time int64
  1694. timeNowStr := time.Now().Format("2006-01-02")
  1695. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1696. //今日的日期减去设置的日期
  1697. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1698. if cha_time >= recordDate.Unix() {
  1699. //查询审核是否允许
  1700. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1701. //申请状态不允许的情况 拒绝修改
  1702. if infor.ApplicationStatus != 1 {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1704. return
  1705. }
  1706. }
  1707. }
  1708. if mode_id > 0 {
  1709. var str string
  1710. //查找该机构用的是什么透析器
  1711. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1712. if filedConfig.ID > 0 {
  1713. str = dialyzerPerfusionApparatus
  1714. } else {
  1715. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1716. }
  1717. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1718. }
  1719. //TODO 需要根据角色去判断
  1720. prescription := models.DialysisPrescription{
  1721. UserOrgId: adminUserInfo.Org.Id,
  1722. PatientId: id,
  1723. RecordDate: recordDate.Unix(),
  1724. ModeId: mode_id,
  1725. DialysisDuration: dialysis_duration,
  1726. Dialyzer: dialyzer,
  1727. PerfusionApparatus: perfusion_apparatus,
  1728. BloodFlowVolume: blood_flow_volume,
  1729. DewaterAmount: dewater_amount,
  1730. DisplaceLiqui: displace_liqui,
  1731. ReplacementWay: replacement_way,
  1732. Anticoagulant: anticoagulant,
  1733. AnticoagulantShouji: anticoagulant_shouji,
  1734. AnticoagulantWeichi: anticoagulant_weichi,
  1735. AnticoagulantZongliang: anticoagulant_zongliang,
  1736. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1737. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1738. Kalium: kalium,
  1739. Sodium: sodium,
  1740. Calcium: calcium,
  1741. Bicarbonate: bicarbonate,
  1742. Glucose: glucose,
  1743. // DryWeight: dry_weight,
  1744. DialysateFlow: dialysate_flow,
  1745. DialysateTemperature: dialysate_temperature,
  1746. // PrescriptionDoctor: prescription_doctor,
  1747. ReplacementTotal: replacement_total,
  1748. Conductivity: conductivity,
  1749. Remark: remark,
  1750. Status: 1,
  1751. CreatedTime: time.Now().Unix(),
  1752. UpdatedTime: time.Now().Unix(),
  1753. DialysisDurationMinute: dialysisDurationMinute,
  1754. DialysisDurationHour: dialysisDurationHour,
  1755. TargetUltrafiltration: targetUltrafiltration,
  1756. DialysateFormulation: dialysateFormulation,
  1757. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1758. BodyFluid: body_fluid,
  1759. SpecialMedicine: special_medicine,
  1760. SpecialMedicineOther: special_medicine_other,
  1761. DisplaceLiquiPart: displace_liqui_part,
  1762. DisplaceLiquiValue: displace_liqui_value,
  1763. BloodAccess: blood_access,
  1764. Ultrafiltration: ultrafiltration,
  1765. BodyFluidOther: body_fluid_other,
  1766. Niprocart: niprocart,
  1767. Jms: jms,
  1768. FistulaNeedleSet: fistula_needle_set,
  1769. FistulaNeedleSet16: fistula_needle_set_16,
  1770. Hemoperfusion: hemoperfusion,
  1771. DialyserSterilised: dialyser_sterilised,
  1772. Filtryzer: filtryzer,
  1773. Dialyzers: dialyzers,
  1774. Injector: injector,
  1775. Bloodlines: bloodlines,
  1776. TubingHemodialysis: tubing_hemodialysis,
  1777. Package: safe_package,
  1778. ALiquid: a_liquid,
  1779. TargetKtv: target_ktv,
  1780. PreImpulse: pre_impulse,
  1781. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1782. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1783. Blood: blood,
  1784. DialysisDialyszers: dialysis_dialyszers,
  1785. DialysisIrrigation: dialysis_irrigation,
  1786. AntioxidantCommodityName: antioxidant_commodity_name,
  1787. DisplaceSpeed: displace_speed,
  1788. Illness: illness,
  1789. Amylaceum: amylaceum,
  1790. SingleTime: single_time,
  1791. SingleWater: single_water,
  1792. ReplacementFlow: replacement_flow,
  1793. PlasmaSeparator: plasma_separator,
  1794. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1795. OxygenUptake: oxygen_uptake,
  1796. OxygenFlow: oxygen_flow,
  1797. OxygenTime: oxygen_time,
  1798. HemodialysisPipelines: hemodialysis_pipelines,
  1799. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1800. PunctureNeedle: puncture_needle,
  1801. PunctureNeedleCount: puncture_needle_count,
  1802. Epo: epo,
  1803. EpoCount: epo_count,
  1804. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1805. AdminUserId: admin_user_id,
  1806. IsWater: is_war,
  1807. DrhyWater: drhy_water,
  1808. DryWaterHour: dry_water_hour,
  1809. WaterMachine: water_machine,
  1810. AddAmount: add_amount,
  1811. ReduceAmount: reduce_amount,
  1812. DialysisRemark: dialysis_remark,
  1813. PrescribingNumber: prescribing_number,
  1814. StartSodium: start_sodium,
  1815. SodiumCurve: sodium_curve,
  1816. TreatmentRemark: treatment_remark,
  1817. PrescriptionSodium: prescription_sodium,
  1818. DialysisFluidFlow: dialysis_fluid_flow,
  1819. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1820. PrescriptionWater: prescription_water,
  1821. DialysisStrainer: dialysis_strainer,
  1822. Chaptalization: chaptalization,
  1823. WashingTime: washing_time,
  1824. WarshCount: warsh_count,
  1825. BloodAccessPartId: blood_access_part_id,
  1826. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1827. Dialyzate: dialyzate,
  1828. }
  1829. //查询最近透析准备表里是否存在 透析器 灌流器
  1830. //
  1831. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1832. //
  1833. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1834. //
  1835. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1836. //if len(mation)>0{
  1837. // for _, item := range splitStr {
  1838. // for _,it := range mation{
  1839. // if(item == it.SpecificationName){
  1840. //
  1841. // //查询最近一次的透析器
  1842. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1843. //
  1844. // if errcode == gorm.ErrRecordNotFound{
  1845. // //插入数据
  1846. // prepare := models.DialysisBeforePrepare{
  1847. // UserOrgId: adminUserInfo.Org.Id,
  1848. // PatientId: id,
  1849. // RecordDate: recordDate.Unix(),
  1850. // GoodTypeId: it.GoodTypeId,
  1851. // GoodId: it.ID,
  1852. // Count: 1,
  1853. // Ctime: time.Now().Unix(),
  1854. // Creater: adminUserInfo.AdminUser.Id,
  1855. // Status:1,
  1856. //
  1857. // }
  1858. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1859. // fmt.Println("",errcode)
  1860. // }
  1861. // }
  1862. // }
  1863. //
  1864. // }
  1865. //
  1866. // for _, item := range splitIrrigation {
  1867. // for _,it := range mation{
  1868. // if(item == it.SpecificationName){
  1869. // //查询最近一次的透析器
  1870. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1871. // if errcode == gorm.ErrRecordNotFound{
  1872. // //插入数据
  1873. // prepare := models.DialysisBeforePrepare{
  1874. // UserOrgId: adminUserInfo.Org.Id,
  1875. // PatientId: id,
  1876. // RecordDate: recordDate.Unix(),
  1877. // GoodTypeId: it.GoodTypeId,
  1878. // GoodId: it.ID,
  1879. // Count: 1,
  1880. // Ctime: time.Now().Unix(),
  1881. // Creater: adminUserInfo.AdminUser.Id,
  1882. // Status:1,
  1883. //
  1884. // }
  1885. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1886. // fmt.Println(errcode)
  1887. // }
  1888. // }
  1889. // }
  1890. // }
  1891. //}
  1892. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1893. if dialysisPrescription.ID == 0 { //新增
  1894. if appRole.UserType == 2 || appRole.UserType == 1 {
  1895. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1896. }
  1897. prescription.Creater = adminUserInfo.AdminUser.Id
  1898. //针对河间咸得
  1899. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1900. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1901. prescription.DisplaceLiquiPart = 0
  1902. prescription.DisplaceLiquiValue = 0
  1903. }
  1904. }
  1905. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1906. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1907. }
  1908. err := service.AddSigleRecord(&prescription)
  1909. //记录日志
  1910. byterequest, _ := json.Marshal(prescription)
  1911. prescriptionLog := models.XtDialysisPrescriptionLog{
  1912. UserOrgId: prescription.UserOrgId,
  1913. Ctime: time.Now().Unix(),
  1914. Mtime: 0,
  1915. ErrLog: string(byterequest),
  1916. AdminUserId: adminUserInfo.AdminUser.Id,
  1917. RecordDate: prescription.RecordDate,
  1918. PatientId: prescription.PatientId,
  1919. Source: "手机端新增保存处方",
  1920. Status: 1,
  1921. }
  1922. service.CreatePrescriptionLog(prescriptionLog)
  1923. finish := models.XtDialysisFinish{
  1924. IsFinish: 1,
  1925. UserOrgId: adminUserInfo.Org.Id,
  1926. Status: 1,
  1927. Ctime: time.Now().Unix(),
  1928. Mtime: 0,
  1929. Module: 1,
  1930. RecordDate: recordDate.Unix(),
  1931. Sourse: 1,
  1932. PatientId: id,
  1933. }
  1934. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1935. if dialysisFinish.ID == 0 {
  1936. service.CreateDialysisFinish(finish)
  1937. }
  1938. //长沙南雅医院,自动生成抗凝剂的临时处方
  1939. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1940. if prescribing_number == 0 {
  1941. prescribing_number = 1
  1942. }
  1943. if prescribing_number == 0 && id == 14682 {
  1944. prescribing_number = 2
  1945. }
  1946. if prescribing_number == 0 && id == 18560 {
  1947. prescribing_number = 2
  1948. }
  1949. advice := models.DoctorAdvice{
  1950. UserOrgId: adminUserInfo.Org.Id,
  1951. PatientId: id,
  1952. GroupNo: 0,
  1953. AdviceType: 2,
  1954. RecordDate: recordDate.Unix(),
  1955. AdviceDate: recordDate.Unix(),
  1956. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1957. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1958. AdviceDesc: "",
  1959. ReminderDate: 0,
  1960. SingleDose: anticoagulant_zongliang,
  1961. SingleDoseUnit: "iu",
  1962. DrugSpec: 0,
  1963. DrugSpecUnit: "",
  1964. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1965. PrescribingNumberUnit: "支",
  1966. DeliveryWay: "静脉注射",
  1967. ExecutionFrequency: "上机前",
  1968. AdviceDoctor: 0,
  1969. Status: 1,
  1970. CreatedTime: time.Now().Unix(),
  1971. UpdatedTime: time.Now().Unix(),
  1972. IsPrescription: 1,
  1973. ExecutionState: 2,
  1974. StopState: 2,
  1975. IsSettle: 2,
  1976. }
  1977. // 查询排班信息
  1978. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1979. if schedulePatient.ID > 0 {
  1980. if schedulePatient.ScheduleType == 1 {
  1981. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1982. }
  1983. if schedulePatient.ScheduleType == 2 {
  1984. advice.StartTime = recordDate.Unix() + 9*60*60
  1985. }
  1986. }
  1987. // 抗凝剂名称
  1988. switch anticoagulant {
  1989. case 1:
  1990. advice.AdviceName = "无肝素"
  1991. break
  1992. case 2:
  1993. advice.AdviceName = "普通肝素"
  1994. break
  1995. case 3:
  1996. advice.AdviceName = "低分子肝素"
  1997. break
  1998. case 4:
  1999. advice.AdviceName = "阿加曲班"
  2000. break
  2001. case 5:
  2002. advice.AdviceName = "枸橼酸钠"
  2003. break
  2004. case 6:
  2005. advice.AdviceName = "低分子肝素钙"
  2006. break
  2007. case 7:
  2008. advice.AdviceName = "低分子肝素钠"
  2009. break
  2010. case 8:
  2011. advice.AdviceName = "依诺肝素"
  2012. break
  2013. case 9:
  2014. advice.AdviceName = "达肝素"
  2015. break
  2016. case 10:
  2017. advice.AdviceName = "体外抗凝"
  2018. break
  2019. case 11:
  2020. advice.AdviceName = "那曲肝素"
  2021. break
  2022. case 12:
  2023. advice.AdviceName = "无抗凝剂"
  2024. break
  2025. }
  2026. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2027. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2028. advice.AdviceDoctor = appRole.AdminUserId
  2029. }
  2030. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2031. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2032. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2033. advice.AdviceName = "低分子肝素钠注射液"
  2034. // 修改患者临时医嘱里的抗凝剂医嘱
  2035. advice.ID = advicePrescription.ID
  2036. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2037. } else {
  2038. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2039. advice.AdviceName = "低分子肝素钠注射液"
  2040. // 新增患者临时医嘱里的抗凝剂医嘱
  2041. service.CreateDoctorAdvice(&advice)
  2042. }
  2043. }
  2044. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2045. redis := service.RedisClient()
  2046. defer redis.Close()
  2047. //清空key 值
  2048. redis.Set(key, "", time.Second)
  2049. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2050. redis.Set(keyOne, "", time.Second)
  2051. }
  2052. //获取key,清空redis
  2053. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2054. redis := service.RedisClient()
  2055. //清空key 值
  2056. redis.Set(key, "", time.Second)
  2057. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2058. //清空key 值
  2059. redis.Set(keyOne, "", time.Second)
  2060. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2061. //清空key 值
  2062. redis.Set(keyTwo, "", time.Second)
  2063. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2064. redis.Set(keySix, "", time.Second)
  2065. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2066. redis.Set(keySeven, "", time.Second)
  2067. if err == nil {
  2068. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2069. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2070. //清空key 值
  2071. redis.Set(keyThree, "", time.Second)
  2072. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2073. //清空key 值
  2074. redis.Set(keyFour, "", time.Second)
  2075. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2076. redis.Set(keyFive, "", time.Second)
  2077. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2078. redis.Set(keySix, "", time.Second)
  2079. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2080. redis.Set(keySeven, "", time.Second)
  2081. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2082. //清空key 值
  2083. redis.Set(keyOne, "", time.Second)
  2084. if updateErr != nil {
  2085. utils.ErrorLog("%v", updateErr)
  2086. }
  2087. defer redis.Close()
  2088. c.ServeSuccessJSON(map[string]interface{}{
  2089. "prescription": prescription,
  2090. })
  2091. }
  2092. } else { //修改
  2093. //if mode_id > 0 {
  2094. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2095. //}
  2096. //if template.TemplateId == 1 {
  2097. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2098. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2099. // if getPermissionErr != nil {
  2100. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2101. // return
  2102. // } else if headNursePermission == nil {
  2103. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2104. // return
  2105. // }
  2106. // }
  2107. //}
  2108. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2109. prescription.Modifier = adminUserInfo.AdminUser.Id
  2110. if appRole.UserType == 2 || appRole.UserType == 1 {
  2111. prescription_doctor := adminUserInfo.AdminUser.Id
  2112. prescription.PrescriptionDoctor = prescription_doctor
  2113. } else {
  2114. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2115. }
  2116. if dialysisPrescription.Creater == 0 { //体重称
  2117. prescription.Creater = adminUserInfo.AdminUser.Id
  2118. } else {
  2119. prescription.Creater = dialysisPrescription.Creater
  2120. if adminUserInfo.Org.Id == 9882 {
  2121. if appRole.UserType == 2 || appRole.UserType == 1 {
  2122. prescription_doctor := adminUserInfo.AdminUser.Id
  2123. prescription.PrescriptionDoctor = prescription_doctor
  2124. prescription.Creater = prescription_doctor
  2125. }
  2126. }
  2127. }
  2128. prescription.ID = dialysisPrescription.ID
  2129. service.UpDateDialysisPrescription(&prescription)
  2130. //记录日志
  2131. byterequest, _ := json.Marshal(prescription)
  2132. prescriptionLog := models.XtDialysisPrescriptionLog{
  2133. UserOrgId: prescription.UserOrgId,
  2134. Ctime: time.Now().Unix(),
  2135. Mtime: 0,
  2136. ErrLog: string(byterequest),
  2137. AdminUserId: adminUserInfo.AdminUser.Id,
  2138. RecordDate: prescription.RecordDate,
  2139. PatientId: prescription.PatientId,
  2140. Source: "手机端修改处方",
  2141. Status: 1,
  2142. }
  2143. service.CreatePrescriptionLog(prescriptionLog)
  2144. finish := models.XtDialysisFinish{
  2145. IsFinish: 1,
  2146. UserOrgId: adminUserInfo.Org.Id,
  2147. Status: 1,
  2148. Ctime: time.Now().Unix(),
  2149. Mtime: 0,
  2150. Module: 1,
  2151. RecordDate: recordDate.Unix(),
  2152. Sourse: 1,
  2153. PatientId: id,
  2154. }
  2155. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2156. if dialysisFinish.ID == 0 {
  2157. service.CreateDialysisFinish(finish)
  2158. }
  2159. //修改处方
  2160. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2161. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2162. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2163. if advicePrescription.ID > 0 {
  2164. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2165. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2166. redis := service.RedisClient()
  2167. defer redis.Close()
  2168. //清空key 值
  2169. redis.Set(key, "", time.Second)
  2170. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2171. redis.Set(keyOne, "", time.Second)
  2172. }
  2173. }
  2174. //获取key,清空redis
  2175. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2176. redis := service.RedisClient()
  2177. //清空key 值
  2178. redis.Set(key, "", time.Second)
  2179. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2180. //清空key 值
  2181. redis.Set(keyOne, "", time.Second)
  2182. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2183. redis.Set(keySix, "", time.Second)
  2184. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2185. redis.Set(keySeven, "", time.Second)
  2186. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2187. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2188. //清空key 值
  2189. redis.Set(keyTwoOne, "", time.Second)
  2190. defer redis.Close()
  2191. if updateErr != nil {
  2192. utils.ErrorLog("%v", updateErr)
  2193. }
  2194. c.ServeSuccessJSON(map[string]interface{}{
  2195. "prescription": prescription,
  2196. })
  2197. }
  2198. }
  2199. func (c *DialysisAPIController) Finish() {
  2200. id, _ := c.GetInt64("patient", 0)
  2201. recordDateStr := c.GetString("record_date")
  2202. nurseID, _ := c.GetInt64("nurse")
  2203. end_time := c.GetString("end_time")
  2204. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2205. internal_fistula := c.GetString("blood_access_internal_fistula")
  2206. catheter := c.GetString("catheter")
  2207. cruor := c.GetString("cruor")
  2208. mission := c.GetString("mission")
  2209. condenser := c.GetString("condenser")
  2210. if id <= 0 || nurseID <= 0 {
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2212. return
  2213. }
  2214. adminUserInfo := c.GetMobileAdminUserInfo()
  2215. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2216. if patient.ID == 0 {
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2218. return
  2219. }
  2220. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2221. if getNurseErr != nil {
  2222. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2224. return
  2225. } else if nurse == nil {
  2226. c.ErrorLog("护士不存在")
  2227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2228. return
  2229. }
  2230. if len(recordDateStr) == 0 {
  2231. recordDateStr = time.Now().Format("2006-01-02")
  2232. }
  2233. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2234. if parseDateErr != nil {
  2235. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2237. return
  2238. }
  2239. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2240. if parseEndDateErr != nil {
  2241. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2243. return
  2244. }
  2245. // 查询信息规挡的设置天数
  2246. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2247. if infor.ID > 0 && infor.WeekDay > 0 {
  2248. var cha_time int64
  2249. timeNowStr := time.Now().Format("2006-01-02")
  2250. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2251. //今日的日期减去设置的日期
  2252. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2253. if cha_time >= recordDate.Unix() {
  2254. //查询审核是否允许
  2255. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2256. //申请状态不允许的情况 拒绝修改
  2257. if infor.ApplicationStatus != 1 {
  2258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2259. return
  2260. }
  2261. }
  2262. }
  2263. //now := time.Now()
  2264. //year, month, day := now.Date()
  2265. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2266. //todayTimeStamp := today_time.Unix()
  2267. // 获取当天的第一条透析纪录
  2268. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2269. if getMonitorRecordsErr != nil {
  2270. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2272. return
  2273. }
  2274. // 获取当前的最后一条透析纪录
  2275. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2276. if getMonitorRecordsErr != nil {
  2277. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2279. return
  2280. }
  2281. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2282. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2283. if getAADErr != nil {
  2284. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2286. return
  2287. }
  2288. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2290. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2291. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2292. if assessmentAfterDislysis != nil {
  2293. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2294. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2295. } else {
  2296. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2297. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2298. tempassessmentAfterDislysis.Status = 1
  2299. tempassessmentAfterDislysis.PatientId = id
  2300. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2301. }
  2302. //长沙南雅
  2303. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2304. //获取最后一条透析处方数据
  2305. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2306. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2307. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2308. }
  2309. if dialysisOrder.Stage == 1 {
  2310. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2311. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2312. fmt.Println(value)
  2313. a, b := math.Modf(value)
  2314. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2315. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2316. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2317. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2318. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2319. }
  2320. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2321. //var num1 int64
  2322. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2323. //fmt.Println(num1)
  2324. //sub := float64(num1 / 3600)
  2325. //fmt.Println(sub)
  2326. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2327. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2328. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2329. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2330. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2331. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2332. if adminUserInfo.Org.Id != 10375 {
  2333. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2334. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2335. }
  2336. if adminUserInfo.Org.Id != 10445 {
  2337. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2338. }
  2339. //北方营口医院
  2340. if adminUserInfo.Org.Id == 10445 {
  2341. //获取最后一条透析处方数据
  2342. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2343. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2344. } else {
  2345. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2346. }
  2347. //新化博翔
  2348. if adminUserInfo.Org.Id == 10447 {
  2349. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2350. }
  2351. //阳春
  2352. if adminUserInfo.Org.Id == 10485 {
  2353. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2354. }
  2355. if adminUserInfo.Org.Id == 10551 {
  2356. //获取最后一条透析处方数据
  2357. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2358. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2359. }
  2360. if adminUserInfo.Org.Id == 10580 {
  2361. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2362. }
  2363. if adminUserInfo.Org.Id == 10612 {
  2364. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2365. }
  2366. //孝康
  2367. if adminUserInfo.Org.Id == 10693 {
  2368. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2369. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2370. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2371. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2372. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2373. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2374. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2375. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2376. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2377. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2378. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2379. }
  2380. if adminUserInfo.Org.Id == 10697 {
  2381. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2382. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2383. lastWeightAfter.LastAfterWeight = floatAfeter
  2384. }
  2385. }
  2386. 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 {
  2387. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2388. if evaluation.SystolicBloodPressure == 0 {
  2389. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2390. if adminUserInfo.Org.Id == 10693 {
  2391. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2392. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2393. }
  2394. pre := models.PredialysisEvaluation{
  2395. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2396. }
  2397. fmt.Println("prew", pre)
  2398. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2399. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2400. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2401. redis := service.RedisClient()
  2402. redis.Set(key, "", time.Second)
  2403. redis.Set(keyOne, "", time.Second)
  2404. defer redis.Close()
  2405. fmt.Println(getNurseErr)
  2406. }
  2407. if evaluation.DiastolicBloodPressure == 0 {
  2408. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2409. if adminUserInfo.Org.Id == 10693 {
  2410. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2411. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2412. }
  2413. pres := models.PredialysisEvaluation{
  2414. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2415. }
  2416. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2417. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2418. redis := service.RedisClient()
  2419. redis.Set(key, "", time.Second)
  2420. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2421. redis.Set(keyOne, "", time.Second)
  2422. defer redis.Close()
  2423. fmt.Println(getNurseErr)
  2424. }
  2425. if evaluation.PulseFrequency == 0 {
  2426. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2427. if adminUserInfo.Org.Id == 10693 {
  2428. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2429. evaluation.PulseFrequency = pulseFrequency
  2430. }
  2431. press := models.PredialysisEvaluation{
  2432. PulseFrequency: evaluation.PulseFrequency,
  2433. }
  2434. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2435. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2436. redis := service.RedisClient()
  2437. redis.Set(key, "", time.Second)
  2438. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2439. redis.Set(keyOne, "", time.Second)
  2440. defer redis.Close()
  2441. fmt.Println(getNurseErr)
  2442. }
  2443. if evaluation.Temperature == 0 {
  2444. evaluation.Temperature = fmonitorRecords.Temperature
  2445. press := models.PredialysisEvaluation{
  2446. Temperature: evaluation.Temperature,
  2447. }
  2448. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2450. redis := service.RedisClient()
  2451. redis.Set(key, "", time.Second)
  2452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2453. redis.Set(keyOne, "", time.Second)
  2454. defer redis.Close()
  2455. fmt.Println(getNurseErr)
  2456. }
  2457. }
  2458. if adminUserInfo.Org.Id == 9583 {
  2459. //获取透析处方的最后一条数据
  2460. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2461. if diaerr != nil {
  2462. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2464. return
  2465. }
  2466. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2467. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2468. }
  2469. }
  2470. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2471. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2472. }
  2473. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2474. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2475. }
  2476. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2477. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2478. }
  2479. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2481. }
  2482. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2483. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2484. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2487. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2488. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2489. }
  2490. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2491. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2492. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2493. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2494. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2495. }
  2496. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2497. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2498. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2499. }
  2500. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2501. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2502. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2503. }
  2504. if lastAssessmentAfterDislysis != nil {
  2505. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2506. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2507. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2508. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2509. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2510. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2511. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2512. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2513. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2514. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2515. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2516. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2517. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2518. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2519. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2520. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2521. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2522. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2523. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2524. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2525. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2526. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2527. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2528. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2529. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2530. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2531. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2532. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2533. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2534. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2535. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2536. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2537. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2538. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2539. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2540. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2541. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2542. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2543. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2544. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2545. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2546. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2547. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2548. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2549. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2550. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2551. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2552. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2553. if tempassessmentAfterDislysis.PatientId == 18695 {
  2554. tempassessmentAfterDislysis.ActualDisplacement = 0
  2555. }
  2556. if adminUserInfo.Org.Id != 10375 {
  2557. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2558. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2559. }
  2560. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2561. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2562. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2563. }
  2564. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2565. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2566. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2567. }
  2568. }
  2569. finish := models.XtDialysisFinish{
  2570. IsFinish: 1,
  2571. UserOrgId: adminUserInfo.Org.Id,
  2572. Status: 1,
  2573. Ctime: time.Now().Unix(),
  2574. Mtime: 0,
  2575. Module: 9,
  2576. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2577. Sourse: 1,
  2578. PatientId: tempassessmentAfterDislysis.PatientId,
  2579. }
  2580. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2581. if dialysisFinish.ID == 0 {
  2582. service.CreateDialysisFinish(finish)
  2583. }
  2584. //孝康
  2585. if adminUserInfo.Org.Id == 10693 {
  2586. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2587. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2588. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2589. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2590. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2591. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2592. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2593. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2594. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2595. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2596. }
  2597. if adminUserInfo.Org.Id == 10697 {
  2598. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2599. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2600. lastWeightAfter.LastAfterWeight = floatAfeter
  2601. }
  2602. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2603. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2604. redis := service.RedisClient()
  2605. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2606. redis.Set(keyOne, "", time.Second)
  2607. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2608. redis.Set(keyTwo, "", time.Second)
  2609. defer redis.Close()
  2610. //清空key 值
  2611. redis.Set(key, "", time.Second)
  2612. if err != nil {
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2614. return
  2615. }
  2616. if dialysisOrder == nil {
  2617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2618. return
  2619. }
  2620. if dialysisOrder.Stage == 2 {
  2621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2622. return
  2623. }
  2624. if dialysisOrder.Stage == 1 {
  2625. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2626. finish := models.XtDialysisFinish{
  2627. IsFinish: 1,
  2628. UserOrgId: adminUserInfo.Org.Id,
  2629. Status: 1,
  2630. Ctime: time.Now().Unix(),
  2631. Mtime: 0,
  2632. Module: 8,
  2633. RecordDate: recordDate.Unix(),
  2634. Sourse: 1,
  2635. PatientId: id,
  2636. }
  2637. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2638. if dialysisFinish.ID == 0 {
  2639. service.CreateDialysisFinish(finish)
  2640. }
  2641. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2642. redis := service.RedisClient()
  2643. defer redis.Close()
  2644. //清空key 值
  2645. redis.Set(key, "", time.Second)
  2646. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2647. redis.Set(keyOne, "", time.Second)
  2648. //结束时候透析次数加1
  2649. service.UpdateSolutionByPatientId(id)
  2650. //下机完自动消毒,针对长沙南雅
  2651. if dialysisOrder.Stage == 1 {
  2652. 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 {
  2653. //根据床位号获取设备型号
  2654. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2655. //查询使用消毒最后一条消毒记录
  2656. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2657. fmt.Println("err", err)
  2658. if err == gorm.ErrRecordNotFound {
  2659. //查找排班
  2660. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2661. //查询改设备是否有消毒计划
  2662. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2663. //根据床位号获取设备id
  2664. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2665. //查询病人信息
  2666. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2667. var con = ""
  2668. if patients.IsInfectious == 0 {
  2669. con = ""
  2670. }
  2671. if patients.IsInfectious == 1 {
  2672. con = "无"
  2673. }
  2674. if patients.IsInfectious == 2 {
  2675. con = "有"
  2676. }
  2677. if errcode == nil {
  2678. var end_time int64
  2679. end_time = endDate.Unix() + plan.DisinfecTime*60
  2680. //新增消毒
  2681. information := models.DeviceInformation{
  2682. Date: dialysisOrder.DialysisDate,
  2683. Zone: dialysisOrder.ZoneId,
  2684. Class: dialysisOrder.SchedualType,
  2685. BedNumber: dialysisOrder.BedID,
  2686. PatientId: dialysisOrder.PatientId,
  2687. DialysisMode: scheduleByPatient.ModeId,
  2688. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2689. Disinfection: 1,
  2690. DialysisConcentration: 1,
  2691. DisinfectionStatus: 1,
  2692. Move: 1,
  2693. UserOrgId: dialysisOrder.UserOrgId,
  2694. DisinfectType: plan.Way,
  2695. DisinfectantType: plan.MachineDisinfectant,
  2696. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2697. Disinfectant: plan.Disinfectant,
  2698. Ctime: time.Now().Unix(),
  2699. Status: 1,
  2700. SignName: nurseID,
  2701. EquimentId: addmacher.ID,
  2702. DisinfectionResidue: 2,
  2703. Bed: addmacher.BedNumber,
  2704. StartTime: dialysisOrder.StartTime,
  2705. EndTime: dialysisOrder.EndTime,
  2706. Contagion: con,
  2707. WeightLoss: 0,
  2708. Hyperfiltratio: 0,
  2709. DialysisHour: "",
  2710. MachineRun: 1,
  2711. DisinfecStartime: endDate.Unix(),
  2712. DisinfecEndtime: end_time,
  2713. }
  2714. err := service.CreateInformationTwo(&information)
  2715. fmt.Println("报错", err)
  2716. }
  2717. }
  2718. }
  2719. }
  2720. dialysisOrder.Stage = 2
  2721. dialysisOrder.FinishNurse = nurseID
  2722. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2723. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2724. dialysisOrder.EndTime = endDate.Unix()
  2725. // 长沙南雅需求
  2726. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2727. //获取最后1条监测的数据
  2728. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2729. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2730. var accumulatedBloodVolume float64
  2731. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2732. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2733. fmt.Println(err)
  2734. // 查询未执行的医嘱
  2735. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2736. for _, item := range doctorAdvice {
  2737. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2738. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2739. redis := service.RedisClient()
  2740. //清空key 值
  2741. redis.Set(key, "", time.Second)
  2742. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2743. redis.Set(keyTwo, "", time.Second)
  2744. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2745. redis.Set(keyThree, "", time.Second)
  2746. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2747. theTime := toTime.Format("2006-01-02")
  2748. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2749. redis.Set(keyFour, "", time.Second)
  2750. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2751. redis.Set(keyFive, "", time.Second)
  2752. defer redis.Close()
  2753. }
  2754. }
  2755. go func() {
  2756. ssoDomain := beego.AppConfig.String("call_domain")
  2757. api := ssoDomain + "/index/downpatient"
  2758. values := make(url.Values)
  2759. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2760. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2761. values.Set("patient_id", strconv.FormatInt(id, 10))
  2762. http.PostForm(api, values)
  2763. }()
  2764. if err == nil {
  2765. c.ServeSuccessJSON(map[string]interface{}{
  2766. "dialysisOrder": dialysisOrder,
  2767. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2768. })
  2769. } else {
  2770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2771. }
  2772. }
  2773. }
  2774. func (c *DialysisAPIController) GetAllZone() {
  2775. adminUserInfo := c.GetMobileAdminUserInfo()
  2776. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "zone": zone,
  2780. })
  2781. }
  2782. }
  2783. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2784. adminUserInfo := c.GetMobileAdminUserInfo()
  2785. page, _ := c.GetInt64("page", 1)
  2786. limit, _ := c.GetInt64("limit", 10)
  2787. schedulType, _ := c.GetInt64("schedul_type", 0)
  2788. startTime, _ := c.GetInt64("schedul_time", 0)
  2789. partitionType, _ := c.GetInt64("partition_type", 0)
  2790. keywords := c.GetString("keywords")
  2791. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2792. if err == nil {
  2793. c.ServeSuccessJSON(map[string]interface{}{
  2794. "schedule": dialysisSchedule,
  2795. })
  2796. }
  2797. return
  2798. }
  2799. // /m/api/dialysis/start [post]
  2800. // @param patient_id:int
  2801. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2802. // @param nurse:int 上机护士
  2803. // @param bed:int 床位号
  2804. func (this *DialysisAPIController) StartDialysis() {
  2805. patientID, _ := this.GetInt64("patient_id")
  2806. recordDateStr := this.GetString("record_date")
  2807. nurseID, _ := this.GetInt64("start_nurse")
  2808. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2809. blood_drawing, _ := this.GetInt64("blood_drawing")
  2810. schedual_type, _ := this.GetInt64("schedual_type")
  2811. bedID, _ := this.GetInt64("bed")
  2812. start_time := this.GetString("start_time")
  2813. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2814. change_nurse, _ := this.GetInt64("change_nurse")
  2815. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2816. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2817. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2818. puncture_needle := this.GetString("puncture_needle")
  2819. puncture_way := this.GetString("puncture_way")
  2820. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2821. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2822. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2823. zone_id, _ := this.GetInt64("zone_id")
  2824. elecsign := this.GetString("url")
  2825. nuclein_date_str := this.GetString("nuclein_date_str")
  2826. schedule_remark := this.GetString("schedule_remark")
  2827. order_remark := this.GetString("order_remark")
  2828. catheter_operation := this.GetString("catheter_operation")
  2829. blood_flow_volume := this.GetString("blood_flow_volume")
  2830. dialysis_strainer := this.GetString("dialysis_strainer")
  2831. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2833. return
  2834. }
  2835. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2836. if parseStartDateErr != nil {
  2837. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2839. return
  2840. }
  2841. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2842. if parseErr != nil {
  2843. this.ErrorLog("时间解析失败:%v", parseErr)
  2844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2845. return
  2846. }
  2847. adminUserInfo := this.GetMobileAdminUserInfo()
  2848. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2849. if getPatientErr != nil {
  2850. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2852. return
  2853. } else if patient == nil {
  2854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2855. return
  2856. }
  2857. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2858. if getNurseErr != nil {
  2859. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2861. return
  2862. } else if nurse == nil {
  2863. this.ErrorLog("护士不存在")
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2865. return
  2866. }
  2867. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2868. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2869. if getDeviceNumberErr != nil {
  2870. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2872. return
  2873. } else if deviceNumber == nil {
  2874. this.ErrorLog("床位号不存在")
  2875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2876. return
  2877. }
  2878. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2879. if getRecordErr != nil {
  2880. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2882. return
  2883. } else if dialysisRecord != nil {
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2885. return
  2886. }
  2887. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2888. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2889. timeLayout := "2006-01-02 15:04:05"
  2890. loc, _ := time.LoadLocation("Local")
  2891. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2892. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2893. schedulestartTime := theStartTime.Unix()
  2894. scheduleendTime := theEndTime.Unix()
  2895. var theNucleinDate int64
  2896. timeLayoutOne := "2006-01-02"
  2897. if len(nuclein_date_str) > 0 {
  2898. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2899. if err != nil {
  2900. utils.ErrorLog(err.Error())
  2901. }
  2902. theNucleinDate = theTime.Unix()
  2903. }
  2904. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2905. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2906. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2907. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2908. //查询该床位是否有人用了
  2909. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2910. if err == gorm.ErrRecordNotFound { //空床位
  2911. // 修改了床位逻辑
  2912. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2913. if daySchedule.ID > 0 {
  2914. daySchedule.PartitionId = deviceNumber.ZoneID
  2915. daySchedule.BedId = bedID
  2916. daySchedule.ScheduleType = schedual_type
  2917. daySchedule.UpdatedTime = time.Now().Unix()
  2918. xtSchedule := models.Schedule{
  2919. PartitionId: deviceNumber.ZoneID,
  2920. BedId: bedID,
  2921. ScheduleType: schedual_type,
  2922. UpdatedTime: time.Now().Unix(),
  2923. }
  2924. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2925. if err != nil {
  2926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2927. return
  2928. }
  2929. }
  2930. } else if err == nil {
  2931. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2932. if order.ID > 0 { //该机位被其他人占用了
  2933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2934. return
  2935. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2936. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2937. if daySchedule.ID > 0 {
  2938. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2939. if err != nil {
  2940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2941. return
  2942. }
  2943. }
  2944. }
  2945. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. }
  2949. //else if order.ID == 0 { //该床位没被占用
  2950. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2951. // if daySchedule.ID > 0 {
  2952. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2953. // //daySchedule.BedId = bedID
  2954. // //daySchedule.ScheduleType = schedual_type
  2955. // //daySchedule.UpdatedTime = time.Now().Unix()
  2956. // //err := service.UpdateSchedule(&daySchedule)
  2957. // xtSchedule := models.Schedule{
  2958. // PartitionId: deviceNumber.ZoneID,
  2959. // BedId: bedID,
  2960. // ScheduleType: schedual_type,
  2961. // UpdatedTime: time.Now().Unix(),
  2962. // }
  2963. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2964. // if err != nil {
  2965. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2966. // return
  2967. // }
  2968. // }
  2969. //}
  2970. //}
  2971. } else if err != nil {
  2972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2973. return
  2974. }
  2975. // 查询信息规挡的设置天数
  2976. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2977. if infor.ID > 0 && infor.WeekDay > 0 {
  2978. var cha_time int64
  2979. timeNowStr := time.Now().Format("2006-01-02")
  2980. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2981. //今日的日期减去设置的日期
  2982. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2983. if cha_time >= recordDate.Unix() {
  2984. //查询审核是否允许
  2985. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2986. //申请状态不允许的情况 拒绝修改
  2987. if infor.ApplicationStatus != 1 {
  2988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2989. return
  2990. }
  2991. }
  2992. }
  2993. dialysisRecord = &models.DialysisOrder{
  2994. DialysisDate: recordDate.Unix(),
  2995. UserOrgId: adminUserInfo.Org.Id,
  2996. PatientId: patientID,
  2997. Stage: 1,
  2998. BedID: bedID,
  2999. StartNurse: nurseID,
  3000. Status: 1,
  3001. StartTime: startDate.Unix(),
  3002. CreatedTime: time.Now().Unix(),
  3003. UpdatedTime: time.Now().Unix(),
  3004. PunctureNurse: puncture_nurse,
  3005. Creator: adminUserInfo.AdminUser.Id,
  3006. Modifier: adminUserInfo.AdminUser.Id,
  3007. SchedualType: schedual_type,
  3008. WashpipeNurse: washpipe_nurse,
  3009. ChangeNurse: change_nurse,
  3010. DifficultPunctureNurse: difficult_puncture_nurse,
  3011. NewFistulaNurse: new_fistula_nurse,
  3012. ZoneId: zone_id,
  3013. QualityNurseId: quality_nurse_id,
  3014. PunctureNeedle: puncture_needle,
  3015. PunctureWay: puncture_way,
  3016. DialysisIrrigation: dialysis_irrigation,
  3017. DialysisDialyszers: dialysis_dialyszers,
  3018. BloodAccessId: blood_access_id,
  3019. Url: elecsign,
  3020. NucleinDate: theNucleinDate,
  3021. ScheduleRemark: schedule_remark,
  3022. OrderRemark: order_remark,
  3023. CatheterOperation: catheter_operation,
  3024. BloodFlowVolume: blood_flow_volume,
  3025. BloodDrawing: blood_drawing,
  3026. DialysisStrainer: dialysis_strainer,
  3027. }
  3028. //查询该床位是否有人用了
  3029. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3030. if errorscode == gorm.ErrRecordNotFound {
  3031. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3032. finish := models.XtDialysisFinish{
  3033. IsFinish: 1,
  3034. UserOrgId: adminUserInfo.Org.Id,
  3035. Status: 1,
  3036. Ctime: time.Now().Unix(),
  3037. Mtime: 0,
  3038. Module: 6,
  3039. RecordDate: schedulestartTime,
  3040. Sourse: 1,
  3041. PatientId: patientID,
  3042. }
  3043. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3044. if dialysisFinish.ID == 0 {
  3045. service.CreateDialysisFinish(finish)
  3046. }
  3047. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3048. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3049. //统计该患者总次数
  3050. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3051. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3052. }
  3053. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3054. //统计该患者总次数
  3055. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3056. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3057. }
  3058. redis := service.RedisClient()
  3059. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3060. redis.Set(key, "", time.Second)
  3061. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3062. //清空key 值
  3063. redis.Set(keyOne, "", time.Second)
  3064. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3065. //清空key 值
  3066. redis.Set(keyTwo, "", time.Second)
  3067. if createErr != nil {
  3068. this.ErrorLog("上机失败:%v", createErr)
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3070. return
  3071. }
  3072. }
  3073. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3074. var tempdispose string
  3075. // 只针对中能建
  3076. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3077. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3078. }
  3079. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3080. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3081. }
  3082. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3083. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3084. //}
  3085. var ultrafiltration_rate float64
  3086. var ultrafiltration_rate_one string
  3087. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3088. //后期预增脱水量
  3089. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3090. if prescription.ID > 0 {
  3091. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3092. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3093. 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
  3094. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3095. }
  3096. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3097. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3098. }
  3099. //针对医师汇
  3100. if adminUserInfo.Org.Id == 10121 {
  3101. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3102. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3103. }
  3104. //针对通道
  3105. if adminUserInfo.Org.Id == 10234 {
  3106. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3107. }
  3108. //针对监利大垸医院
  3109. if template.TemplateId == 41 {
  3110. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3111. }
  3112. //针对肇庆三鹤血液透析中心
  3113. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3114. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3115. }
  3116. if adminUserInfo.Org.Id == 10469 {
  3117. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3118. }
  3119. if adminUserInfo.Org.Id == 10667 {
  3120. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3121. }
  3122. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3124. }
  3125. // 只针对方济医院
  3126. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3127. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3128. ultrafiltration_rate = value
  3129. }
  3130. //针对
  3131. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3132. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3133. ultrafiltration_rate = ultrafiltration_rate / 1000
  3134. }
  3135. if adminUserInfo.Org.Id == 10551 {
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3137. ultrafiltration_rate = ultrafiltration_rate / 1000
  3138. }
  3139. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3140. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3141. ultrafiltration_rate = ultrafiltration_rate / 1000
  3142. }
  3143. if adminUserInfo.Org.Id == 10580 {
  3144. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3145. ultrafiltration_rate = ultrafiltration_rate / 1000
  3146. }
  3147. if adminUserInfo.Org.Id == 10629 {
  3148. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3149. ultrafiltration_rate = ultrafiltration_rate / 1000
  3150. }
  3151. if adminUserInfo.Org.Id == 10644 {
  3152. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3153. ultrafiltration_rate = ultrafiltration_rate / 1000
  3154. }
  3155. if adminUserInfo.Org.Id == 10667 {
  3156. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3157. ultrafiltration_rate = ultrafiltration_rate / 1000
  3158. }
  3159. //孝昌
  3160. if adminUserInfo.Org.Id == 10693 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate
  3163. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3164. }
  3165. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3166. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3167. ultrafiltration_rate = ultrafiltration_rate / 1000
  3168. }
  3169. if adminUserInfo.Org.Id == 10702 {
  3170. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3171. ultrafiltration_rate = ultrafiltration_rate / 1000
  3172. }
  3173. }
  3174. }
  3175. record := models.MonitoringRecord{
  3176. UserOrgId: adminUserInfo.Org.Id,
  3177. PatientId: patientID,
  3178. DialysisOrderId: dialysisRecord.ID,
  3179. MonitoringDate: schedulestartTime,
  3180. OperateTime: startDate.Unix(),
  3181. // MonitoringTime: recordTime,
  3182. MonitoringNurse: nurseID,
  3183. Dispose: tempdispose,
  3184. UltrafiltrationRate: ultrafiltration_rate,
  3185. UltrafiltrationVolume: 0,
  3186. Status: 1,
  3187. CreatedTime: time.Now().Unix(),
  3188. UpdatedTime: time.Now().Unix(),
  3189. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3190. }
  3191. //只针对广慈医院
  3192. 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 {
  3193. // 查询病人是否有透前评估数据
  3194. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3195. //如果有数据就插入
  3196. if errcode == nil {
  3197. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3198. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3199. record.BreathingRate = befor.BreathingRate
  3200. record.PulseFrequency = befor.PulseFrequency
  3201. record.Temperature = befor.Temperature
  3202. }
  3203. }
  3204. //孝昌
  3205. if adminUserInfo.Org.Id == 10693 {
  3206. // 查询病人是否有透前评估数据
  3207. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3208. //如果有数据就插入
  3209. if errcode == nil {
  3210. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3211. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3212. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3213. record.BreathingRate = befor.BreathingRate
  3214. }
  3215. }
  3216. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3217. if newdialysisRecord.ID > 0 {
  3218. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3219. record.Temperature = 36.5
  3220. record.ArterialPressure = -100
  3221. record.DialysateTemperature = 36.5
  3222. record.Conductivity = 14
  3223. record.BreathingRate = "20"
  3224. record.VenousPressure = 80
  3225. record.TransmembranePressure = 60
  3226. record.Dispose = catheter_operation
  3227. }
  3228. //针对新化博翔
  3229. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3230. record.BloodOxygenSaturation = "99"
  3231. record.Conductivity = 14
  3232. record.DialysateTemperature = 36.5
  3233. record.BreathingRate = "20"
  3234. }
  3235. //针对兰溪人民医院的需求
  3236. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3237. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3238. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3239. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3240. record.Temperature = befor.Temperature
  3241. record.PulseFrequency = befor.PulseFrequency
  3242. record.BreathingRate = befor.BreathingRate
  3243. }
  3244. //针对乐山友谊医院的需求
  3245. if adminUserInfo.Org.Id == 10677 {
  3246. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3247. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3248. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3249. record.Temperature = befor.Temperature
  3250. record.PulseFrequency = befor.PulseFrequency
  3251. record.BreathingRate = befor.BreathingRate
  3252. }
  3253. //新化博翔
  3254. if adminUserInfo.Org.Id == 10447 {
  3255. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3256. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3257. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3258. record.BreathingRate = befor.BreathingRate
  3259. }
  3260. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3261. record.PulseFrequency = 80
  3262. record.Temperature = 36.5
  3263. }
  3264. //诊断灵山圣康
  3265. if adminUserInfo.Org.Id == 10375 {
  3266. record.Conductivity = 13.8
  3267. record.DialysateTemperature = 37
  3268. record.DialysateFlow = 500
  3269. record.BloodFlowVolume = 200
  3270. record.BreathingRate = "18"
  3271. record.SodiumConcentration = 140
  3272. }
  3273. //江成肾病医院
  3274. if adminUserInfo.Org.Id == 10517 {
  3275. record.SodiumConcentration = 138
  3276. record.DialysateTemperature = 36.5
  3277. }
  3278. if adminUserInfo.Org.Id != 10683 {
  3279. err = service.CreateMonitor(&record)
  3280. }
  3281. //记录日志
  3282. byterequest, _ := json.Marshal(record)
  3283. monitorRecordLog := models.XtMonitorRecordLog{
  3284. RecordDate: record.MonitoringDate,
  3285. PatientId: record.PatientId,
  3286. Module: 1,
  3287. AdminUserId: adminUserInfo.AdminUser.Id,
  3288. Ctime: time.Now().Unix(),
  3289. Mtime: 0,
  3290. Status: 1,
  3291. UserOrgId: record.UserOrgId,
  3292. ErrLog: string(byterequest),
  3293. Source: "执行上机时新增监测",
  3294. }
  3295. service.CreateMonitorRecordLog(monitorRecordLog)
  3296. finish := models.XtDialysisFinish{
  3297. IsFinish: 1,
  3298. UserOrgId: adminUserInfo.Org.Id,
  3299. Status: 1,
  3300. Ctime: time.Now().Unix(),
  3301. Mtime: 0,
  3302. Module: 7,
  3303. RecordDate: schedulestartTime,
  3304. Sourse: 1,
  3305. PatientId: patientID,
  3306. }
  3307. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3308. if dialysisFinish.ID == 0 {
  3309. service.CreateDialysisFinish(finish)
  3310. }
  3311. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3312. redis := service.RedisClient()
  3313. //清空key 值
  3314. redis.Set(key, "", time.Second)
  3315. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3316. redis.Set(keyOne, "", time.Second)
  3317. defer redis.Close()
  3318. if err != nil {
  3319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3320. return
  3321. }
  3322. }
  3323. go func() {
  3324. ssoDomain := beego.AppConfig.String("call_domain")
  3325. api := ssoDomain + "/index/uppatient"
  3326. values := make(url.Values)
  3327. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3328. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3329. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3330. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3331. http.PostForm(api, values)
  3332. }()
  3333. this.ServeSuccessJSON(map[string]interface{}{
  3334. "dialysis_order": newdialysisRecord,
  3335. "monitor": record,
  3336. })
  3337. return
  3338. }
  3339. func (c *DialysisAPIController) PostSolution() {
  3340. id, _ := c.GetInt64("patient", 0)
  3341. recordDateStr := c.GetString("record_date")
  3342. if id <= 0 {
  3343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3344. return
  3345. }
  3346. adminUserInfo := c.GetMobileAdminUserInfo()
  3347. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3348. if patient.ID == 0 {
  3349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3350. return
  3351. }
  3352. if len(recordDateStr) == 0 {
  3353. recordDateStr = time.Now().Format("2006-01-02")
  3354. }
  3355. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3356. if parseDateErr != nil {
  3357. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3359. return
  3360. }
  3361. mode_id, _ := c.GetInt64("mode_id", 0)
  3362. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3363. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3364. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3365. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3366. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3367. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3368. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3369. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3370. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3371. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3372. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3373. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3374. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3375. kalium, _ := c.GetFloat("kalium", 0)
  3376. sodium, _ := c.GetFloat("sodium", 0)
  3377. calcium, _ := c.GetFloat("calcium", 0)
  3378. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3379. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3380. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3381. glucose, _ := c.GetFloat("glucose", 0)
  3382. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3383. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3384. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3385. conductivity, _ := c.GetFloat("conductivity", 0)
  3386. remark := c.GetString("remark")
  3387. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3388. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3389. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3390. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3391. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3392. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3393. special_medicine_other := c.GetString("special_medicine_other")
  3394. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3395. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3396. blood_access, _ := c.GetInt64("blood_access", 0)
  3397. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3398. body_fluid_other := c.GetString("body_fluid_other")
  3399. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3400. niprocart, _ := c.GetInt64("niprocart", 0)
  3401. jms, _ := c.GetInt64("jms", 0)
  3402. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3403. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3404. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3405. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3406. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3407. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3408. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3409. injector, _ := c.GetInt64("injector", 0)
  3410. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3411. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3412. safe_package, _ := c.GetInt64("package", 0)
  3413. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3414. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3415. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3416. blood := c.GetString("blood")
  3417. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3418. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3419. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3420. displace_speed := c.GetString("displace_speed")
  3421. illness, _ := c.GetInt64("illness")
  3422. amylaceum := c.GetString("amylaceum")
  3423. single_time := c.GetString("single_time")
  3424. single_water := c.GetString("single_water")
  3425. replacement_flow := c.GetString("replacement_flow")
  3426. plasma_separator := c.GetString("plasma_separator")
  3427. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3428. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3429. oxygen_flow := c.GetString("oxygen_flow")
  3430. oxygen_time := c.GetString("oxygen_time")
  3431. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3432. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3433. puncture_needle := c.GetString("puncture_needle")
  3434. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3435. epo := c.GetString("epo")
  3436. epo_count, _ := c.GetFloat("epo_count", 0)
  3437. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3438. pre_impulse := c.GetString("pre_impulse")
  3439. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3440. admin_user_id, _ := c.GetInt64("admin_user_id")
  3441. is_water := c.GetString("is_water")
  3442. add_amount, _ := c.GetFloat("add_amount")
  3443. reduce_amount, _ := c.GetFloat("reduce_amount")
  3444. prescribing_number, _ := c.GetFloat("prescribing_number")
  3445. treatment_remark := c.GetString("treatment_remark")
  3446. prescription_sodium := c.GetString("prescription_sodium")
  3447. start_sodium := c.GetString("start_sodium")
  3448. sodium_curve := c.GetString("sodium_curve")
  3449. var is_war int64
  3450. if is_water == "是" {
  3451. is_war = 1
  3452. }
  3453. if is_water == "否" {
  3454. is_war = 2
  3455. }
  3456. if is_water == "请选择" {
  3457. is_war = 0
  3458. }
  3459. drhy_water := c.GetString("drhy_water")
  3460. dry_water_hour := c.GetString("dry_water_hour")
  3461. water_machine := c.GetString("water_machine")
  3462. dialysis_remark := c.GetString("dialysis_remark")
  3463. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3464. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3465. prescription_water, _ := c.GetFloat("prescription_water")
  3466. dialysis_strainer := c.GetString("dialysis_strainer")
  3467. chaptalization := c.GetString("chaptalization")
  3468. washing_time := c.GetString("washing_time")
  3469. warsh_count := c.GetString("warsh_count")
  3470. blood_access_part_id := c.GetString("blood_access_part_id")
  3471. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3472. dialyzate := c.GetString("dialyzate")
  3473. if mode_id > 0 {
  3474. var str string
  3475. //查找该机构用的是什么透析器
  3476. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3477. if filedConfig.ID > 0 {
  3478. str = dialyzerPerfusionApparatus
  3479. } else {
  3480. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3481. }
  3482. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3483. }
  3484. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3485. //
  3486. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3487. // if appRole.UserType == 3 {
  3488. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3489. // if getPermissionErr != nil {
  3490. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3491. // return
  3492. // } else if headNursePermission == nil {
  3493. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3494. // return
  3495. // }
  3496. // }
  3497. //}
  3498. // 查询信息规挡的设置天数
  3499. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3500. if infor.ID > 0 && infor.WeekDay > 0 {
  3501. var cha_time int64
  3502. timeNowStr := time.Now().Format("2006-01-02")
  3503. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3504. //今日的日期减去设置的日期
  3505. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3506. if cha_time >= recordDate.Unix() {
  3507. //查询审核是否允许
  3508. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3509. //申请状态不允许的情况 拒绝修改
  3510. if infor.ApplicationStatus != 1 {
  3511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3512. return
  3513. }
  3514. }
  3515. }
  3516. prescription := models.DialysisPrescription{
  3517. UserOrgId: adminUserInfo.Org.Id,
  3518. PatientId: id,
  3519. RecordDate: recordDate.Unix(),
  3520. ModeId: mode_id,
  3521. DialysisDuration: dialysis_duration,
  3522. Dialyzer: dialyzer,
  3523. PerfusionApparatus: perfusion_apparatus,
  3524. BloodFlowVolume: blood_flow_volume,
  3525. DewaterAmount: dewater_amount,
  3526. DisplaceLiqui: displace_liqui,
  3527. ReplacementWay: replacement_way,
  3528. Anticoagulant: anticoagulant,
  3529. AnticoagulantShouji: anticoagulant_shouji,
  3530. AnticoagulantWeichi: anticoagulant_weichi,
  3531. AnticoagulantZongliang: anticoagulant_zongliang,
  3532. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3533. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3534. Kalium: kalium,
  3535. Sodium: sodium,
  3536. Calcium: calcium,
  3537. Bicarbonate: bicarbonate,
  3538. Glucose: glucose,
  3539. // DryWeight: dry_weight,
  3540. DialysateFlow: dialysate_flow,
  3541. DialysateTemperature: dialysate_temperature,
  3542. Conductivity: conductivity,
  3543. Remark: remark,
  3544. Status: 1,
  3545. CreatedTime: time.Now().Unix(),
  3546. UpdatedTime: time.Now().Unix(),
  3547. DialysisDurationMinute: dialysisDurationMinute,
  3548. DialysisDurationHour: dialysisDurationHour,
  3549. TargetUltrafiltration: targetUltrafiltration,
  3550. DialysateFormulation: dialysateFormulation,
  3551. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3552. BodyFluid: body_fluid,
  3553. SpecialMedicine: special_medicine,
  3554. SpecialMedicineOther: special_medicine_other,
  3555. DisplaceLiquiPart: displace_liqui_part,
  3556. DisplaceLiquiValue: displace_liqui_value,
  3557. BloodAccess: blood_access,
  3558. Ultrafiltration: ultrafiltration,
  3559. BodyFluidOther: body_fluid_other,
  3560. ReplacementTotal: replacement_total,
  3561. Niprocart: niprocart,
  3562. Jms: jms,
  3563. FistulaNeedleSet: fistula_needle_set,
  3564. FistulaNeedleSet16: fistula_needle_set_16,
  3565. Hemoperfusion: hemoperfusion,
  3566. DialyserSterilised: dialyser_sterilised,
  3567. Filtryzer: filtryzer,
  3568. TargetKtv: target_ktv,
  3569. Dialyzers: dialyzers,
  3570. Injector: injector,
  3571. Bloodlines: bloodlines,
  3572. TubingHemodialysis: tubing_hemodialysis,
  3573. Package: safe_package,
  3574. ALiquid: a_liquid,
  3575. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3576. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3577. Blood: blood,
  3578. DialysisDialyszers: dialysis_dialyszers,
  3579. DialysisIrrigation: dialysis_irrigation,
  3580. AntioxidantCommodityName: antioxidant_commodity_name,
  3581. DisplaceSpeed: displace_speed,
  3582. Illness: illness,
  3583. Amylaceum: amylaceum,
  3584. SingleWater: single_water,
  3585. SingleTime: single_time,
  3586. ReplacementFlow: replacement_flow,
  3587. PlasmaSeparator: plasma_separator,
  3588. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3589. OxygenUptake: oxygen_uptake,
  3590. OxygenTime: oxygen_time,
  3591. OxygenFlow: oxygen_flow,
  3592. HemodialysisPipelines: hemodialysis_pipelines,
  3593. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3594. PunctureNeedle: puncture_needle,
  3595. PunctureNeedleCount: puncture_needle_count,
  3596. Epo: epo,
  3597. EpoCount: epo_count,
  3598. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3599. PreImpulse: impulse,
  3600. AdminUserId: admin_user_id,
  3601. IsWater: is_war,
  3602. DrhyWater: drhy_water,
  3603. DryWaterHour: dry_water_hour,
  3604. WaterMachine: water_machine,
  3605. AddAmount: add_amount,
  3606. ReduceAmount: reduce_amount,
  3607. DialysisRemark: dialysis_remark,
  3608. PrescribingNumber: prescribing_number,
  3609. PrescriptionSodium: prescription_sodium,
  3610. StartSodium: start_sodium,
  3611. SodiumCurve: sodium_curve,
  3612. TreatmentRemark: treatment_remark,
  3613. DialysisFluidFlow: dialysis_fluid_flow,
  3614. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3615. PrescriptionWater: prescription_water,
  3616. DialysisStrainer: dialysis_strainer,
  3617. Chaptalization: chaptalization,
  3618. WashingTime: washing_time,
  3619. WarshCount: warsh_count,
  3620. BloodAccessPartId: blood_access_part_id,
  3621. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3622. Dialyzate: dialyzate,
  3623. }
  3624. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3625. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3626. //
  3627. if appRole.UserType == 2 || appRole.UserType == 1 {
  3628. prescription_doctor = adminUserInfo.AdminUser.Id
  3629. prescription.PrescriptionDoctor = prescription_doctor
  3630. }
  3631. if dialysisPrescription.ID == 0 { //新增
  3632. prescription.Creater = adminUserInfo.AdminUser.Id
  3633. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3634. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3635. }
  3636. } else { //修改
  3637. if dialysisPrescription.Creater == 0 {
  3638. prescription.Creater = adminUserInfo.AdminUser.Id
  3639. } else {
  3640. prescription.Creater = dialysisPrescription.Creater
  3641. if adminUserInfo.Org.Id == 9882 {
  3642. if appRole.UserType == 2 || appRole.UserType == 1 {
  3643. prescription.Creater = adminUserInfo.AdminUser.Id
  3644. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3645. }
  3646. }
  3647. }
  3648. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3649. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3650. }
  3651. //if/**/
  3652. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3653. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3654. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3655. // if getPermissionErr != nil {
  3656. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3657. // return
  3658. // } else if headNursePermission == nil {
  3659. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3660. // return
  3661. // }
  3662. //}
  3663. //prescription.Creater = dialysisPrescription.Creater
  3664. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3665. prescription.Modifier = adminUserInfo.AdminUser.Id
  3666. prescription.ID = dialysisPrescription.ID
  3667. }
  3668. solution := models.DialysisSolution{
  3669. RegistrarsId: adminUserInfo.AdminUser.Id,
  3670. UserOrgId: adminUserInfo.Org.Id,
  3671. Doctor: prescription_doctor,
  3672. PatientId: id,
  3673. ModeId: mode_id,
  3674. DialysisDuration: dialysis_duration,
  3675. PerfusionApparatus: perfusion_apparatus,
  3676. BloodFlowVolume: blood_flow_volume,
  3677. Dewater: dewater_amount,
  3678. DisplaceLiqui: displace_liqui,
  3679. ReplacementWay: replacement_way,
  3680. Anticoagulant: anticoagulant,
  3681. AnticoagulantShouji: anticoagulant_shouji,
  3682. AnticoagulantWeichi: anticoagulant_weichi,
  3683. AnticoagulantZongliang: anticoagulant_zongliang,
  3684. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3685. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3686. Kalium: kalium,
  3687. Sodium: sodium,
  3688. Calcium: calcium,
  3689. Bicarbonate: bicarbonate,
  3690. Glucose: glucose,
  3691. // DryWeight: dry_weight,
  3692. DialysateFlow: dialysate_flow,
  3693. DialysateTemperature: dialysate_temperature,
  3694. Conductivity: conductivity,
  3695. Remark: remark,
  3696. Status: 1,
  3697. CreatedTime: time.Now().Unix(),
  3698. UpdatedTime: time.Now().Unix(),
  3699. DialysisDurationMinute: dialysisDurationMinute,
  3700. DialysisDurationHour: dialysisDurationHour,
  3701. TargetUltrafiltration: targetUltrafiltration,
  3702. DialysateFormulation: dialysateFormulation,
  3703. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3704. BodyFluid: body_fluid,
  3705. SpecialMedicine: special_medicine,
  3706. SpecialMedicineOther: special_medicine_other,
  3707. DisplaceLiquiPart: displace_liqui_part,
  3708. DisplaceLiquiValue: displace_liqui_value,
  3709. BloodAccess: blood_access,
  3710. Ultrafiltration: ultrafiltration,
  3711. BodyFluidOther: body_fluid_other,
  3712. ReplacementTotal: replacement_total,
  3713. TargetKtv: target_ktv,
  3714. DialysisDialyszers: dialysis_dialyszers,
  3715. DialysisIrrigation: dialysis_irrigation,
  3716. HemodialysisPipelines: hemodialysis_pipelines,
  3717. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3718. PunctureNeedle: puncture_needle,
  3719. PunctureNeedleCount: puncture_needle_count,
  3720. Epo: epo,
  3721. EpoCount: epo_count,
  3722. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3723. PreImpulse: impulse,
  3724. SolutionStatus: 1,
  3725. DialysisRemark: dialysis_remark,
  3726. PrescribingNumber: prescribing_number,
  3727. PrescriptionSodium: prescription_sodium,
  3728. StartSodium: start_sodium,
  3729. SodiumCurve: sodium_curve,
  3730. TreatmentRemark: treatment_remark,
  3731. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3732. DialysisFluidFlow: dialysis_fluid_flow,
  3733. PrescriptionWater: prescription_water,
  3734. DialysisStrainer: dialysis_strainer,
  3735. Chaptalization: chaptalization,
  3736. WashingTime: washing_time,
  3737. WarshCount: warsh_count,
  3738. BloodAccessPartId: blood_access_part_id,
  3739. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3740. Dialyzate: dialyzate,
  3741. }
  3742. //针对河间咸的
  3743. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3744. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3745. solution.DisplaceLiquiPart = 0
  3746. solution.DisplaceLiquiValue = 0
  3747. }
  3748. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3749. prescription.DisplaceLiquiPart = 0
  3750. prescription.DisplaceLiquiValue = 0
  3751. }
  3752. }
  3753. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3754. if solution.PrescribingNumber == 0 {
  3755. solution.PrescribingNumber = 1
  3756. }
  3757. if prescription.PrescribingNumber == 0 {
  3758. prescription.PrescribingNumber = 1
  3759. }
  3760. if solution.PrescribingNumber == 0 && id == 14682 {
  3761. solution.PrescribingNumber = 2
  3762. }
  3763. if solution.PrescribingNumber == 0 && id == 18560 {
  3764. solution.PrescribingNumber = 2
  3765. }
  3766. if prescription.PrescribingNumber == 0 && id == 14682 {
  3767. prescription.PrescribingNumber = 2
  3768. }
  3769. if prescription.PrescribingNumber == 0 && id == 18560 {
  3770. prescription.PrescribingNumber = 2
  3771. }
  3772. }
  3773. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3774. //记录日志
  3775. byterequest, _ := json.Marshal(prescription)
  3776. prescriptionLog := models.XtDialysisPrescriptionLog{
  3777. UserOrgId: prescription.UserOrgId,
  3778. Ctime: time.Now().Unix(),
  3779. Mtime: 0,
  3780. ErrLog: string(byterequest),
  3781. AdminUserId: adminUserInfo.AdminUser.Id,
  3782. RecordDate: prescription.RecordDate,
  3783. PatientId: prescription.PatientId,
  3784. Source: "手机端新增长期处方",
  3785. Status: 1,
  3786. }
  3787. service.CreatePrescriptionLog(prescriptionLog)
  3788. finish := models.XtDialysisFinish{
  3789. IsFinish: 1,
  3790. UserOrgId: adminUserInfo.Org.Id,
  3791. Status: 1,
  3792. Ctime: time.Now().Unix(),
  3793. Mtime: 0,
  3794. Module: 1,
  3795. RecordDate: recordDate.Unix(),
  3796. Sourse: 1,
  3797. PatientId: id,
  3798. }
  3799. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3800. if dialysisFinish.ID == 0 {
  3801. service.CreateDialysisFinish(finish)
  3802. }
  3803. //获取最新1条
  3804. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3805. //更新状态
  3806. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3807. //长沙南雅医院,自动生成抗凝剂的临时处方
  3808. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3809. if prescribing_number == 0 {
  3810. prescribing_number = 1
  3811. }
  3812. advice := models.DoctorAdvice{
  3813. UserOrgId: adminUserInfo.Org.Id,
  3814. PatientId: id,
  3815. GroupNo: 0,
  3816. AdviceType: 2,
  3817. RecordDate: recordDate.Unix(),
  3818. AdviceDate: recordDate.Unix(),
  3819. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3820. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3821. AdviceDesc: "",
  3822. ReminderDate: 0,
  3823. SingleDose: prescription.AnticoagulantZongliang,
  3824. SingleDoseUnit: "iu",
  3825. DrugSpec: 0,
  3826. DrugSpecUnit: "",
  3827. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3828. PrescribingNumberUnit: "支",
  3829. DeliveryWay: "静脉注射",
  3830. ExecutionFrequency: "上机前",
  3831. AdviceDoctor: 0,
  3832. Status: 1,
  3833. CreatedTime: time.Now().Unix(),
  3834. UpdatedTime: time.Now().Unix(),
  3835. IsPrescription: 1,
  3836. ExecutionState: 2,
  3837. StopState: 2,
  3838. IsSettle: 2,
  3839. }
  3840. // 查询排班信息
  3841. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3842. if schedulePatient.ID > 0 {
  3843. if schedulePatient.ScheduleType == 1 {
  3844. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3845. }
  3846. if schedulePatient.ScheduleType == 2 {
  3847. advice.StartTime = recordDate.Unix() + 9*60*60
  3848. }
  3849. }
  3850. // 抗凝剂名称
  3851. switch anticoagulant {
  3852. case 1:
  3853. advice.AdviceName = "无肝素"
  3854. break
  3855. case 2:
  3856. advice.AdviceName = "普通肝素"
  3857. break
  3858. case 3:
  3859. advice.AdviceName = "低分子肝素"
  3860. break
  3861. case 4:
  3862. advice.AdviceName = "阿加曲班"
  3863. break
  3864. case 5:
  3865. advice.AdviceName = "枸橼酸钠"
  3866. break
  3867. case 6:
  3868. advice.AdviceName = "低分子肝素钙"
  3869. break
  3870. case 7:
  3871. advice.AdviceName = "低分子肝素钠"
  3872. break
  3873. case 8:
  3874. advice.AdviceName = "依诺肝素"
  3875. break
  3876. case 9:
  3877. advice.AdviceName = "达肝素"
  3878. break
  3879. case 10:
  3880. advice.AdviceName = "体外抗凝"
  3881. break
  3882. case 11:
  3883. advice.AdviceName = "那曲肝素"
  3884. break
  3885. case 12:
  3886. advice.AdviceName = "无抗凝剂"
  3887. break
  3888. }
  3889. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3890. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3891. advice.AdviceDoctor = appRole.AdminUserId
  3892. }
  3893. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3894. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3895. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3896. advice.AdviceName = "低分子肝素钠注射液"
  3897. // 修改患者临时医嘱里的抗凝剂医嘱
  3898. advice.ID = advicePrescription.ID
  3899. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3900. } else {
  3901. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3902. advice.AdviceName = "低分子肝素钠注射液"
  3903. service.CreateDoctorAdvice(&advice)
  3904. }
  3905. }
  3906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3907. redis := service.RedisClient()
  3908. defer redis.Close()
  3909. //清空key 值
  3910. redis.Set(key, "", time.Second)
  3911. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3912. redis.Set(keyOne, "", time.Second)
  3913. }
  3914. //获取key,清空redis
  3915. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3916. redis := service.RedisClient()
  3917. defer redis.Close()
  3918. //清空key 值
  3919. redis.Set(key, "", time.Second)
  3920. //清空长期医嘱的key
  3921. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3922. redis.Set(soulution_key, "", time.Second)
  3923. //查询最近透析准备表里是否存在 透析器 灌流器
  3924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3925. redis.Set(keyOne, "", time.Second)
  3926. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3927. redis.Set(keyTwo, "", time.Second)
  3928. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3929. redis.Set(keyThree, "", time.Second)
  3930. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3931. redis.Set(keyFour, "", time.Second)
  3932. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3933. //
  3934. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3935. //
  3936. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3937. //if len(mation)>0{
  3938. // for _, item := range splitStr {
  3939. // for _,it := range mation{
  3940. // if(item == it.SpecificationName){
  3941. //
  3942. // //查询最近一次的透析器
  3943. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3944. //
  3945. // if errcode == gorm.ErrRecordNotFound{
  3946. // //插入数据
  3947. // prepare := models.DialysisBeforePrepare{
  3948. // UserOrgId: adminUserInfo.Org.Id,
  3949. // PatientId: id,
  3950. // RecordDate: recordDate.Unix(),
  3951. // GoodTypeId: it.GoodTypeId,
  3952. // GoodId: it.ID,
  3953. // Count: 1,
  3954. // Ctime: time.Now().Unix(),
  3955. // Creater: adminUserInfo.AdminUser.Id,
  3956. // Status:1,
  3957. //
  3958. // }
  3959. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3960. // fmt.Println("",errcode)
  3961. // }
  3962. // }
  3963. // }
  3964. //
  3965. // }
  3966. //
  3967. // for _, item := range splitIrrigation {
  3968. // for _,it := range mation{
  3969. // if(item == it.SpecificationName){
  3970. // //查询最近一次的透析器
  3971. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3972. // if errcode == gorm.ErrRecordNotFound{
  3973. // //插入数据
  3974. // prepare := models.DialysisBeforePrepare{
  3975. // UserOrgId: adminUserInfo.Org.Id,
  3976. // PatientId: id,
  3977. // RecordDate: recordDate.Unix(),
  3978. // GoodTypeId: it.GoodTypeId,
  3979. // GoodId: it.ID,
  3980. // Count: 1,
  3981. // Ctime: time.Now().Unix(),
  3982. // Creater: adminUserInfo.AdminUser.Id,
  3983. // Status:1,
  3984. //
  3985. // }
  3986. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3987. // fmt.Println(errcode)
  3988. // }
  3989. // }
  3990. // }
  3991. // }
  3992. //}
  3993. c.ServeSuccessJSON(map[string]interface{}{
  3994. "solution": &solution,
  3995. "prescription": &prescription,
  3996. })
  3997. }
  3998. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3999. patient, _ := c.GetInt64("patient", 0)
  4000. adminUserInfo := c.GetMobileAdminUserInfo()
  4001. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4002. c.ServeSuccessJSON(map[string]interface{}{
  4003. "receiveTreatmentAsses": receiveTreatmentAsses,
  4004. })
  4005. }
  4006. func (this *DialysisAPIController) PostSignInfo() {
  4007. patientID, _ := this.GetInt64("patient_id")
  4008. recordDateStr := this.GetString("date")
  4009. if patientID <= 0 {
  4010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4011. return
  4012. }
  4013. if len(recordDateStr) == 0 {
  4014. recordDateStr = time.Now().Format("2006-01-02")
  4015. }
  4016. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4017. if parseDateErr != nil {
  4018. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4020. return
  4021. }
  4022. adminInfo := this.GetMobileAdminUserInfo()
  4023. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4024. if err != nil {
  4025. this.ErrorLog("签名失败:%v", err)
  4026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4027. return
  4028. }
  4029. this.ServeSuccessJSON(map[string]interface{}{
  4030. "doctor_id": adminInfo.AdminUser.Id,
  4031. })
  4032. }
  4033. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4034. patientID, _ := this.GetInt64("patient_id")
  4035. adminInfo := this.GetMobileAdminUserInfo()
  4036. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4037. this.ServeSuccessJSON(map[string]interface{}{
  4038. "monitor": record,
  4039. })
  4040. }
  4041. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4042. thisTime := time.Now()
  4043. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4044. timeLayout := "2006-01-02 15:04:05"
  4045. loc, _ := time.LoadLocation("Local")
  4046. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4047. theAssessmentDateTime := theStartTime.Unix()
  4048. patientID, _ := this.GetInt64("patient_id")
  4049. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4050. adminInfo := this.GetMobileAdminUserInfo()
  4051. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4052. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4053. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4054. var ultrafiltration_rate float64
  4055. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4056. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4057. fmt.Println(evaluation)
  4058. fmt.Println("prescription.ID", prescription.ID)
  4059. if prescription.ID > 0 {
  4060. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4062. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4063. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4064. record.UltrafiltrationRate = ultrafiltration_rate
  4065. }
  4066. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4067. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4068. record.UltrafiltrationRate = ultrafiltration_rate
  4069. }
  4070. if adminInfo.Org.Id == 10510 {
  4071. record.UltrafiltrationRate = 0
  4072. }
  4073. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4074. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4075. record.UltrafiltrationRate = ultrafiltration_rate
  4076. }
  4077. if template.TemplateId == 20 || template.TemplateId == 22 {
  4078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4079. record.UltrafiltrationRate = ultrafiltration_rate
  4080. }
  4081. // 只针对方济医院
  4082. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4083. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4084. ultrafiltration_rate = value
  4085. record.UltrafiltrationRate = ultrafiltration_rate
  4086. }
  4087. if template.TemplateId == 41 || template.TemplateId == 47 {
  4088. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4089. record.UltrafiltrationRate = ultrafiltration_rate
  4090. }
  4091. if template.TemplateId == 43 {
  4092. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4093. record.UltrafiltrationRate = ultrafiltration_rate
  4094. }
  4095. if template.TemplateId == 46 || template.TemplateId == 54 {
  4096. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4097. record.UltrafiltrationRate = ultrafiltration_rate
  4098. }
  4099. 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 {
  4100. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if adminInfo.Org.Id == 10469 {
  4104. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if adminInfo.Org.Id == 10667 {
  4108. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if adminInfo.Org.Id == 10471 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4113. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4114. }
  4115. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4116. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4117. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4118. }
  4119. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4120. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4121. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4122. }
  4123. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4124. record.UltrafiltrationRate = 0
  4125. }
  4126. //if template.TemplateId == 47 {
  4127. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4128. // record.UltrafiltrationRate = ultrafiltration_rate
  4129. //}
  4130. }
  4131. }
  4132. // record.UltrafiltrationRate = ultrafiltration_rate
  4133. record.UltrafiltrationVolume = 0
  4134. 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
  4135. if ultrafiltration_rate > 0 {
  4136. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4137. record.UltrafiltrationVolume = value
  4138. }
  4139. }
  4140. 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
  4141. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4142. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4143. record.UltrafiltrationVolume = ultrafiltration_volume
  4144. }
  4145. }
  4146. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4147. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4148. record.UltrafiltrationVolume = ultrafiltration_volume
  4149. }
  4150. //长沙南雅
  4151. 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 {
  4152. if ultrafiltration_rate > 0 {
  4153. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4154. record.UltrafiltrationVolume = ultrafiltration_volume
  4155. }
  4156. }
  4157. if adminInfo.Org.Id == 10471 {
  4158. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4159. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4160. }
  4161. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4162. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4163. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4164. }
  4165. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4166. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4167. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4168. }
  4169. //长沙南雅累计血容量自动计算
  4170. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4171. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4172. //}
  4173. if template.TemplateId == 47 || template.TemplateId == 54 {
  4174. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4175. }
  4176. if adminInfo.Org.Id == 10510 {
  4177. record.UltrafiltrationVolume = 0
  4178. }
  4179. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4180. this.ServeSuccessJSON(map[string]interface{}{
  4181. "monitor": record,
  4182. "lastMonitorRecordList": lastMonitorRecordList,
  4183. })
  4184. }
  4185. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4186. record_id, _ := this.GetInt64("id")
  4187. nurseID, _ := this.GetInt64("start_nurse")
  4188. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4189. bedID, _ := this.GetInt64("bed")
  4190. start_time := this.GetString("start_time")
  4191. schedual_type, _ := this.GetInt64("schedual_type")
  4192. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4193. change_nurse, _ := this.GetInt64("change_nurse")
  4194. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4195. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4196. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4197. patient_id, _ := this.GetInt64("patient_id")
  4198. record_date, _ := this.GetInt64("record_date")
  4199. puncture_needle := this.GetString("puncture_needle")
  4200. puncture_way := this.GetString("puncture_way")
  4201. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4202. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4203. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4204. nuclein_date_str := this.GetString("nuclein_date_str")
  4205. order_remark := this.GetString("order_remark")
  4206. schedule_remark := this.GetString("schedule_remark")
  4207. catheter_operation := this.GetString("catheter_operation")
  4208. blood_flow_volume := this.GetString("blood_flow_volume")
  4209. blood_drawing, _ := this.GetInt64("blood_drawing")
  4210. dialysis_strainer := this.GetString("dialysis_strainer")
  4211. if record_id == 0 {
  4212. this.ErrorLog("id:%v", record_id)
  4213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4214. return
  4215. }
  4216. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4217. if parseStartDateErr != nil {
  4218. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4220. return
  4221. }
  4222. adminUserInfo := this.GetMobileAdminUserInfo()
  4223. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4224. if getNurseErr != nil {
  4225. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4227. return
  4228. } else if nurse == nil {
  4229. this.ErrorLog("护士不存在")
  4230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. return
  4232. }
  4233. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4234. //if getNurseErr != nil {
  4235. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4236. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4237. // return
  4238. //} else if nurse == nil {
  4239. // this.ErrorLog("护士不存在")
  4240. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4241. // return
  4242. //}
  4243. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4244. if getDeviceNumberErr != nil {
  4245. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4247. return
  4248. } else if deviceNumber == nil {
  4249. this.ErrorLog("床位号不存在")
  4250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4251. return
  4252. }
  4253. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4254. //
  4255. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4256. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4257. // if getPermissionErr != nil {
  4258. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4259. // return
  4260. // } else if headNursePermission == nil {
  4261. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4262. // return
  4263. // }
  4264. //}
  4265. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4266. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4267. timeLayout := "2006-01-02 15:04:05"
  4268. loc, _ := time.LoadLocation("Local")
  4269. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4270. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4271. schedulestartTime := theStartTime.Unix()
  4272. scheduleendTime := theEndTime.Unix()
  4273. var theNucleinDate int64
  4274. timeLayoutOne := "2006-01-02"
  4275. if len(nuclein_date_str) > 0 {
  4276. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4277. if err != nil {
  4278. utils.ErrorLog(err.Error())
  4279. }
  4280. theNucleinDate = theTime.Unix()
  4281. }
  4282. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4283. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4284. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4285. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4286. if err == gorm.ErrRecordNotFound { //空床位
  4287. // 修改了床位逻辑
  4288. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4289. if daySchedule.ID > 0 {
  4290. //daySchedule.BedId = bedID
  4291. //daySchedule.PartitionId = deviceNumber.ZoneID
  4292. //daySchedule.ScheduleType = schedual_type
  4293. //daySchedule.UpdatedTime = time.Now().Unix()
  4294. //err := service.UpdateSchedule(&daySchedule)
  4295. xtSchedule := models.Schedule{
  4296. PartitionId: deviceNumber.ZoneID,
  4297. BedId: bedID,
  4298. ScheduleType: schedual_type,
  4299. UpdatedTime: time.Now().Unix(),
  4300. }
  4301. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4302. if err != nil {
  4303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4304. return
  4305. }
  4306. }
  4307. } else if err == nil {
  4308. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4309. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4310. if daySchedule.ID > 0 {
  4311. //daySchedule.BedId = bedID
  4312. //daySchedule.PartitionId = deviceNumber.ZoneID
  4313. //
  4314. //daySchedule.ScheduleType = schedual_type
  4315. //daySchedule.UpdatedTime = time.Now().Unix()
  4316. //err := service.UpdateSchedule(&daySchedule)
  4317. xtSchedule := models.Schedule{
  4318. PartitionId: deviceNumber.ZoneID,
  4319. BedId: bedID,
  4320. ScheduleType: schedual_type,
  4321. UpdatedTime: time.Now().Unix(),
  4322. }
  4323. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4324. if err != nil {
  4325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4326. return
  4327. }
  4328. }
  4329. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4331. return
  4332. }
  4333. } else if err != nil {
  4334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4335. return
  4336. }
  4337. }
  4338. dialysisRecord := &models.DialysisOrder{
  4339. ID: record_id,
  4340. UserOrgId: adminUserInfo.Org.Id,
  4341. BedID: bedID,
  4342. StartNurse: nurseID,
  4343. StartTime: startDate.Unix(),
  4344. PunctureNurse: puncture_nurse,
  4345. Creator: adminUserInfo.AdminUser.Id,
  4346. Modifier: adminUserInfo.AdminUser.Id,
  4347. WashpipeNurse: washpipe_nurse,
  4348. SchedualType: schedual_type,
  4349. ChangeNurse: change_nurse,
  4350. DifficultPunctureNurse: difficult_puncture_nurse,
  4351. NewFistulaNurse: new_fistula_nurse,
  4352. QualityNurseId: quality_nurse_id,
  4353. PunctureNeedle: puncture_needle,
  4354. PunctureWay: puncture_way,
  4355. DialysisDialyszers: dialysis_dialyszers,
  4356. DialysisIrrigation: dialysis_irrigation,
  4357. BloodAccessId: blood_access_id,
  4358. NucleinDate: theNucleinDate,
  4359. OrderRemark: order_remark,
  4360. ScheduleRemark: schedule_remark,
  4361. CatheterOperation: catheter_operation,
  4362. BloodFlowVolume: blood_flow_volume,
  4363. BloodDrawing: blood_drawing,
  4364. DialysisStrainer: dialysis_strainer,
  4365. }
  4366. //修改床位号需要重新消毒
  4367. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4368. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4369. //查询第一条监测
  4370. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4371. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4372. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4373. redis := service.RedisClient()
  4374. //清空key 值
  4375. redis.Set(key, "", time.Second)
  4376. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4377. redis.Set(keyOne, "", time.Second)
  4378. defer redis.Close()
  4379. }
  4380. // 查询信息规挡的设置天数
  4381. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4382. if infor.ID > 0 && infor.WeekDay > 0 {
  4383. var cha_time int64
  4384. timeNowStr := time.Now().Format("2006-01-02")
  4385. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4386. //今日的日期减去设置的日期
  4387. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4388. if cha_time >= record_date {
  4389. //查询审核是否允许
  4390. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4391. //申请状态不允许的情况 拒绝修改
  4392. if infor.ApplicationStatus != 1 {
  4393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4394. return
  4395. }
  4396. }
  4397. }
  4398. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4399. order, _ := service.GetLastPatientOrder(record_id)
  4400. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4401. redis := service.RedisClient()
  4402. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4403. redis.Set(key, "", time.Second)
  4404. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4405. //清空key 值
  4406. redis.Set(keyOne, "", time.Second)
  4407. scheduleDateStartOne := startDate.Format("2006-01-02")
  4408. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4409. redis.Set(keyTwo, "", time.Second)
  4410. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4411. redis.Set(keyThree, "", time.Second)
  4412. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4413. redis.Set(keyFour, "", time.Second)
  4414. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4415. redis.Set(keyFive, "", time.Second)
  4416. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4417. redis.Set(keySix, "", time.Second)
  4418. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4419. redis.Set(keySeven, "", time.Second)
  4420. if updateErr != nil {
  4421. this.ErrorLog("修改上机失败:%v", updateErr)
  4422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4423. return
  4424. }
  4425. if updateErr == nil {
  4426. if tempDialysisRecord.Stage == 2 {
  4427. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4428. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4429. fmt.Println(value)
  4430. a, b := math.Modf(value)
  4431. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4432. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4433. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4434. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4435. redis := service.RedisClient()
  4436. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4437. redis.Set(key, "", time.Second)
  4438. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4439. redis.Set(keyOne, "", time.Second)
  4440. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4441. //清空key 值
  4442. redis.Set(keySix, "", time.Second)
  4443. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4444. redis.Set(keySeven, "", time.Second)
  4445. redis.Close()
  4446. if updateAssessmentErr != nil {
  4447. utils.ErrorLog("%v", updateAssessmentErr)
  4448. }
  4449. }
  4450. }
  4451. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4452. this.ServeSuccessJSON(map[string]interface{}{
  4453. "dialysis_order": dialysisRecords,
  4454. })
  4455. }
  4456. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4457. record_id, _ := c.GetInt64("id")
  4458. nurseID, _ := c.GetInt64("nurse")
  4459. end_time := c.GetString("end_time")
  4460. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4461. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4462. catheter := c.GetString("catheter")
  4463. cruor := c.GetString("cruor")
  4464. mission := c.GetString("mission")
  4465. condenser := c.GetString("condenser")
  4466. if record_id <= 0 || nurseID <= 0 {
  4467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4468. return
  4469. }
  4470. adminUserInfo := c.GetMobileAdminUserInfo()
  4471. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4472. if getNurseErr != nil {
  4473. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4475. return
  4476. } else if nurse == nil {
  4477. c.ErrorLog("护士不存在")
  4478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4479. return
  4480. }
  4481. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4482. if parseEndDateErr != nil {
  4483. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4485. return
  4486. }
  4487. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4488. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4489. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4490. // if getPermissionErr != nil {
  4491. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4492. // return
  4493. // } else if headNursePermission == nil {
  4494. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4495. // return
  4496. // }
  4497. //}
  4498. // 查询信息规挡的设置天数
  4499. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4500. if infor.ID > 0 {
  4501. var cha_time int64
  4502. timeNowStr := time.Now().Format("2006-01-02")
  4503. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4504. //今日的日期减去设置的日期
  4505. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4506. if cha_time >= tempDialysisRecords.DialysisDate {
  4507. //查询审核是否允许
  4508. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4509. //申请状态不允许的情况 拒绝修改
  4510. if infor.ApplicationStatus != 1 {
  4511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4512. return
  4513. }
  4514. }
  4515. }
  4516. dialysisRecord := &models.DialysisOrder{
  4517. ID: record_id,
  4518. UserOrgId: adminUserInfo.Org.Id,
  4519. EndTime: endDate.Unix(),
  4520. FinishNurse: nurseID,
  4521. FinishModifier: adminUserInfo.AdminUser.Id,
  4522. PuncturePointHaematoma: puncture_point_haematoma,
  4523. BloodAccessInternalFistula: blood_access_internal_fistula,
  4524. Catheter: catheter,
  4525. Cruor: cruor,
  4526. Mission: mission,
  4527. Condenser: condenser,
  4528. }
  4529. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4530. redis := service.RedisClient()
  4531. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4532. //清空key 值
  4533. redis.Set(key, "", time.Second)
  4534. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4535. //清空key 值
  4536. redis.Set(keyOne, "", time.Second)
  4537. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4538. redis.Set(keySeven, "", time.Second)
  4539. redis.Close()
  4540. if updateErr != nil {
  4541. c.ErrorLog("修改下机失败:%v", updateErr)
  4542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4543. return
  4544. }
  4545. if updateErr == nil {
  4546. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4547. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4548. a, b := math.Modf(value)
  4549. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4550. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4551. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4552. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4553. redis := service.RedisClient()
  4554. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4555. redis.Set(keyTen, "", time.Second)
  4556. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4557. redis.Set(keyTwo, "", time.Second)
  4558. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4559. redis.Set(key, "", time.Second)
  4560. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4561. redis.Set(keyThree, "", time.Second)
  4562. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4563. redis.Set(keySeven, "", time.Second)
  4564. defer redis.Close()
  4565. if updateAssessmentErr != nil {
  4566. utils.ErrorLog("%v", updateAssessmentErr)
  4567. }
  4568. }
  4569. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4570. c.ServeSuccessJSON(map[string]interface{}{
  4571. "dialysis_order": dialysisRecords,
  4572. })
  4573. }
  4574. func (c *DialysisAPIController) GetLongAdvice() {
  4575. patient_id, _ := c.GetInt64("id")
  4576. adminUserInfo := c.GetMobileAdminUserInfo()
  4577. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4578. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4579. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4580. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4581. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4582. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4583. c.ServeSuccessJSON(map[string]interface{}{
  4584. "status": "1",
  4585. })
  4586. return
  4587. } else { //开启推送提醒
  4588. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4589. var advice_three []*models.DoctorAdvice
  4590. recordDateStr := time.Now().Format("2006-01-02")
  4591. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4592. nowtime := recordDate.Unix()
  4593. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4594. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4595. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4596. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4597. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4598. for _, advice := range advices {
  4599. if advice.FrequencyType == 3 {
  4600. t := time.Now()
  4601. week := int(t.Weekday())
  4602. fmt.Println(t.Weekday())
  4603. fmt.Println(week)
  4604. switch week {
  4605. case 1:
  4606. if strings.Index(advice.WeekDay, "周一") == -1 {
  4607. advice_three = append(advice_three, advice)
  4608. }
  4609. break
  4610. case 2:
  4611. if strings.Index(advice.WeekDay, "周二") == -1 {
  4612. advice_three = append(advice_three, advice)
  4613. }
  4614. break
  4615. case 3:
  4616. if strings.Index(advice.WeekDay, "周三") == -1 {
  4617. advice_three = append(advice_three, advice)
  4618. }
  4619. break
  4620. case 4:
  4621. if strings.Index(advice.WeekDay, "周四") == -1 {
  4622. advice_three = append(advice_three, advice)
  4623. }
  4624. break
  4625. case 5:
  4626. if strings.Index(advice.WeekDay, "周五") == -1 {
  4627. advice_three = append(advice_three, advice)
  4628. }
  4629. break
  4630. case 6:
  4631. if strings.Index(advice.WeekDay, "周六") == -1 {
  4632. advice_three = append(advice_three, advice)
  4633. }
  4634. break
  4635. case 0:
  4636. if strings.Index(advice.WeekDay, "周日") == -1 {
  4637. advice_three = append(advice_three, advice)
  4638. }
  4639. break
  4640. }
  4641. }
  4642. }
  4643. for _, advice := range advices_two {
  4644. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4645. now := p.Unix()
  4646. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4647. dayStr2 := "-" + dayStr
  4648. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4649. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4650. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4651. for _, ad := range advices {
  4652. advice_three = append(advice_three, ad)
  4653. }
  4654. }
  4655. if err == nil {
  4656. c.ServeSuccessJSON(map[string]interface{}{
  4657. "status": "2",
  4658. "advices": advices,
  4659. "advices_two": RemoveRepeatedElement(advice_three),
  4660. "is_open_remind": config.IsOpenRemind,
  4661. "his_config_open": hisConfig.IsOpen,
  4662. "is_advice_open": is_advice_open.IsAdviceOpen,
  4663. "prescription_open": prescription_open.IsOpen,
  4664. })
  4665. }
  4666. }
  4667. }
  4668. func (c *DialysisAPIController) GetLongAdviceOne() {
  4669. patient_id, _ := c.GetInt64("id")
  4670. startTime := c.GetString("schedule_date")
  4671. timeLayout := "2006-01-02"
  4672. loc, _ := time.LoadLocation("Local")
  4673. var theStartTime int64
  4674. if len(startTime) > 0 {
  4675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4676. if err != nil {
  4677. utils.ErrorLog(err.Error())
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4679. return
  4680. }
  4681. theStartTime = theTime.Unix()
  4682. }
  4683. adminUserInfo := c.GetMobileAdminUserInfo()
  4684. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4685. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4686. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4687. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4688. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4689. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4690. c.ServeSuccessJSON(map[string]interface{}{
  4691. "status": "1",
  4692. })
  4693. return
  4694. } else { //开启推送提醒
  4695. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4696. var advice_three []*models.DoctorAdvice
  4697. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4698. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4699. for _, advice := range advices {
  4700. if advice.FrequencyType == 3 {
  4701. t := time.Now()
  4702. week := int(t.Weekday())
  4703. fmt.Println(t.Weekday())
  4704. fmt.Println(week)
  4705. switch week {
  4706. case 1:
  4707. if strings.Index(advice.WeekDay, "周一") == -1 {
  4708. advice_three = append(advice_three, advice)
  4709. }
  4710. break
  4711. case 2:
  4712. if strings.Index(advice.WeekDay, "周二") == -1 {
  4713. advice_three = append(advice_three, advice)
  4714. }
  4715. break
  4716. case 3:
  4717. if strings.Index(advice.WeekDay, "周三") == -1 {
  4718. advice_three = append(advice_three, advice)
  4719. }
  4720. break
  4721. case 4:
  4722. if strings.Index(advice.WeekDay, "周四") == -1 {
  4723. advice_three = append(advice_three, advice)
  4724. }
  4725. break
  4726. case 5:
  4727. if strings.Index(advice.WeekDay, "周五") == -1 {
  4728. advice_three = append(advice_three, advice)
  4729. }
  4730. break
  4731. case 6:
  4732. if strings.Index(advice.WeekDay, "周六") == -1 {
  4733. advice_three = append(advice_three, advice)
  4734. }
  4735. break
  4736. case 0:
  4737. if strings.Index(advice.WeekDay, "周日") == -1 {
  4738. advice_three = append(advice_three, advice)
  4739. }
  4740. break
  4741. }
  4742. }
  4743. }
  4744. for _, advice := range advices_two {
  4745. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4746. now := p.Unix()
  4747. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4748. dayStr2 := "-" + dayStr
  4749. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4750. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4751. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4752. for _, ad := range advices {
  4753. advice_three = append(advice_three, ad)
  4754. }
  4755. }
  4756. if err == nil {
  4757. c.ServeSuccessJSON(map[string]interface{}{
  4758. "status": "2",
  4759. "advices": advices,
  4760. "advices_two": RemoveRepeatedElement(advice_three),
  4761. "is_open_remind": config.IsOpenRemind,
  4762. "his_config_open": hisConfig.IsOpen,
  4763. "is_advice_open": is_advice_open.IsAdviceOpen,
  4764. "prescription_open": prescription_open.IsOpen,
  4765. })
  4766. }
  4767. }
  4768. }
  4769. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4770. newArr = make([]*models.DoctorAdvice, 0)
  4771. for i := 0; i < len(arr); i++ {
  4772. repeat := false
  4773. for j := i + 1; j < len(arr); j++ {
  4774. if arr[i].ID == arr[j].ID {
  4775. repeat = true
  4776. break
  4777. }
  4778. }
  4779. if !repeat {
  4780. newArr = append(newArr, arr[i])
  4781. }
  4782. }
  4783. return
  4784. }
  4785. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4786. patient, _ := c.GetInt64("id", 0)
  4787. groupNo, _ := c.GetInt64("groupno", 0)
  4788. if patient <= 0 {
  4789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4790. return
  4791. }
  4792. adminUserInfo := c.GetMobileAdminUserInfo()
  4793. dataBody := make(map[string]interface{}, 0)
  4794. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4795. if err != nil {
  4796. utils.ErrorLog(err.Error())
  4797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4798. return
  4799. }
  4800. utils.ErrorLog("%v", dataBody)
  4801. timeLayout := "2006-01-02 15:04"
  4802. loc, _ := time.LoadLocation("Local")
  4803. timeLayout2 := "2006-01-02"
  4804. loc2, _ := time.LoadLocation("Local")
  4805. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4806. utils.ErrorLog("advice_type")
  4807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4808. return
  4809. }
  4810. adviceType := int64(2)
  4811. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4812. utils.ErrorLog("advice_date")
  4813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4814. return
  4815. }
  4816. adviceDate, _ := dataBody["advice_date"].(string)
  4817. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4818. AdviceDate := theTime.Unix()
  4819. RecordDate := theTime.Unix()
  4820. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4821. utils.ErrorLog("start_time")
  4822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4823. return
  4824. }
  4825. startTime, _ := dataBody["start_time"].(string)
  4826. if len(startTime) == 0 {
  4827. utils.ErrorLog("len(start_time) == 0")
  4828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4829. return
  4830. }
  4831. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4832. if err != nil {
  4833. utils.ErrorLog(err.Error())
  4834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4835. return
  4836. }
  4837. StartTime := theTime.Unix()
  4838. Remark := ""
  4839. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4840. remark, _ := dataBody["remark"].(string)
  4841. Remark = remark
  4842. }
  4843. var advices []*models.GroupAdvice
  4844. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4845. utils.ErrorLog("advices")
  4846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4847. return
  4848. }
  4849. adviceNames := dataBody["advices"].([]interface{})
  4850. for _, adviceNameMap := range adviceNames {
  4851. adviceNameM := adviceNameMap.(map[string]interface{})
  4852. var advice models.GroupAdvice
  4853. advice.Remark = Remark
  4854. advice.AdviceType = adviceType
  4855. advice.StartTime = StartTime
  4856. advice.AdviceDate = AdviceDate
  4857. advice.RecordDate = RecordDate
  4858. advice.Status = 1
  4859. advice.CreatedTime = time.Now().Unix()
  4860. advice.UpdatedTime = time.Now().Unix()
  4861. advice.StopState = 2
  4862. advice.ExecutionState = 2
  4863. advice.UserOrgId = adminUserInfo.Org.Id
  4864. advice.PatientId = patient
  4865. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4866. advice.IsSettle = 2
  4867. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4868. utils.ErrorLog("advice_name")
  4869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4870. return
  4871. }
  4872. adviceName, _ := adviceNameM["advice_name"].(string)
  4873. if len(adviceName) == 0 {
  4874. utils.ErrorLog("len(advice_name) == 0")
  4875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4876. return
  4877. }
  4878. advice.AdviceName = adviceName
  4879. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4880. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4881. advice.DrugSpec = drugSpec
  4882. }
  4883. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4884. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4885. advice.AdviceDesc = adviceDesc
  4886. }
  4887. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4888. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4889. advice.DrugSpecUnit = drugSpecUnit
  4890. }
  4891. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4892. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4893. // advice.SingleDose = singleDose
  4894. //}
  4895. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4896. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4897. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4898. }
  4899. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4900. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4901. advice.SingleDoseUnit = singleDoseUnit
  4902. }
  4903. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4904. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4905. // advice.PrescribingNumber = prescribingNumber
  4906. //}
  4907. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4908. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4909. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4910. }
  4911. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4912. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4913. advice.PrescribingNumberUnit = prescribingNumberUnit
  4914. }
  4915. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4916. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4917. advice.DeliveryWay = deliveryWay
  4918. }
  4919. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4920. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4921. advice.ExecutionFrequency = executionFrequency
  4922. }
  4923. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4924. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4925. advice.FrequencyType = frequency_type
  4926. }
  4927. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4928. day_count := int64(adviceNameM["day_count"].(float64))
  4929. advice.DayCount = day_count
  4930. }
  4931. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4932. week_day, _ := adviceNameM["week_day"].(string)
  4933. advice.WeekDay = week_day
  4934. }
  4935. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4936. way := int64(adviceNameM["way"].(float64))
  4937. advice.Way = way
  4938. }
  4939. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4940. drug_id := int64(adviceNameM["drug_id"].(float64))
  4941. advice.DrugId = drug_id
  4942. }
  4943. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4944. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4945. advice.DrugNameId = drug_name_id
  4946. }
  4947. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4948. remark, _ := adviceNameM["remark"].(string)
  4949. advice.Remark = remark
  4950. }
  4951. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4952. groupno := int64(adviceNameM["groupno"].(float64))
  4953. advice.GroupNo = groupno
  4954. }
  4955. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4956. template_id, _ := adviceNameM["template_id"].(string)
  4957. advice.TemplateId = template_id
  4958. }
  4959. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4960. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4961. advice.ExecutionFrequency = executionFrequency
  4962. }
  4963. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4964. children := adviceNameM["child"].([]interface{})
  4965. if len(children) > 0 {
  4966. for _, childrenMap := range children {
  4967. childMap := childrenMap.(map[string]interface{})
  4968. var child models.GroupAdvice
  4969. child.Remark = Remark
  4970. child.AdviceType = adviceType
  4971. child.StartTime = StartTime
  4972. child.AdviceDate = AdviceDate
  4973. child.RecordDate = RecordDate
  4974. child.Status = 1
  4975. child.CreatedTime = time.Now().Unix()
  4976. child.UpdatedTime = time.Now().Unix()
  4977. child.StopState = 2
  4978. child.ExecutionState = 2
  4979. child.UserOrgId = adminUserInfo.Org.Id
  4980. child.PatientId = patient
  4981. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4982. child.IsSettle = 1
  4983. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4984. utils.ErrorLog("child advice_name")
  4985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4986. return
  4987. }
  4988. childAdviceName, _ := childMap["advice_name"].(string)
  4989. if len(childAdviceName) == 0 {
  4990. utils.ErrorLog("len(child advice_name) == 0")
  4991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4992. return
  4993. }
  4994. child.AdviceName = childAdviceName
  4995. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4996. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4997. child.AdviceDesc = childAdviceDesc
  4998. }
  4999. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5000. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5001. child.DrugSpec = childDrugSpec
  5002. }
  5003. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5004. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5005. child.DrugSpecUnit = childDrugSpecUnit
  5006. }
  5007. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5008. child.SingleDose = childMap["single_dose"].(float64)
  5009. }
  5010. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5011. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5012. child.SingleDoseUnit = childSingleDoseUnit
  5013. }
  5014. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5015. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5016. }
  5017. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5018. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5019. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5020. }
  5021. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5022. groupno := int64(childMap["groupno"].(float64))
  5023. advice.GroupNo = groupno
  5024. }
  5025. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5026. remark, _ := childMap["remark"].(string)
  5027. child.Remark = remark
  5028. }
  5029. child.DeliveryWay = advice.DeliveryWay
  5030. child.ExecutionFrequency = advice.ExecutionFrequency
  5031. advice.Children = append(advice.Children, &child)
  5032. }
  5033. }
  5034. }
  5035. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5036. if temp_advice.ID == 0 {
  5037. advices = append(advices, &advice)
  5038. }
  5039. }
  5040. if len(advices) > 0 {
  5041. finish := models.XtDialysisFinish{
  5042. IsFinish: 1,
  5043. UserOrgId: adminUserInfo.Org.Id,
  5044. Status: 1,
  5045. Ctime: time.Now().Unix(),
  5046. Mtime: 0,
  5047. Module: 4,
  5048. RecordDate: AdviceDate,
  5049. Sourse: 1,
  5050. PatientId: patient,
  5051. }
  5052. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5053. if dialysisFinish.ID == 0 {
  5054. service.CreateDialysisFinish(finish)
  5055. }
  5056. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5057. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5058. for _, item := range advices {
  5059. byterequest, _ := json.Marshal(item)
  5060. adviceLog := models.XtDoctorAdviceLog{
  5061. UserOrgId: adminUserInfo.Org.Id,
  5062. PatientId: patient,
  5063. AdminUserId: adminUserInfo.AdminUser.Id,
  5064. Module: 1,
  5065. ErrLog: string(byterequest),
  5066. Status: 1,
  5067. Ctime: time.Now().Unix(),
  5068. Mtime: 0,
  5069. Source: "手机端医嘱推送",
  5070. RecordDate: item.AdviceDate,
  5071. }
  5072. service.CreateDoctorAdviceLog(adviceLog)
  5073. }
  5074. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5075. redis := service.RedisClient()
  5076. //清空key 值
  5077. redis.Set(key, "", time.Second)
  5078. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5079. redis.Set(keyOne, "", time.Second)
  5080. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5081. defer redis.Close()
  5082. redis.Set(keyThree, "", time.Second)
  5083. if err != nil {
  5084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5085. return
  5086. }
  5087. c.ServeSuccessJSON(map[string]interface{}{
  5088. "msg": "ok",
  5089. "advices": list,
  5090. })
  5091. } else {
  5092. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5093. for _, item := range advices {
  5094. byterequest, _ := json.Marshal(item)
  5095. adviceLog := models.XtDoctorAdviceLog{
  5096. UserOrgId: adminUserInfo.Org.Id,
  5097. PatientId: patient,
  5098. AdminUserId: adminUserInfo.AdminUser.Id,
  5099. Module: 1,
  5100. ErrLog: string(byterequest),
  5101. Status: 1,
  5102. Ctime: time.Now().Unix(),
  5103. Mtime: 0,
  5104. Source: "手机端医嘱推送",
  5105. RecordDate: item.AdviceDate,
  5106. }
  5107. service.CreateDoctorAdviceLog(adviceLog)
  5108. }
  5109. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5110. redis := service.RedisClient()
  5111. //清空key 值
  5112. redis.Set(key, "", time.Second)
  5113. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5114. redis.Set(keyOne, "", time.Second)
  5115. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5116. defer redis.Close()
  5117. redis.Set(keyThree, "", time.Second)
  5118. if err != nil {
  5119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5120. return
  5121. }
  5122. c.ServeSuccessJSON(map[string]interface{}{
  5123. "msg": "ok",
  5124. "advices": list,
  5125. })
  5126. }
  5127. } else {
  5128. c.ServeSuccessJSON(map[string]interface{}{
  5129. "msg": "ok",
  5130. })
  5131. }
  5132. return
  5133. }
  5134. func (c *DialysisAPIController) UploadDryWeight() {
  5135. patient_id, _ := c.GetInt64("id")
  5136. dry_weight, _ := c.GetFloat("dry_weight")
  5137. doctor_id, _ := c.GetInt64("doctor_id")
  5138. remark := c.GetString("remark")
  5139. adminUserInfo := c.GetMobileAdminUserInfo()
  5140. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5141. if err == gorm.ErrRecordNotFound {
  5142. dryWeight := &models.SgjPatientDryweight{
  5143. PatientId: patient_id,
  5144. DryWeight: dry_weight,
  5145. Remakes: remark,
  5146. Ctime: time.Now().Unix(),
  5147. Mtime: time.Now().Unix(),
  5148. Creator: doctor_id,
  5149. Status: 1,
  5150. UserOrgId: adminUserInfo.Org.Id,
  5151. AdjustedValue: "/",
  5152. UserId: adminUserInfo.AdminUser.Id,
  5153. }
  5154. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5155. redis := service.RedisClient()
  5156. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5157. redis.Set(keyOne, "", time.Second)
  5158. loc, _ := time.LoadLocation("Local")
  5159. nowTime := time.Now()
  5160. nowDay := nowTime.Format("2006-01-02")
  5161. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5162. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5163. redis.Set(key, "", time.Second)
  5164. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5165. redis.Set(keyTwo, "", time.Second)
  5166. redis.Close()
  5167. if createErr == nil {
  5168. c.ServeSuccessJSON(map[string]interface{}{
  5169. "msg": "提交成功",
  5170. "weight": dryWeight,
  5171. })
  5172. }
  5173. } else {
  5174. dryWeight := &models.SgjPatientDryweight{
  5175. PatientId: patient_id,
  5176. DryWeight: dry_weight,
  5177. Remakes: remark,
  5178. Ctime: time.Now().Unix(),
  5179. Mtime: time.Now().Unix(),
  5180. Creator: doctor_id,
  5181. Status: 1,
  5182. UserOrgId: adminUserInfo.Org.Id,
  5183. AdjustedValue: "/",
  5184. UserId: adminUserInfo.AdminUser.Id,
  5185. }
  5186. var value float64
  5187. value = dry_weight - weightAdjust.DryWeight
  5188. if value < 0 {
  5189. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5190. } else if value == 0 {
  5191. dryWeight.AdjustedValue = "/"
  5192. } else if value > 0 {
  5193. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5194. }
  5195. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5196. redis := service.RedisClient()
  5197. loc, _ := time.LoadLocation("Local")
  5198. nowTime := time.Now()
  5199. nowDay := nowTime.Format("2006-01-02")
  5200. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5201. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5202. redis.Set(keyOne, "", time.Second)
  5203. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5204. redis.Set(key, "", time.Second)
  5205. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5206. redis.Set(keyTwo, "", time.Second)
  5207. redis.Close()
  5208. if createErr == nil {
  5209. c.ServeSuccessJSON(map[string]interface{}{
  5210. "msg": "提交成功",
  5211. "weight": dryWeight,
  5212. })
  5213. }
  5214. }
  5215. }
  5216. func (c *DialysisAPIController) GetSolution() {
  5217. patient_id, _ := c.GetInt64("patient_id")
  5218. mode_id, _ := c.GetInt64("mode_id")
  5219. adminUserInfo := c.GetMobileAdminUserInfo()
  5220. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5221. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5222. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5223. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5224. if err != nil {
  5225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5226. return
  5227. }
  5228. c.ServeSuccessJSON(map[string]interface{}{
  5229. "solution": solution,
  5230. "prescription": prescription,
  5231. "system_prescription": system_prescription,
  5232. "dialysisPrescription": dialysisPrescription,
  5233. })
  5234. }
  5235. func (c *DialysisAPIController) GetSchedule() {
  5236. schedual_type, _ := c.GetInt64("schedual_type")
  5237. adminUserInfo := c.GetMobileAdminUserInfo()
  5238. scheduleTime, _ := c.GetInt64("record_date")
  5239. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5240. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5241. c.ServeSuccessJSON(map[string]interface{}{
  5242. "number": deviceNumber,
  5243. "list": list,
  5244. })
  5245. }
  5246. func (c *DialysisAPIController) GetPatientId() {
  5247. id, _ := c.GetInt64("id")
  5248. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5249. patientId, _ := service.GetPatientId(id)
  5250. //获取该患者的所有传染病
  5251. list, _ := service.GetPatientInfectious(id)
  5252. c.ServeSuccessJSON(map[string]interface{}{
  5253. "patient": patientId,
  5254. "infectioulist": list,
  5255. })
  5256. }
  5257. func (this *DialysisAPIController) GetDialysisSchedule() {
  5258. schedualDate := this.GetString("date")
  5259. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5260. if parseDateErr != nil {
  5261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5262. return
  5263. }
  5264. adminInfo := this.GetMobileAdminUserInfo()
  5265. orgID := adminInfo.Org.Id
  5266. redis := service.RedisClient()
  5267. defer redis.Close()
  5268. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5269. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5270. if len(scheduals) > 0 {
  5271. //缓存数据
  5272. scheduals_json, err := json.Marshal(scheduals)
  5273. if err == nil {
  5274. redis.Set(key, scheduals_json, time.Second*30)
  5275. }
  5276. }
  5277. this.ServeSuccessJSON(map[string]interface{}{
  5278. "scheduals": scheduals,
  5279. })
  5280. }
  5281. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5282. change_type, _ := this.GetInt64("type", 0)
  5283. record_date := this.GetString("record_time")
  5284. patient_id, _ := this.GetInt64("patient_id", 0)
  5285. timeLayout := "2006-01-02"
  5286. loc, _ := time.LoadLocation("Local")
  5287. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5288. record_time := theAdviceRecordTime.Unix()
  5289. adminUserInfo := this.GetMobileAdminUserInfo()
  5290. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5291. if err == nil {
  5292. if len(advices) == 0 {
  5293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5294. return
  5295. } else {
  5296. this.ServeSuccessJSON(map[string]interface{}{
  5297. "advices": advices,
  5298. "schedule": sch,
  5299. })
  5300. return
  5301. }
  5302. } else {
  5303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5304. return
  5305. }
  5306. }
  5307. func (c *DialysisAPIController) CreateConsumables() {
  5308. record_date := c.GetString("record_time")
  5309. patient_id, _ := c.GetInt64("patient_id", 0)
  5310. active, _ := c.GetInt64("active")
  5311. adminUser := c.GetMobileAdminUserInfo()
  5312. timeLayout := "2006-01-02"
  5313. loc, _ := time.LoadLocation("Local")
  5314. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5315. record_time := theRecordTime.Unix()
  5316. // 查询信息规挡的设置天数
  5317. orgid := c.GetMobileAdminUserInfo().Org.Id
  5318. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5319. if infor.ID > 0 {
  5320. var cha_time int64
  5321. timeNowStr := time.Now().Format("2006-01-02")
  5322. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5323. //今日的日期减去设置的日期
  5324. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5325. if cha_time >= record_time {
  5326. //查询审核是否允许
  5327. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5328. //申请状态不允许的情况 拒绝修改
  5329. if infor.ApplicationStatus != 1 {
  5330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5331. return
  5332. }
  5333. }
  5334. }
  5335. dataBody := make(map[string]interface{}, 0)
  5336. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5337. if err != nil {
  5338. utils.ErrorLog(err.Error())
  5339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5340. return
  5341. }
  5342. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5343. var beforePrepares []*models.DialysisBeforePrepareGoods
  5344. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5345. var dialysisBefor []*models.DialysisBeforePrepare
  5346. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5347. goods, _ := dataBody["goods"].([]interface{})
  5348. if len(goods) > 0 {
  5349. for _, item := range goods {
  5350. items := item.(map[string]interface{})
  5351. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5352. utils.ErrorLog("good_id")
  5353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5354. return
  5355. }
  5356. good_id := int64(items["good_id"].(float64))
  5357. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5358. utils.ErrorLog("good_type_id")
  5359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5360. return
  5361. }
  5362. good_type_id := int64(items["good_type_id"].(float64))
  5363. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5364. utils.ErrorLog("count")
  5365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5366. return
  5367. }
  5368. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5369. commdity_code := items["commdity_code"].(string)
  5370. fmt.Println("commdity", commdity_code)
  5371. prepareGoods := &models.DialysisBeforePrepareGoods{
  5372. GoodTypeId: good_type_id,
  5373. GoodId: good_id,
  5374. Count: count,
  5375. StorehouseId: houseConfig.StorehouseOutInfo,
  5376. PatientId: patient_id,
  5377. }
  5378. beforePrepares = append(beforePrepares, prepareGoods)
  5379. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5380. GoodTypeId: good_type_id,
  5381. GoodId: good_id,
  5382. Count: count,
  5383. StorehouseId: houseConfig.StorehouseOutInfo,
  5384. PatientId: patient_id,
  5385. }
  5386. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5387. prepare := &models.DialysisBeforePrepare{
  5388. GoodTypeId: good_type_id,
  5389. GoodId: good_id,
  5390. Count: count,
  5391. PatientId: patient_id,
  5392. RecordDate: record_time,
  5393. UserOrgId: adminUser.Org.Id,
  5394. Status: 1,
  5395. Ctime: time.Now().Unix(),
  5396. Creater: adminUser.AdminUser.Id,
  5397. CommdityCode: commdity_code,
  5398. StorehouseId: houseConfig.StorehouseOutInfo,
  5399. }
  5400. dialysisBefor = append(dialysisBefor, prepare)
  5401. }
  5402. }
  5403. //查询是否有库存
  5404. for _, item := range dialysisBefor {
  5405. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5406. if err == gorm.ErrRecordNotFound {
  5407. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5408. c.ServeSuccessJSON(map[string]interface{}{
  5409. "message": "1",
  5410. "good_name": goodObj.GoodName,
  5411. "specification_name": goodObj.SpecificationName,
  5412. })
  5413. return
  5414. }
  5415. if err != nil {
  5416. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5417. c.ServeSuccessJSON(map[string]interface{}{
  5418. "message": "1",
  5419. "good_name": goodObj.GoodName,
  5420. "specification_name": goodObj.SpecificationName,
  5421. })
  5422. return
  5423. }
  5424. }
  5425. //新增
  5426. if active == 1 && len(goods) > 0 {
  5427. db := service.XTWriteDB()
  5428. tx := db.Begin()
  5429. // 在函数结束时处理事务回滚
  5430. defer func() {
  5431. if r := recover(); r != nil {
  5432. tx.Rollback()
  5433. } else {
  5434. tx.Commit()
  5435. }
  5436. }()
  5437. for _, item := range newBeforePrepares {
  5438. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5439. adminInfo := c.GetMobileAdminUserInfo()
  5440. var his_count int64
  5441. //查询该耗材今日出库了多少
  5442. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  5443. for _, it := range outInfo {
  5444. his_count += it.Count
  5445. }
  5446. if item.Count > his_count {
  5447. //如果当前出库数据 大于历史出库数据,那么需要出库
  5448. var cha_count int64
  5449. cha_count = item.Count - his_count
  5450. timeStr := time.Now().Format("2006-01-02")
  5451. timeArr := strings.Split(timeStr, "-")
  5452. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5453. total = total + 1
  5454. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5455. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5456. number = number + total
  5457. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5458. operation_time := time.Now().Unix()
  5459. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5460. recordDateStr := time.Now().Format("2006-01-02")
  5461. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5462. nowtime := recordDate.Unix()
  5463. //查询默认出库仓库库存
  5464. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5465. warehouseOut := models.WarehouseOut{
  5466. WarehouseOutOrderNumber: warehousing_out_order,
  5467. OperationTime: operation_time,
  5468. OrgId: adminInfo.Org.Id,
  5469. Creater: creater,
  5470. Ctime: time.Now().Unix(),
  5471. Status: 1,
  5472. WarehouseOutTime: nowtime,
  5473. Type: 1,
  5474. StorehouseId: storeConfig.StorehouseOutInfo,
  5475. IsCheck: 1,
  5476. IsSys: 1,
  5477. }
  5478. //查询是否生成出库单
  5479. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5480. if out.ID == 0 {
  5481. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5482. }
  5483. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5484. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5485. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5486. dialyPrepareOne := models.DialysisBeforePrepare{
  5487. GoodTypeId: goodObj.GoodTypeId,
  5488. GoodId: item.GoodId,
  5489. PatientId: item.PatientId,
  5490. RecordDate: record_time,
  5491. UserOrgId: adminInfo.Org.Id,
  5492. Count: cha_count,
  5493. Ctime: time.Now().Unix(),
  5494. Creater: creater,
  5495. Status: 1,
  5496. StorehouseId: houseConfig.StorehouseOutInfo,
  5497. ProjectId: item.ProjectId,
  5498. }
  5499. //出库
  5500. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5501. if err == nil {
  5502. goodErrcode := models.XtGoodErrcode{
  5503. UserOrgId: adminInfo.Org.Id,
  5504. Errcode: "自动出库接口报错",
  5505. GoodId: 0,
  5506. Status: 1,
  5507. Ctime: time.Now().Unix(),
  5508. Mtime: 0,
  5509. Count: 0,
  5510. StockCount: 0,
  5511. Creater: creator,
  5512. BatchNumberId: 0,
  5513. WarehouseOutId: 0,
  5514. }
  5515. service.CreateGoodErrcode(goodErrcode)
  5516. utils.TraceLog("创建出库单失败 err = %v", err)
  5517. }
  5518. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5519. }
  5520. if item.Count < his_count {
  5521. var cha_count int64
  5522. cha_count = his_count - item.Count
  5523. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  5524. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5525. newPrescriptionProject := &models.HisPrescriptionProject{
  5526. ID: item.ProjectId,
  5527. ProjectId: item.GoodId,
  5528. UserOrgId: adminInfo.Org.Id,
  5529. Status: 1,
  5530. Ctime: time.Now().Unix(),
  5531. Mtime: time.Now().Unix(),
  5532. PatientId: item.PatientId,
  5533. RecordDate: record_time,
  5534. Count: strconv.FormatInt(item.Count, 10),
  5535. }
  5536. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5537. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5538. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5539. }
  5540. if item.Count == his_count {
  5541. if his_count == 0 {
  5542. recordDateStr := time.Now().Format("2006-01-02")
  5543. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5544. nowtime := recordDate.Unix()
  5545. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5546. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5547. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5548. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5549. dialyPrepareOne := models.DialysisBeforePrepare{
  5550. GoodTypeId: goodObj.GoodTypeId,
  5551. GoodId: item.GoodId,
  5552. PatientId: item.PatientId,
  5553. RecordDate: record_time,
  5554. UserOrgId: adminInfo.Org.Id,
  5555. Count: item.Count,
  5556. Ctime: time.Now().Unix(),
  5557. Creater: creater,
  5558. Status: 1,
  5559. StorehouseId: houseConfig.StorehouseOutInfo,
  5560. ProjectId: item.ProjectId,
  5561. }
  5562. //出库
  5563. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5564. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5565. }
  5566. }
  5567. //查询剩余库存
  5568. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  5569. var sum_count int64
  5570. for _, item := range goodList {
  5571. sum_count += item.StockCount
  5572. }
  5573. //更新剩余库存
  5574. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  5575. //耗材
  5576. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  5577. }
  5578. if err == nil {
  5579. c.ServeSuccessJSON(map[string]interface{}{
  5580. "msg": "保存成功",
  5581. "message": "2",
  5582. })
  5583. return
  5584. } else {
  5585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5586. return
  5587. }
  5588. }
  5589. if len(beforePrepares) > 0 && active == 2 {
  5590. db := service.XTWriteDB()
  5591. tx := db.Begin()
  5592. // 在函数结束时处理事务回滚
  5593. defer func() {
  5594. if r := recover(); r != nil {
  5595. tx.Rollback()
  5596. } else {
  5597. tx.Commit()
  5598. }
  5599. }()
  5600. for _, item := range newBeforePrepares {
  5601. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5602. adminInfo := c.GetMobileAdminUserInfo()
  5603. var his_count int64
  5604. //查询该耗材今日出库了多少
  5605. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  5606. for _, it := range outInfo {
  5607. his_count += it.Count
  5608. }
  5609. if item.Count > his_count {
  5610. //如果当前出库数据 大于历史出库数据,那么需要出库
  5611. var cha_count int64
  5612. cha_count = item.Count - his_count
  5613. timeStr := time.Now().Format("2006-01-02")
  5614. timeArr := strings.Split(timeStr, "-")
  5615. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5616. total = total + 1
  5617. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5618. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5619. number = number + total
  5620. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5621. operation_time := time.Now().Unix()
  5622. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5623. recordDateStr := time.Now().Format("2006-01-02")
  5624. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5625. nowtime := recordDate.Unix()
  5626. //查询默认出库仓库库存
  5627. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5628. warehouseOut := models.WarehouseOut{
  5629. WarehouseOutOrderNumber: warehousing_out_order,
  5630. OperationTime: operation_time,
  5631. OrgId: adminInfo.Org.Id,
  5632. Creater: creater,
  5633. Ctime: time.Now().Unix(),
  5634. Status: 1,
  5635. WarehouseOutTime: nowtime,
  5636. Type: 1,
  5637. StorehouseId: storeConfig.StorehouseOutInfo,
  5638. IsCheck: 1,
  5639. IsSys: 1,
  5640. }
  5641. //查询是否生成出库单
  5642. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5643. if out.ID == 0 {
  5644. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5645. }
  5646. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5647. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5648. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5649. dialyPrepareOne := models.DialysisBeforePrepare{
  5650. GoodTypeId: goodObj.GoodTypeId,
  5651. GoodId: item.GoodId,
  5652. PatientId: item.PatientId,
  5653. RecordDate: record_time,
  5654. UserOrgId: adminInfo.Org.Id,
  5655. Count: cha_count,
  5656. Ctime: time.Now().Unix(),
  5657. Creater: creater,
  5658. Status: 1,
  5659. StorehouseId: houseConfig.StorehouseOutInfo,
  5660. ProjectId: item.ProjectId,
  5661. }
  5662. //出库
  5663. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5664. if err == nil {
  5665. goodErrcode := models.XtGoodErrcode{
  5666. UserOrgId: adminInfo.Org.Id,
  5667. Errcode: "自动出库接口报错",
  5668. GoodId: 0,
  5669. Status: 1,
  5670. Ctime: time.Now().Unix(),
  5671. Mtime: 0,
  5672. Count: 0,
  5673. StockCount: 0,
  5674. Creater: creator,
  5675. BatchNumberId: 0,
  5676. WarehouseOutId: 0,
  5677. }
  5678. service.CreateGoodErrcode(goodErrcode)
  5679. utils.TraceLog("创建出库单失败 err = %v", err)
  5680. }
  5681. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5682. }
  5683. if item.Count < his_count {
  5684. var cha_count int64
  5685. cha_count = his_count - item.Count
  5686. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  5687. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5688. newPrescriptionProject := &models.HisPrescriptionProject{
  5689. ID: item.ProjectId,
  5690. ProjectId: item.GoodId,
  5691. UserOrgId: adminInfo.Org.Id,
  5692. Status: 1,
  5693. Ctime: time.Now().Unix(),
  5694. Mtime: time.Now().Unix(),
  5695. PatientId: item.PatientId,
  5696. RecordDate: record_time,
  5697. Count: strconv.FormatInt(item.Count, 10),
  5698. }
  5699. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5700. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5701. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5702. }
  5703. if item.Count == his_count {
  5704. if his_count == 0 {
  5705. recordDateStr := time.Now().Format("2006-01-02")
  5706. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5707. nowtime := recordDate.Unix()
  5708. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5709. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5710. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5711. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5712. dialyPrepareOne := models.DialysisBeforePrepare{
  5713. GoodTypeId: goodObj.GoodTypeId,
  5714. GoodId: item.GoodId,
  5715. PatientId: item.PatientId,
  5716. RecordDate: record_time,
  5717. UserOrgId: adminInfo.Org.Id,
  5718. Count: item.Count,
  5719. Ctime: time.Now().Unix(),
  5720. Creater: creater,
  5721. Status: 1,
  5722. StorehouseId: houseConfig.StorehouseOutInfo,
  5723. ProjectId: item.ProjectId,
  5724. }
  5725. //出库
  5726. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5727. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5728. }
  5729. }
  5730. //查询剩余库存
  5731. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  5732. var sum_count int64
  5733. for _, item := range goodList {
  5734. sum_count += item.StockCount
  5735. }
  5736. //更新剩余库存
  5737. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  5738. //耗材
  5739. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  5740. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5741. c.ServeSuccessJSON(map[string]interface{}{
  5742. "message": "1",
  5743. "good_name": goodObj.GoodName,
  5744. "specification_name": goodObj.SpecificationName,
  5745. })
  5746. return
  5747. }
  5748. }
  5749. var errs error
  5750. if errs == nil {
  5751. c.ServeSuccessJSON(map[string]interface{}{
  5752. "msg": "提交成功",
  5753. "message": "2",
  5754. "good_name": "",
  5755. "specification_name": "",
  5756. })
  5757. return
  5758. } else {
  5759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5760. return
  5761. }
  5762. }
  5763. }
  5764. func (c *DialysisAPIController) CreateStockOutInfo() {
  5765. patient_id, _ := c.GetInt64("patient_id", 0)
  5766. record_date := c.GetString("record_time")
  5767. if patient_id <= 0 {
  5768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. return
  5770. }
  5771. adminInfo := c.GetMobileAdminUserInfo()
  5772. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5773. timeLayout := "2006-01-02"
  5774. loc, _ := time.LoadLocation("Local")
  5775. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5776. record_time := theRecordTime.Unix()
  5777. // 查询信息规挡的设置天数
  5778. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5779. if infor.ID > 0 && infor.WeekDay > 0 {
  5780. var cha_time int64
  5781. timeNowStr := time.Now().Format("2006-01-02")
  5782. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5783. //今日的日期减去设置的日期
  5784. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5785. if cha_time >= record_time {
  5786. //查询审核是否允许
  5787. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5788. //申请状态不允许的情况 拒绝修改
  5789. if infor.ApplicationStatus != 1 {
  5790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5791. return
  5792. }
  5793. }
  5794. }
  5795. //创建步骤表
  5796. finish := models.XtDialysisFinish{
  5797. IsFinish: 1,
  5798. UserOrgId: adminInfo.Org.Id,
  5799. Status: 1,
  5800. Ctime: time.Now().Unix(),
  5801. Mtime: 0,
  5802. Module: 11,
  5803. RecordDate: record_time,
  5804. Sourse: 1,
  5805. PatientId: patient_id,
  5806. }
  5807. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5808. if dialysisFinish.ID == 0 {
  5809. service.CreateDialysisFinish(finish)
  5810. }
  5811. dataBody := make(map[string]interface{}, 0)
  5812. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5813. if err != nil {
  5814. utils.ErrorLog(err.Error())
  5815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5816. return
  5817. }
  5818. var consumables []*models.DialysisBeforePrepare
  5819. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5820. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5821. goods, _ := dataBody["goods"].([]interface{})
  5822. if len(goods) > 0 {
  5823. for _, item := range goods {
  5824. items := item.(map[string]interface{})
  5825. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5826. utils.ErrorLog("good_id")
  5827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. return
  5829. }
  5830. good_id := int64(items["good_id"].(float64))
  5831. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5832. utils.ErrorLog("good_type_id")
  5833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5834. return
  5835. }
  5836. good_type_id := int64(items["good_type_id"].(float64))
  5837. if items["new_count"] == nil || reflect.TypeOf(items["new_count"]).String() != "float64" {
  5838. utils.ErrorLog("new_count")
  5839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5840. return
  5841. }
  5842. count := int64(items["new_count"].(float64))
  5843. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5844. utils.ErrorLog("project_id")
  5845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5846. return
  5847. }
  5848. project_id := int64(items["project_id"].(float64))
  5849. prepare := &models.DialysisBeforePrepare{
  5850. GoodTypeId: good_type_id,
  5851. GoodId: good_id,
  5852. Count: count,
  5853. PatientId: patient_id,
  5854. RecordDate: record_time,
  5855. UserOrgId: adminInfo.Org.Id,
  5856. Status: 1,
  5857. Ctime: time.Now().Unix(),
  5858. Creater: adminInfo.AdminUser.Id,
  5859. StorehouseId: houseConfig.StorehouseOutInfo,
  5860. ProjectId: project_id,
  5861. }
  5862. consumables = append(consumables, prepare)
  5863. }
  5864. }
  5865. }
  5866. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5867. if record.IsOpen == 1 {
  5868. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5869. //查询是否有库存
  5870. for _, item := range consumables {
  5871. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5872. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, good.GoodTypeId, houseConfig.StorehouseOutInfo)
  5873. if item.Count > warehouse.Count {
  5874. goodErrcode := models.XtGoodErrcode{
  5875. UserOrgId: item.UserOrgId,
  5876. Errcode: "自动出库库存不足",
  5877. GoodId: item.ProjectId,
  5878. Status: 1,
  5879. Ctime: time.Now().Unix(),
  5880. Mtime: 0,
  5881. Count: 0,
  5882. StockCount: 0,
  5883. Creater: creator,
  5884. BatchNumberId: warehouse.ID,
  5885. WarehouseOutId: 0,
  5886. }
  5887. service.CreateGoodErrcode(goodErrcode)
  5888. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5889. c.ServeSuccessJSON(map[string]interface{}{
  5890. "message": "1",
  5891. "good_name": goodObj.GoodName,
  5892. "specification_name": goodObj.SpecificationName,
  5893. })
  5894. return
  5895. }
  5896. }
  5897. //查询是否有出库单
  5898. _, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5899. if err == gorm.ErrRecordNotFound {
  5900. //没有记录,则创建出库单
  5901. timeStr := time.Now().Format("2006-01-02")
  5902. timeArr := strings.Split(timeStr, "-")
  5903. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5904. total = total + 1
  5905. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5906. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5907. number = number + total
  5908. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5909. creater := adminInfo.AdminUser.Id
  5910. warehouseOut := models.WarehouseOut{
  5911. WarehouseOutOrderNumber: warehousing_out_order,
  5912. OperationTime: time.Now().Unix(),
  5913. OrgId: adminInfo.Org.Id,
  5914. Creater: creater,
  5915. Ctime: time.Now().Unix(),
  5916. Status: 1,
  5917. WarehouseOutTime: record_time,
  5918. Dealer: 0,
  5919. Manufacturer: 0,
  5920. Type: 1,
  5921. IsSys: 1,
  5922. StorehouseId: houseConfig.StorehouseOutInfo,
  5923. IsCheck: 1,
  5924. }
  5925. err := service.AddSigleWarehouseOut(&warehouseOut)
  5926. if err != nil {
  5927. goodErrcode := models.XtGoodErrcode{
  5928. UserOrgId: adminInfo.Org.Id,
  5929. Errcode: "创建出库单失败",
  5930. GoodId: 0,
  5931. Status: 1,
  5932. Ctime: time.Now().Unix(),
  5933. Mtime: 0,
  5934. Count: 0,
  5935. StockCount: 0,
  5936. Creater: creator,
  5937. BatchNumberId: 0,
  5938. WarehouseOutId: 0,
  5939. }
  5940. service.CreateGoodErrcode(goodErrcode)
  5941. utils.TraceLog("创建出库单失败 err = %v", err)
  5942. } else {
  5943. db := service.XTWriteDB()
  5944. tx := db.Begin()
  5945. // 在函数结束时处理事务回滚
  5946. defer func() {
  5947. if r := recover(); r != nil {
  5948. tx.Rollback()
  5949. } else {
  5950. tx.Commit()
  5951. }
  5952. }()
  5953. for _, item := range consumables {
  5954. //出库
  5955. if item.Count > 0 {
  5956. timeStr := time.Now().Format("2006-01-02")
  5957. timeArr := strings.Split(timeStr, "-")
  5958. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5959. total = total + 1
  5960. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5961. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5962. number = number + total
  5963. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5964. operation_time := time.Now().Unix()
  5965. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5966. recordDateStr := time.Now().Format("2006-01-02")
  5967. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5968. nowtime := recordDate.Unix()
  5969. //查询默认出库仓库库存
  5970. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5971. warehouseOut := models.WarehouseOut{
  5972. WarehouseOutOrderNumber: warehousing_out_order,
  5973. OperationTime: operation_time,
  5974. OrgId: adminInfo.Org.Id,
  5975. Creater: creater,
  5976. Ctime: time.Now().Unix(),
  5977. Status: 1,
  5978. WarehouseOutTime: nowtime,
  5979. Type: 1,
  5980. StorehouseId: storeConfig.StorehouseOutInfo,
  5981. IsCheck: 1,
  5982. IsSys: 1,
  5983. }
  5984. //查询是否生成出库单
  5985. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5986. if out.ID == 0 {
  5987. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5988. }
  5989. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5990. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5991. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5992. dialyPrepareOne := models.DialysisBeforePrepare{
  5993. GoodTypeId: goodObj.GoodTypeId,
  5994. GoodId: item.GoodId,
  5995. PatientId: patient_id,
  5996. RecordDate: record_time,
  5997. UserOrgId: adminInfo.Org.Id,
  5998. Count: item.Count,
  5999. Ctime: time.Now().Unix(),
  6000. Creater: creater,
  6001. Status: 1,
  6002. StorehouseId: houseConfig.StorehouseOutInfo,
  6003. ProjectId: item.ProjectId,
  6004. }
  6005. //出库
  6006. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  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. utils.TraceLog("创建出库单失败 err = %v", err)
  6023. }
  6024. //添加
  6025. service.ModfiyAddDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6026. }
  6027. //退库
  6028. if item.Count < 0 {
  6029. count := math.Abs(float64(item.Count))
  6030. item.Count = int64(count)
  6031. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6032. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6033. newPrescriptionProject := &models.HisPrescriptionProject{
  6034. ID: item.ProjectId,
  6035. ProjectId: item.GoodId,
  6036. UserOrgId: adminInfo.Org.Id,
  6037. Status: 1,
  6038. Ctime: time.Now().Unix(),
  6039. Mtime: time.Now().Unix(),
  6040. PatientId: patient_id,
  6041. RecordDate: record_time,
  6042. }
  6043. fmt.Println("item.Count---------------------------------------", item.Count)
  6044. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6045. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6046. //减少
  6047. service.ModfiyReduceDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6048. }
  6049. //查询剩余库存
  6050. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6051. var sum_count int64
  6052. for _, item := range goodList {
  6053. sum_count += item.StockCount
  6054. }
  6055. //更新剩余库存
  6056. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6057. //耗材
  6058. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6059. }
  6060. }
  6061. //
  6062. } else if err == nil {
  6063. for _, item := range consumables {
  6064. db := service.XTWriteDB()
  6065. tx := db.Begin()
  6066. // 在函数结束时处理事务回滚
  6067. defer func() {
  6068. if r := recover(); r != nil {
  6069. tx.Rollback()
  6070. } else {
  6071. tx.Commit()
  6072. }
  6073. }()
  6074. //出库
  6075. if item.Count > 0 {
  6076. timeStr := time.Now().Format("2006-01-02")
  6077. timeArr := strings.Split(timeStr, "-")
  6078. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6079. total = total + 1
  6080. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6081. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6082. number = number + total
  6083. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6084. operation_time := time.Now().Unix()
  6085. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6086. recordDateStr := time.Now().Format("2006-01-02")
  6087. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6088. nowtime := recordDate.Unix()
  6089. //查询默认出库仓库库存
  6090. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6091. warehouseOut := models.WarehouseOut{
  6092. WarehouseOutOrderNumber: warehousing_out_order,
  6093. OperationTime: operation_time,
  6094. OrgId: adminInfo.Org.Id,
  6095. Creater: creater,
  6096. Ctime: time.Now().Unix(),
  6097. Status: 1,
  6098. WarehouseOutTime: nowtime,
  6099. Type: 1,
  6100. StorehouseId: storeConfig.StorehouseOutInfo,
  6101. IsCheck: 1,
  6102. IsSys: 1,
  6103. }
  6104. //查询是否生成出库单
  6105. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6106. if out.ID == 0 {
  6107. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6108. }
  6109. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6110. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6111. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6112. dialyPrepareOne := models.DialysisBeforePrepare{
  6113. GoodTypeId: goodObj.GoodTypeId,
  6114. GoodId: item.GoodId,
  6115. PatientId: patient_id,
  6116. RecordDate: record_time,
  6117. UserOrgId: adminInfo.Org.Id,
  6118. Count: item.Count,
  6119. Ctime: time.Now().Unix(),
  6120. Creater: creater,
  6121. Status: 1,
  6122. StorehouseId: houseConfig.StorehouseOutInfo,
  6123. ProjectId: item.ProjectId,
  6124. }
  6125. //出库
  6126. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6127. if err == nil {
  6128. goodErrcode := models.XtGoodErrcode{
  6129. UserOrgId: adminInfo.Org.Id,
  6130. Errcode: "自动出库接口报错",
  6131. GoodId: 0,
  6132. Status: 1,
  6133. Ctime: time.Now().Unix(),
  6134. Mtime: 0,
  6135. Count: 0,
  6136. StockCount: 0,
  6137. Creater: creator,
  6138. BatchNumberId: 0,
  6139. WarehouseOutId: 0,
  6140. }
  6141. service.CreateGoodErrcode(goodErrcode)
  6142. utils.TraceLog("创建出库单失败 err = %v", err)
  6143. }
  6144. //减少
  6145. service.ModfiyAddDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6146. }
  6147. //退库
  6148. if item.Count < 0 {
  6149. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6150. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6151. count := math.Abs(float64(item.Count))
  6152. item.Count = int64(count)
  6153. fmt.Println("item.Count---------------------------------------", item.Count)
  6154. fmt.Println("item.GoodId-----------------------------------", item.GoodId)
  6155. newPrescriptionProject := &models.HisPrescriptionProject{
  6156. ID: item.ProjectId,
  6157. ProjectId: item.GoodId,
  6158. UserOrgId: adminInfo.Org.Id,
  6159. Status: 1,
  6160. Ctime: time.Now().Unix(),
  6161. Mtime: time.Now().Unix(),
  6162. PatientId: item.PatientId,
  6163. RecordDate: record_time,
  6164. Count: strconv.FormatInt(item.Count, 10),
  6165. }
  6166. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6167. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6168. //减少
  6169. service.ModfiyReduceDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6170. }
  6171. //查询剩余库存
  6172. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6173. var sum_count int64
  6174. for _, item := range goodList {
  6175. sum_count += item.StockCount
  6176. }
  6177. //更新剩余库存
  6178. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6179. //耗材
  6180. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6181. }
  6182. }
  6183. c.ServeSuccessJSON(map[string]interface{}{
  6184. "msg": "提交成功",
  6185. "message": "2",
  6186. "good_name": "",
  6187. "specification_name": "",
  6188. })
  6189. return
  6190. } else {
  6191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6192. return
  6193. }
  6194. }
  6195. func (c *DialysisAPIController) EditConsumables() {
  6196. patient_id, _ := c.GetInt64("patient_id", 0)
  6197. record_date := c.GetString("record_time")
  6198. if patient_id <= 0 {
  6199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6200. return
  6201. }
  6202. adminInfo := c.GetMobileAdminUserInfo()
  6203. timeLayout := "2006-01-02"
  6204. loc, _ := time.LoadLocation("Local")
  6205. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6206. record_time := theRecordTime.Unix()
  6207. // 查询信息规挡的设置天数
  6208. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6209. if infor.ID > 0 && infor.WeekDay > 0 {
  6210. var cha_time int64
  6211. timeNowStr := time.Now().Format("2006-01-02")
  6212. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6213. //今日的日期减去设置的日期
  6214. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6215. if cha_time >= record_time {
  6216. //查询审核是否允许
  6217. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6218. //申请状态不允许的情况 拒绝修改
  6219. if infor.ApplicationStatus != 1 {
  6220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6221. return
  6222. }
  6223. }
  6224. }
  6225. dataBody := make(map[string]interface{}, 0)
  6226. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6227. if err != nil {
  6228. utils.ErrorLog(err.Error())
  6229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6230. return
  6231. }
  6232. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6233. var beforePrepares []*models.DialysisBeforePrepareGoods
  6234. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6235. //判断是否开启自动出库
  6236. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6237. fmt.Println("record.IsOpen====================================", record)
  6238. if record.IsOpen == 1 {
  6239. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6240. goods, _ := dataBody["goods"].([]interface{})
  6241. if len(goods) > 0 {
  6242. for _, item := range goods {
  6243. items := item.(map[string]interface{})
  6244. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6245. utils.ErrorLog("good_id")
  6246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6247. return
  6248. }
  6249. good_id := int64(items["good_id"].(float64))
  6250. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6251. utils.ErrorLog("good_type_id")
  6252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6253. return
  6254. }
  6255. good_type_id := int64(items["good_type_id"].(float64))
  6256. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6257. utils.ErrorLog("count")
  6258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6259. return
  6260. }
  6261. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6262. commdity_code := items["commdity_code"].(string)
  6263. fmt.Println(commdity_code)
  6264. prepareGoods := &models.DialysisBeforePrepareGoods{
  6265. GoodTypeId: good_type_id,
  6266. GoodId: good_id,
  6267. Count: count,
  6268. StorehouseId: houseConfig.StorehouseOutInfo,
  6269. PatientId: patient_id,
  6270. }
  6271. beforePrepares = append(beforePrepares, prepareGoods)
  6272. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6273. GoodTypeId: good_type_id,
  6274. GoodId: good_id,
  6275. Count: count,
  6276. StorehouseId: houseConfig.StorehouseOutInfo,
  6277. PatientId: patient_id,
  6278. }
  6279. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6280. }
  6281. db := service.XTWriteDB()
  6282. tx := db.Begin()
  6283. // 在函数结束时处理事务回滚
  6284. defer func() {
  6285. if r := recover(); r != nil {
  6286. tx.Rollback()
  6287. } else {
  6288. tx.Commit()
  6289. }
  6290. }()
  6291. for _, item := range newBeforePrepares {
  6292. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6293. var his_count int64
  6294. //查询该耗材今日出库了多少
  6295. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  6296. fmt.Println("outInfo---------------------------------------", outInfo)
  6297. for _, it := range outInfo {
  6298. his_count += it.Count
  6299. }
  6300. if item.Count > his_count {
  6301. //如果当前出库数据 大于历史出库数据,那么需要出库
  6302. var cha_count int64
  6303. cha_count = item.Count - his_count
  6304. timeStr := time.Now().Format("2006-01-02")
  6305. timeArr := strings.Split(timeStr, "-")
  6306. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6307. total = total + 1
  6308. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6309. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6310. number = number + total
  6311. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6312. operation_time := time.Now().Unix()
  6313. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6314. recordDateStr := time.Now().Format("2006-01-02")
  6315. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6316. nowtime := recordDate.Unix()
  6317. //查询默认出库仓库库存
  6318. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6319. warehouseOut := models.WarehouseOut{
  6320. WarehouseOutOrderNumber: warehousing_out_order,
  6321. OperationTime: operation_time,
  6322. OrgId: adminInfo.Org.Id,
  6323. Creater: creater,
  6324. Ctime: time.Now().Unix(),
  6325. Status: 1,
  6326. WarehouseOutTime: nowtime,
  6327. Type: 1,
  6328. StorehouseId: storeConfig.StorehouseOutInfo,
  6329. IsCheck: 1,
  6330. IsSys: 1,
  6331. }
  6332. //查询是否生成出库单
  6333. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6334. if out.ID == 0 {
  6335. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6336. }
  6337. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6338. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6339. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6340. dialyPrepareOne := models.DialysisBeforePrepare{
  6341. GoodTypeId: goodObj.GoodTypeId,
  6342. GoodId: item.GoodId,
  6343. PatientId: item.PatientId,
  6344. RecordDate: record_time,
  6345. UserOrgId: adminInfo.Org.Id,
  6346. Count: cha_count,
  6347. Ctime: time.Now().Unix(),
  6348. Creater: creater,
  6349. Status: 1,
  6350. StorehouseId: houseConfig.StorehouseOutInfo,
  6351. ProjectId: item.ProjectId,
  6352. }
  6353. //出库
  6354. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6355. if err == nil {
  6356. goodErrcode := models.XtGoodErrcode{
  6357. UserOrgId: adminInfo.Org.Id,
  6358. Errcode: "自动出库接口报错",
  6359. GoodId: 0,
  6360. Status: 1,
  6361. Ctime: time.Now().Unix(),
  6362. Mtime: 0,
  6363. Count: 0,
  6364. StockCount: 0,
  6365. Creater: creator,
  6366. BatchNumberId: 0,
  6367. WarehouseOutId: 0,
  6368. }
  6369. service.CreateGoodErrcode(goodErrcode)
  6370. utils.TraceLog("创建出库单失败 err = %v", err)
  6371. }
  6372. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6373. }
  6374. if item.Count < his_count {
  6375. var cha_count int64
  6376. cha_count = his_count - item.Count
  6377. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6378. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6379. newPrescriptionProject := &models.HisPrescriptionProject{
  6380. ID: item.ProjectId,
  6381. ProjectId: item.GoodId,
  6382. UserOrgId: adminInfo.Org.Id,
  6383. Status: 1,
  6384. Ctime: time.Now().Unix(),
  6385. Mtime: time.Now().Unix(),
  6386. PatientId: item.PatientId,
  6387. RecordDate: record_time,
  6388. }
  6389. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6390. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6391. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6392. }
  6393. if item.Count == his_count {
  6394. if his_count == 0 {
  6395. recordDateStr := time.Now().Format("2006-01-02")
  6396. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6397. nowtime := recordDate.Unix()
  6398. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6399. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6400. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6401. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6402. dialyPrepareOne := models.DialysisBeforePrepare{
  6403. GoodTypeId: goodObj.GoodTypeId,
  6404. GoodId: item.GoodId,
  6405. PatientId: item.PatientId,
  6406. RecordDate: record_time,
  6407. UserOrgId: adminInfo.Org.Id,
  6408. Count: item.Count,
  6409. Ctime: time.Now().Unix(),
  6410. Creater: creater,
  6411. Status: 1,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. ProjectId: item.ProjectId,
  6414. }
  6415. //出库
  6416. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6417. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6418. }
  6419. }
  6420. //查询剩余库存
  6421. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6422. var sum_count int64
  6423. for _, item := range goodList {
  6424. sum_count += item.StockCount
  6425. }
  6426. //更新剩余库存
  6427. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6428. //耗材
  6429. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6430. }
  6431. }
  6432. }
  6433. //更新自动出库的地方
  6434. var errs error
  6435. if errs == nil {
  6436. c.ServeSuccessJSON(map[string]interface{}{
  6437. "msg": "修改成功",
  6438. "message": "2",
  6439. "good_name": "",
  6440. "specification_name": "",
  6441. })
  6442. return
  6443. } else {
  6444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6445. return
  6446. }
  6447. }
  6448. }
  6449. func (c *DialysisAPIController) GetDialysisGoods() {
  6450. schedualDate := c.GetString("schedule_date")
  6451. schedule_type, _ := c.GetInt64("schedule_type")
  6452. partition_id, _ := c.GetInt64("partition_id")
  6453. page, _ := c.GetInt("page")
  6454. patient_id, _ := c.GetInt64("patient_id")
  6455. schedualEndDate := int64(0)
  6456. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6457. if parseDateErr != nil && len(schedualDate) != 0 {
  6458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6459. return
  6460. }
  6461. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6462. if parseDateErr != nil && len(schedualDate) != 0 {
  6463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6464. return
  6465. }
  6466. schedualEndDate = endDate.Unix()
  6467. adminUser := c.GetMobileAdminUserInfo()
  6468. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6469. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6470. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6471. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6472. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6473. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6474. //获取当天该病人的透析处方
  6475. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6476. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6477. if err == gorm.ErrRecordNotFound {
  6478. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6479. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6480. if patient_id != 0 {
  6481. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6482. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6483. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6484. //获取患者总的出库数据
  6485. item.LastAutomaticReduceDetail = goodUser
  6486. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6487. item.Project = project
  6488. for _, it := range item.AutomaticReduceDetail {
  6489. var total int64
  6490. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6491. for _, its := range auto {
  6492. total += its.Count
  6493. }
  6494. it.Count = total
  6495. }
  6496. }
  6497. }
  6498. c.ServeSuccessJSON(map[string]interface{}{
  6499. "dialysis_goods": dialysisGoods,
  6500. "good_type": goodTypes,
  6501. "total": total,
  6502. "prescribe": prescribe,
  6503. "good_info": good_info,
  6504. "warehouseOutList": warehouseOutList,
  6505. "config": config,
  6506. "outConfig": outConfig,
  6507. "settleConfig": settleConfig,
  6508. })
  6509. return
  6510. } else if err == nil {
  6511. //获取当天排班的每个患者的库存使用情况
  6512. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6513. //获取患者总的出库数据
  6514. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6515. if patient_id != 0 {
  6516. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6517. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6518. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6519. item.Project = project
  6520. item.LastAutomaticReduceDetail = goodUser
  6521. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6522. for _, it := range item.AutomaticReduceDetail {
  6523. var total int64
  6524. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6525. for _, its := range auto {
  6526. total += its.Count
  6527. }
  6528. it.Count = total
  6529. }
  6530. }
  6531. }
  6532. if err == nil {
  6533. c.ServeSuccessJSON(map[string]interface{}{
  6534. "dialysis_goods": dialysisGoods,
  6535. "good_type": goodTypes,
  6536. "total": total,
  6537. "prescribe": prescribe,
  6538. "good_info": good_info,
  6539. "project": project,
  6540. "warehouseOutList": warehouseOutList,
  6541. "config": config,
  6542. "outConfig": outConfig,
  6543. "settleConfig": settleConfig,
  6544. })
  6545. return
  6546. } else {
  6547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6548. return
  6549. }
  6550. } else if err != nil {
  6551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6552. return
  6553. }
  6554. }
  6555. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6556. start_time := c.GetString("start_time")
  6557. end_time := c.GetString("end_time")
  6558. timeLayout := "2006-01-02"
  6559. loc, _ := time.LoadLocation("Local")
  6560. var theStartTime int64
  6561. if len(start_time) > 0 {
  6562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6563. if err != nil {
  6564. utils.ErrorLog(err.Error())
  6565. }
  6566. theStartTime = theTime.Unix()
  6567. }
  6568. var theEndtTime int64
  6569. if len(end_time) > 0 {
  6570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6571. if err != nil {
  6572. utils.ErrorLog(err.Error())
  6573. }
  6574. theEndtTime = theTime.Unix()
  6575. }
  6576. adminUser := c.GetMobileAdminUserInfo()
  6577. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6578. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6579. if err == nil {
  6580. c.ServeSuccessJSON(map[string]interface{}{
  6581. "stock_out": outInfo,
  6582. "stockCount": stockCount,
  6583. })
  6584. return
  6585. } else {
  6586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6587. return
  6588. }
  6589. }
  6590. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6591. patient_id, _ := c.GetInt64("patient_id", 0)
  6592. record_time := c.GetString("record_time")
  6593. adminUser := c.GetMobileAdminUserInfo()
  6594. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6595. if parseDateErr != nil && len(record_time) != 0 {
  6596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6597. return
  6598. }
  6599. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6600. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6601. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6602. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6603. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6604. //获取今日患者的透析处方参数
  6605. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6606. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6607. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6608. c.ServeSuccessJSON(map[string]interface{}{
  6609. "good_type": goodTypes,
  6610. "good_user": goodUser,
  6611. "good_info": good_info,
  6612. "last_good_user": lastGoodUserDetial,
  6613. "project": project,
  6614. "prescription": prescribe,
  6615. "outInfo": outInfo,
  6616. "configs": configs,
  6617. })
  6618. return
  6619. }
  6620. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6621. patient_id, _ := c.GetInt64("patient_id", 0)
  6622. record_date := c.GetString("record_time")
  6623. timeLayout := "2006-01-02"
  6624. loc, _ := time.LoadLocation("Local")
  6625. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6626. record_time := theRecordTime.Unix()
  6627. adminInfo := c.GetMobileAdminUserInfo()
  6628. dataBody := make(map[string]interface{}, 0)
  6629. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6630. if err != nil {
  6631. utils.ErrorLog(err.Error())
  6632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6633. return
  6634. }
  6635. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6636. var beforePrepares []*models.DialysisBeforePrepareGoods
  6637. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6638. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6639. goods, _ := dataBody["goods"].([]interface{})
  6640. if len(goods) > 0 {
  6641. for _, item := range goods {
  6642. items := item.(map[string]interface{})
  6643. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6644. utils.ErrorLog("good_id")
  6645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6646. return
  6647. }
  6648. good_id := int64(items["good_id"].(float64))
  6649. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6650. utils.ErrorLog("good_type_id")
  6651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6652. return
  6653. }
  6654. good_type_id := int64(items["good_type_id"].(float64))
  6655. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6656. utils.ErrorLog("count")
  6657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6658. return
  6659. }
  6660. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6661. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6662. utils.ErrorLog("project_id")
  6663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6664. return
  6665. }
  6666. project_id := int64(items["project_id"].(float64))
  6667. new_count := int64(items["new_count"].(float64))
  6668. old_count := int64(items["old_count"].(float64))
  6669. prepare := &models.DialysisBeforePrepareGoods{
  6670. GoodId: good_id,
  6671. GoodTypeId: good_type_id,
  6672. Count: count,
  6673. ProjectId: project_id,
  6674. StorehouseId: houseConfig.StorehouseOutInfo,
  6675. NewCount: new_count,
  6676. OldCount: old_count,
  6677. PatientId: patient_id,
  6678. }
  6679. beforePrepares = append(beforePrepares, prepare)
  6680. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6681. GoodId: good_id,
  6682. GoodTypeId: good_type_id,
  6683. Count: count,
  6684. ProjectId: project_id,
  6685. StorehouseId: houseConfig.StorehouseOutInfo,
  6686. NewCount: new_count,
  6687. OldCount: old_count,
  6688. PatientId: patient_id,
  6689. RecordDate: record_time,
  6690. }
  6691. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6692. }
  6693. }
  6694. }
  6695. //查询是否有库存
  6696. for _, item := range beforePrepares {
  6697. if item.NewCount > 0 {
  6698. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6699. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6700. if item.Count > warehouse.Count {
  6701. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6702. c.ServeSuccessJSON(map[string]interface{}{
  6703. "message": "1",
  6704. "good_name": goodObj.GoodName,
  6705. "specification_name": goodObj.SpecificationName,
  6706. })
  6707. return
  6708. }
  6709. }
  6710. }
  6711. // 查询信息规挡的设置天数
  6712. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6713. if infor.ID > 0 && infor.WeekDay > 0 {
  6714. var cha_time int64
  6715. timeNowStr := time.Now().Format("2006-01-02")
  6716. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6717. //今日的日期减去设置的日期
  6718. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6719. if cha_time >= record_time {
  6720. //查询审核是否允许
  6721. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6722. //申请状态不允许的情况 拒绝修改
  6723. if infor.ApplicationStatus != 1 {
  6724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6725. return
  6726. }
  6727. }
  6728. }
  6729. db := service.XTWriteDB()
  6730. tx := db.Begin()
  6731. // 在函数结束时处理事务回滚
  6732. defer func() {
  6733. if r := recover(); r != nil {
  6734. tx.Rollback()
  6735. } else {
  6736. tx.Commit()
  6737. }
  6738. }()
  6739. for _, item := range beforePrepares {
  6740. var his_count int64
  6741. //查询该耗材今日出库了多少
  6742. outInfo, _ := service.GetHistoryWarehouseOutInfo(patient_id, adminInfo.Org.Id, record_time, item.GoodId, tx)
  6743. for _, it := range outInfo {
  6744. his_count += it.Count
  6745. }
  6746. //如果当前出库数据 大于历史出库数据,那么需要出库
  6747. if item.Count > his_count {
  6748. var cha_count int64
  6749. cha_count = item.Count - his_count
  6750. timeStr := time.Now().Format("2006-01-02")
  6751. timeArr := strings.Split(timeStr, "-")
  6752. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6753. total = total + 1
  6754. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6755. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6756. number = number + total
  6757. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6758. operation_time := time.Now().Unix()
  6759. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6760. recordDateStr := time.Now().Format("2006-01-02")
  6761. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6762. nowtime := recordDate.Unix()
  6763. //查询默认出库仓库库存
  6764. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6765. warehouseOut := models.WarehouseOut{
  6766. WarehouseOutOrderNumber: warehousing_out_order,
  6767. OperationTime: operation_time,
  6768. OrgId: adminInfo.Org.Id,
  6769. Creater: creater,
  6770. Ctime: time.Now().Unix(),
  6771. Status: 1,
  6772. WarehouseOutTime: nowtime,
  6773. Type: 1,
  6774. StorehouseId: storeConfig.StorehouseOutInfo,
  6775. IsCheck: 1,
  6776. IsSys: 1,
  6777. }
  6778. //查询是否生成出库单
  6779. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6780. if out.ID == 0 {
  6781. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6782. }
  6783. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6784. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6785. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6786. dialyPrepareOne := models.DialysisBeforePrepare{
  6787. GoodTypeId: goodObj.GoodTypeId,
  6788. GoodId: item.GoodId,
  6789. PatientId: item.PatientId,
  6790. RecordDate: record_time,
  6791. UserOrgId: adminInfo.Org.Id,
  6792. Count: cha_count,
  6793. Ctime: time.Now().Unix(),
  6794. Creater: creater,
  6795. Status: 1,
  6796. StorehouseId: houseConfig.StorehouseOutInfo,
  6797. ProjectId: item.ProjectId,
  6798. }
  6799. //出库
  6800. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6801. }
  6802. //如果当前出库数据 大于历史出库数据,则需要退库
  6803. if item.Count < his_count {
  6804. var cha_count int64
  6805. cha_count = his_count - item.Count
  6806. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  6807. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6808. newPrescriptionProject := &models.HisPrescriptionProject{
  6809. ID: item.ProjectId,
  6810. ProjectId: item.GoodId,
  6811. UserOrgId: adminInfo.Org.Id,
  6812. Status: 1,
  6813. Ctime: time.Now().Unix(),
  6814. Mtime: time.Now().Unix(),
  6815. PatientId: item.PatientId,
  6816. RecordDate: record_time,
  6817. Count: strconv.FormatInt(item.Count, 10),
  6818. }
  6819. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6820. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6821. }
  6822. if item.Count == his_count {
  6823. if his_count == 0 {
  6824. recordDateStr := time.Now().Format("2006-01-02")
  6825. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6826. nowtime := recordDate.Unix()
  6827. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6828. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6829. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6830. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6831. dialyPrepareOne := models.DialysisBeforePrepare{
  6832. GoodTypeId: goodObj.GoodTypeId,
  6833. GoodId: item.GoodId,
  6834. PatientId: item.PatientId,
  6835. RecordDate: record_time,
  6836. UserOrgId: adminInfo.Org.Id,
  6837. Count: item.Count,
  6838. Ctime: time.Now().Unix(),
  6839. Creater: creater,
  6840. Status: 1,
  6841. StorehouseId: houseConfig.StorehouseOutInfo,
  6842. ProjectId: item.ProjectId,
  6843. }
  6844. //出库
  6845. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6846. }
  6847. }
  6848. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6849. //查询剩余库存
  6850. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6851. var sum_count int64
  6852. for _, item := range goodList {
  6853. sum_count += item.StockCount
  6854. }
  6855. //更新剩余库存
  6856. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6857. //耗材
  6858. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6859. //查询总共出库了多少支
  6860. autoGoodInfo, _ := service.GetDialysisAutoGoodInfo(patient_id, record_time, adminInfo.Org.Id, tx, item.GoodId)
  6861. if len(autoGoodInfo) > 0 {
  6862. var out_count int64
  6863. for _, item := range autoGoodInfo {
  6864. out_count += item.Count
  6865. }
  6866. dialysisBeforePrepare := models.DialysisBeforePrepare{
  6867. UserOrgId: adminInfo.Org.Id,
  6868. PatientId: patient_id,
  6869. RecordDate: record_time,
  6870. GoodId: item.GoodId,
  6871. GoodTypeId: item.GoodTypeId,
  6872. Count: out_count,
  6873. Ctime: time.Now().Unix(),
  6874. Mtime: time.Now().Unix(),
  6875. Creater: adminInfo.AdminUser.Id,
  6876. Modifier: adminInfo.AdminUser.Id,
  6877. Status: 1,
  6878. CommdityCode: "",
  6879. NewCount: 0,
  6880. Children: nil,
  6881. ProjectId: item.ProjectId,
  6882. StorehouseId: houseConfig.StorehouseOutInfo,
  6883. }
  6884. service.CreateDialysisPrepare(dialysisBeforePrepare, tx)
  6885. }
  6886. }
  6887. finish := models.XtDialysisFinish{
  6888. IsFinish: 1,
  6889. UserOrgId: adminInfo.Org.Id,
  6890. Status: 1,
  6891. Ctime: time.Now().Unix(),
  6892. Mtime: 0,
  6893. Module: 11,
  6894. RecordDate: record_time,
  6895. Sourse: 1,
  6896. PatientId: patient_id,
  6897. }
  6898. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6899. if dialysisFinish.ID == 0 {
  6900. service.CreateDialysisFinish(finish)
  6901. }
  6902. //更新自动出库的地方
  6903. var errs error
  6904. if errs == nil {
  6905. c.ServeSuccessJSON(map[string]interface{}{
  6906. "msg": "修改成功",
  6907. "message": "2",
  6908. "good_name": "",
  6909. "specification_name": "",
  6910. })
  6911. return
  6912. } else {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6914. return
  6915. }
  6916. }
  6917. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6918. newArr = make([]*models.DialysisBeforePrepare, 0)
  6919. for i := 0; i < len(arr); i++ {
  6920. repeat := false
  6921. for j := i + 1; j < len(arr); j++ {
  6922. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  6923. repeat = true
  6924. break
  6925. }
  6926. }
  6927. if !repeat {
  6928. newArr = append(newArr, arr[i])
  6929. }
  6930. }
  6931. return
  6932. }
  6933. func (c *DialysisAPIController) GetAllDrug() {
  6934. patient_id, _ := c.GetInt64("patient_id", 0)
  6935. adminInfo := c.GetMobileAdminUserInfo()
  6936. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6937. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  6938. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  6939. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  6940. c.ServeSuccessJSON(map[string]interface{}{
  6941. "base_drug_config": drugStockConfig,
  6942. "private_drug_config": privateDrugConfig,
  6943. "base_drug_list": drugList,
  6944. "private_drug_list": privateDrugList,
  6945. })
  6946. }
  6947. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6948. newArr = make([]*models.DialysisBeforePrepare, 0)
  6949. for i := 0; i < len(arr); i++ {
  6950. repeat := false
  6951. for j := i + 1; j < len(arr); j++ {
  6952. if arr[i].GoodId == arr[j].GoodId {
  6953. repeat = true
  6954. break
  6955. }
  6956. }
  6957. if !repeat {
  6958. newArr = append(newArr, arr[i])
  6959. }
  6960. }
  6961. return
  6962. }
  6963. func (c *DialysisAPIController) GetDepartment() {
  6964. adminInfo := c.GetMobileAdminUserInfo()
  6965. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  6966. if err == nil {
  6967. c.ServeSuccessJSON(map[string]interface{}{
  6968. "departments": departments,
  6969. })
  6970. } else {
  6971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6972. return
  6973. }
  6974. }
  6975. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  6976. types, _ := c.GetInt("type", 0)
  6977. start_time := c.GetString("start_time")
  6978. end_time := c.GetString("end_time")
  6979. orgId := c.GetMobileAdminUserInfo().Org.Id
  6980. timeLayout := "2006-01-02"
  6981. loc, _ := time.LoadLocation("Local")
  6982. var startTime int64
  6983. if len(start_time) > 0 {
  6984. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6985. if err != nil {
  6986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6987. return
  6988. }
  6989. startTime = theTime.Unix()
  6990. }
  6991. var endTime int64
  6992. if len(end_time) > 0 {
  6993. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6994. if err != nil {
  6995. utils.ErrorLog(err.Error())
  6996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6997. return
  6998. }
  6999. endTime = theTime.Unix()
  7000. }
  7001. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7002. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7003. if err != nil {
  7004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7005. } else {
  7006. c.ServeSuccessJSON(map[string]interface{}{
  7007. "list": list,
  7008. "type": types,
  7009. "stockTotal": stockTotal,
  7010. })
  7011. }
  7012. }
  7013. func (c *DialysisAPIController) GetPrescriptionList() {
  7014. start_time := c.GetString("start_time")
  7015. end_time := c.GetString("end_time")
  7016. schedule_type, _ := c.GetInt64("schedule_type")
  7017. partion_id, _ := c.GetInt64("partion_id")
  7018. orgId := c.GetMobileAdminUserInfo().Org.Id
  7019. timeLayout := "2006-01-02"
  7020. loc, _ := time.LoadLocation("Local")
  7021. var startTime int64
  7022. if len(start_time) > 0 {
  7023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7024. if err != nil {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7026. return
  7027. }
  7028. startTime = theTime.Unix()
  7029. }
  7030. var endTime int64
  7031. if len(end_time) > 0 {
  7032. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7033. if err != nil {
  7034. utils.ErrorLog(err.Error())
  7035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7036. return
  7037. }
  7038. endTime = theTime.Unix()
  7039. }
  7040. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7041. fmt.Println("schedulelist22222222", schedulelist)
  7042. c.ServeSuccessJSON(map[string]interface{}{
  7043. "list": schedulelist,
  7044. })
  7045. return
  7046. }
  7047. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7048. ids := c.GetString("ids")
  7049. //patient_id, _ := c.GetInt64("patient_id")
  7050. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7051. idArray := strings.Split(ids, ",")
  7052. err := service.BatchDeleteMonitor(idArray)
  7053. fmt.Print("err", err)
  7054. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7055. //redis := service.RedisClient()
  7056. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7057. //redis.Set(key, "", time.Second)
  7058. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7059. //redis.Set(keyOne, "", time.Second)
  7060. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7061. //redis.Close()
  7062. c.ServeSuccessJSON(map[string]interface{}{
  7063. "msg": "批量删除成功",
  7064. })
  7065. return
  7066. }
  7067. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7068. id, _ := c.GetInt64("id")
  7069. timeLayout := "2006-01-02"
  7070. loc, _ := time.LoadLocation("Local")
  7071. //start_time := time.Now().Format("2006-01-02")
  7072. start_time := c.GetString("start_time")
  7073. end_time := c.GetString("end_time")
  7074. var startdateunix int64
  7075. if len(start_time) > 0 {
  7076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7077. if err != nil {
  7078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7079. return
  7080. }
  7081. startdateunix = theTime.Unix()
  7082. }
  7083. var enddateunix int64
  7084. if len(end_time) > 0 {
  7085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7086. if err != nil {
  7087. utils.ErrorLog(err.Error())
  7088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7089. return
  7090. }
  7091. enddateunix = theTime.Unix()
  7092. }
  7093. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7094. //nowTime := time.Now()
  7095. //endTime := nowTime.AddDate(-30, 0, 0)
  7096. //endTimes := endTime.Format("2006-01-02")
  7097. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7098. org_id := c.GetMobileAdminUserInfo().Org.Id
  7099. //if org_id == 10579 {
  7100. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7101. // c.ServeSuccessJSON(map[string]interface{}{
  7102. // "list": list,
  7103. // })
  7104. // return
  7105. //} else {
  7106. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7107. // c.ServeSuccessJSON(map[string]interface{}{
  7108. // "list": list,
  7109. // })
  7110. // return
  7111. //}
  7112. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7113. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7114. c.ServeSuccessJSON(map[string]interface{}{
  7115. "list": list,
  7116. })
  7117. return
  7118. } else {
  7119. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7120. c.ServeSuccessJSON(map[string]interface{}{
  7121. "list": list,
  7122. })
  7123. }
  7124. return
  7125. }
  7126. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7127. dataBody := make(map[string]interface{}, 0)
  7128. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7129. ids := c.GetString("ids")
  7130. idArray := strings.Split(ids, ",")
  7131. origin, _ := c.GetInt64("origin")
  7132. if origin == 1 {
  7133. err = service.BatchDeleteAdvice(idArray)
  7134. fmt.Print("err", err)
  7135. c.ServeSuccessJSON(map[string]interface{}{
  7136. "msg": "批量删除成功",
  7137. })
  7138. return
  7139. }
  7140. if origin == 2 {
  7141. service.BatchDeleteHisAdvice(idArray)
  7142. }
  7143. }
  7144. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7145. good_id, _ := c.GetInt64("good_id")
  7146. count, _ := c.GetInt64("count")
  7147. record_time, _ := c.GetInt64("record_time")
  7148. patient_id, _ := c.GetInt64("patient_id")
  7149. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7150. c.ServeSuccessJSON(map[string]interface{}{
  7151. "detail": detail,
  7152. })
  7153. return
  7154. }
  7155. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7156. good_id, _ := c.GetInt64("good_id")
  7157. record_time, _ := c.GetInt64("record_time")
  7158. patient_id, _ := c.GetInt64("patient_id")
  7159. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7160. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7161. fmt.Print("err", err)
  7162. c.ServeSuccessJSON(map[string]interface{}{
  7163. "msg": "批量删除成功",
  7164. })
  7165. return
  7166. }
  7167. func (c *DialysisAPIController) BatchAdviceCheck() {
  7168. ids := c.GetString("ids")
  7169. idArray := strings.Split(ids, ",")
  7170. creator, _ := c.GetInt64("creator")
  7171. origin, _ := c.GetInt64("origin")
  7172. if origin == 1 {
  7173. err := service.BatchAdviceCheck(idArray, creator)
  7174. fmt.Println(err)
  7175. list, _ := service.GetAdviceExecutionById(idArray)
  7176. c.ServeSuccessJSON(map[string]interface{}{
  7177. "list": list,
  7178. })
  7179. return
  7180. }
  7181. if origin == 2 {
  7182. service.BatchHisAdviceCheck(idArray, creator)
  7183. list, _ := service.GetHisAdviceExecutionById(idArray)
  7184. c.ServeSuccessJSON(map[string]interface{}{
  7185. "list": list,
  7186. })
  7187. return
  7188. }
  7189. }
  7190. func (c *DialysisAPIController) BatchAdviceExecution() {
  7191. ids := c.GetString("ids")
  7192. idArray := strings.Split(ids, ",")
  7193. executionTime := c.GetString("execution_time")
  7194. creator, _ := c.GetInt64("creator")
  7195. timeLayout := "2006-01-02 15:04:05"
  7196. loc, _ := time.LoadLocation("Local")
  7197. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7198. orgin, _ := c.GetInt64("origin")
  7199. if orgin == 1 {
  7200. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7201. list, _ := service.GetAdviceExecutionById(idArray)
  7202. fmt.Println(err)
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "list": list,
  7205. })
  7206. return
  7207. }
  7208. if orgin == 2 {
  7209. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7210. list, _ := service.GetHisAdviceExecutionById(idArray)
  7211. fmt.Println(err)
  7212. c.ServeSuccessJSON(map[string]interface{}{
  7213. "list": list,
  7214. })
  7215. return
  7216. }
  7217. }
  7218. func (c *DialysisAPIController) UpdateStockGoods() {
  7219. good_id, _ := c.GetInt64("good_id")
  7220. record_time, _ := c.GetInt64("record_time")
  7221. patient_id, _ := c.GetInt64("patient_id")
  7222. count, _ := c.GetInt64("count")
  7223. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7224. fmt.Print("err", err)
  7225. c.ServeSuccessJSON(map[string]interface{}{
  7226. "msg": "更新成功",
  7227. })
  7228. return
  7229. }
  7230. // 当前数据比上一次出库数据少
  7231. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7232. //查询该患者当天已经出库的耗材信息
  7233. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7234. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7235. for i := len(goods_yc) - 1; i >= 0; i-- {
  7236. goods_yc_temp := goods_yc[i]
  7237. for j := len(goods) - 1; j >= 0; j-- {
  7238. goods_temp := goods[j]
  7239. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7240. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7241. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7242. if goods_yc_temp.Count == goods_temp.Count {
  7243. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7244. goods = append(goods[:j], goods[j+1:]...)
  7245. break
  7246. }
  7247. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7248. if goods_yc_temp.Count > goods_temp.Count {
  7249. temp_count := goods_yc_temp.Count - goods_temp.Count
  7250. goods_yc[i].Count = temp_count
  7251. goods = append(goods[:j], goods[j+1:]...)
  7252. break
  7253. }
  7254. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7255. if goods_yc_temp.Count < goods_temp.Count {
  7256. temp_count := goods_temp.Count - goods_yc_temp.Count
  7257. goods[j].Count = temp_count
  7258. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7259. break
  7260. }
  7261. }
  7262. }
  7263. }
  7264. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7265. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7266. //退库
  7267. if len(goods_yc) > 0 {
  7268. for _, good_yc := range goods_yc {
  7269. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7270. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7271. }
  7272. }
  7273. return nil
  7274. }
  7275. // 耗材出库删除
  7276. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7277. // 先根据相关信息查询当天该耗材的出库信息
  7278. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7279. if err != nil {
  7280. return err
  7281. }
  7282. var delete_count int64 = 0
  7283. delete_count = warehouseOutInfos.Count - count
  7284. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7285. // 在出库记录表里记录退库详情
  7286. warehouseOutInfo := &models.WarehouseOutInfo{
  7287. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7288. WarehouseOutId: warehouseOut.ID,
  7289. Status: 1,
  7290. Ctime: time.Now().Unix(),
  7291. OrgId: orgID,
  7292. Type: 1,
  7293. IsSys: 1,
  7294. SysRecordTime: record_time,
  7295. GoodTypeId: good_yc.GoodTypeId,
  7296. GoodId: good_yc.GoodId,
  7297. PatientId: good_yc.PatientId,
  7298. ConsumableType: 2,
  7299. StorehouseId: houseConfig.StorehouseOutInfo,
  7300. IsCheck: 1,
  7301. }
  7302. warehouseOutInfo.Count = count
  7303. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7304. warehouseOutInfo.Price = stockInInfo.Price
  7305. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7306. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7307. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7308. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7309. warehouseOutInfo.Number = warehouseOutInfos.Number
  7310. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7311. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7312. //查找当天是否存在出库记录
  7313. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7314. if errcod == gorm.ErrRecordNotFound {
  7315. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7316. //插入详情明细表
  7317. stockFlow := models.VmStockFlow{
  7318. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7319. WarehouseOutId: warehouseOut.ID,
  7320. GoodId: good_yc.GoodId,
  7321. Number: warehouseOutInfos.Number,
  7322. ProductDate: stockInInfo.ProductDate,
  7323. ExpireDate: stockInInfo.ExpiryDate,
  7324. Count: count,
  7325. Price: stockInInfo.Price,
  7326. Status: 1,
  7327. Ctime: time.Now().Unix(),
  7328. UserOrgId: good_yc.OrgId,
  7329. Manufacturer: stockInInfo.Manufacturer,
  7330. Dealer: stockInInfo.Dealer,
  7331. LicenseNumber: stockInInfo.LicenseNumber,
  7332. IsEdit: 2,
  7333. Creator: creater,
  7334. SystemTime: record_time,
  7335. ConsumableType: 3,
  7336. WarehousingDetailId: 0,
  7337. IsSys: 1,
  7338. UpdateCreator: creater,
  7339. PatientId: patient_id,
  7340. StorehouseId: houseConfig.StorehouseOutInfo,
  7341. }
  7342. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7343. if errflow == gorm.ErrRecordNotFound {
  7344. //创建流水表
  7345. err := service.CreateStockFlowOne(stockFlow)
  7346. fmt.Println("err", err)
  7347. } else if errflow == nil {
  7348. //插入详情明细表
  7349. stockFlow := models.VmStockFlow{
  7350. ID: exsit.ID,
  7351. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7352. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7353. WarehouseOutId: warehouseOut.ID,
  7354. GoodId: good_yc.GoodId,
  7355. Number: warehouseOutInfos.Number,
  7356. ProductDate: stockInInfo.ProductDate,
  7357. ExpireDate: stockInInfo.ExpiryDate,
  7358. Count: exsit.Count - delete_count,
  7359. Price: stockInInfo.Price,
  7360. Status: 1,
  7361. Ctime: time.Now().Unix(),
  7362. UserOrgId: good_yc.OrgId,
  7363. Manufacturer: stockInInfo.Manufacturer,
  7364. Dealer: stockInInfo.Dealer,
  7365. LicenseNumber: stockInInfo.LicenseNumber,
  7366. IsEdit: 2,
  7367. Creator: creater,
  7368. SystemTime: record_time,
  7369. ConsumableType: 3,
  7370. WarehousingDetailId: 0,
  7371. IsSys: 1,
  7372. UpdateCreator: creater,
  7373. PatientId: patient_id,
  7374. StorehouseId: houseConfig.StorehouseOutInfo,
  7375. }
  7376. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7377. }
  7378. if errOne != nil {
  7379. return errOne
  7380. }
  7381. } else if errcod == nil {
  7382. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7383. //插入详情明细表
  7384. stockFlow := models.VmStockFlow{
  7385. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7386. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7387. WarehouseOutId: warehouseOut.ID,
  7388. GoodId: good_yc.GoodId,
  7389. Number: warehouseOutInfos.Number,
  7390. ProductDate: stockInInfo.ProductDate,
  7391. ExpireDate: stockInInfo.ExpiryDate,
  7392. Count: count,
  7393. Price: stockInInfo.Price,
  7394. Status: 1,
  7395. Ctime: time.Now().Unix(),
  7396. UserOrgId: good_yc.OrgId,
  7397. Manufacturer: stockInInfo.Manufacturer,
  7398. Dealer: stockInInfo.Dealer,
  7399. LicenseNumber: stockInInfo.LicenseNumber,
  7400. IsEdit: 2,
  7401. Creator: creater,
  7402. SystemTime: record_time,
  7403. ConsumableType: 3,
  7404. WarehousingDetailId: 0,
  7405. IsSys: 1,
  7406. UpdateCreator: creater,
  7407. PatientId: patient_id,
  7408. ReturnCount: delete_count,
  7409. StorehouseId: houseConfig.StorehouseOutInfo,
  7410. }
  7411. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7412. if errflows == gorm.ErrRecordNotFound {
  7413. //创建流水表
  7414. service.CreateStockFlowOne(stockFlow)
  7415. } else if errflows == nil {
  7416. stockFlow := models.VmStockFlow{
  7417. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7418. ID: exsit.ID,
  7419. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7420. WarehouseOutId: warehouseOut.ID,
  7421. GoodId: good_yc.GoodId,
  7422. Number: warehouseOutInfos.Number,
  7423. ProductDate: stockInInfo.ProductDate,
  7424. ExpireDate: stockInInfo.ExpiryDate,
  7425. Count: exsit.Count - delete_count,
  7426. Price: stockInInfo.Price,
  7427. Status: 1,
  7428. Ctime: time.Now().Unix(),
  7429. UserOrgId: good_yc.OrgId,
  7430. Manufacturer: stockInInfo.Manufacturer,
  7431. Dealer: stockInInfo.Dealer,
  7432. LicenseNumber: stockInInfo.LicenseNumber,
  7433. IsEdit: 2,
  7434. Creator: creater,
  7435. SystemTime: record_time,
  7436. ConsumableType: 3,
  7437. WarehousingDetailId: 0,
  7438. IsSys: 1,
  7439. UpdateCreator: creater,
  7440. PatientId: patient_id,
  7441. ReturnCount: delete_count,
  7442. StorehouseId: houseConfig.StorehouseOutInfo,
  7443. }
  7444. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7445. }
  7446. }
  7447. //更改自动出库的表格
  7448. details := models.BloodAutomaticReduceDetail{
  7449. WarehouseOutId: warehouseOutInfo.ID,
  7450. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7451. PatientId: patient_id,
  7452. Ctime: time.Now().Unix(),
  7453. Mtime: time.Now().Unix(),
  7454. Status: 1,
  7455. RecordTime: record_time,
  7456. OrgId: orgID,
  7457. GoodId: good_yc.GoodId,
  7458. GoodTypeId: good_yc.GoodTypeId,
  7459. Count: count,
  7460. StorehouseId: houseConfig.StorehouseOutInfo,
  7461. }
  7462. //查询当天耗材是否已经存在数据
  7463. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7464. if errcode == gorm.ErrRecordNotFound {
  7465. errTwo := service.CreateAutoReduceRecord(&details)
  7466. if errTwo != nil {
  7467. return errTwo
  7468. }
  7469. } else if errcode == nil {
  7470. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7471. service.CreateAutoReduceRecord(&details)
  7472. }
  7473. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7474. //增加出库库存数量
  7475. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7476. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7477. fmt.Println("errOne", errOne)
  7478. // 删除出库完成后,要增加对应批次的库存数量
  7479. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7480. if errThree != nil {
  7481. return errThree
  7482. }
  7483. if good_yc.Count == 0 {
  7484. return nil
  7485. } else {
  7486. return errors.New("退库和出库数据不匹配")
  7487. }
  7488. }
  7489. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7490. //查询该患者当天已经出库的耗材信息
  7491. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7492. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7493. for i := len(goods_yc) - 1; i >= 0; i-- {
  7494. goods_yc_temp := goods_yc[i]
  7495. for j := len(goods) - 1; j >= 0; j-- {
  7496. goods_temp := goods[j]
  7497. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7498. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7499. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7500. if goods_yc_temp.Count == goods_temp.Count {
  7501. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7502. goods = append(goods[:j], goods[j+1:]...)
  7503. break
  7504. }
  7505. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7506. if goods_yc_temp.Count > goods_temp.Count {
  7507. temp_count := goods_yc_temp.Count - goods_temp.Count
  7508. goods_yc[i].Count = temp_count
  7509. goods = append(goods[:j], goods[j+1:]...)
  7510. break
  7511. }
  7512. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7513. if goods_yc_temp.Count < goods_temp.Count {
  7514. temp_count := goods_temp.Count - goods_yc_temp.Count
  7515. goods[j].Count = temp_count
  7516. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7517. break
  7518. }
  7519. }
  7520. }
  7521. }
  7522. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7523. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7524. fmt.Println("剩余需要出库的", len(goods))
  7525. if len(goods) > 0 {
  7526. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7527. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7528. if err == gorm.ErrRecordNotFound {
  7529. //没有记录,则创建出库单
  7530. timeStr := time.Now().Format("2006-01-02")
  7531. timeArr := strings.Split(timeStr, "-")
  7532. total, _ := service.FindAllWarehouseOut(orgID)
  7533. total = total + 1
  7534. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7535. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7536. number = number + total
  7537. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7538. warehouseOut := models.WarehouseOut{
  7539. WarehouseOutOrderNumber: warehousing_out_order,
  7540. OperationTime: time.Now().Unix(),
  7541. OrgId: orgID,
  7542. Creater: creater,
  7543. Ctime: time.Now().Unix(),
  7544. Status: 1,
  7545. WarehouseOutTime: record_time,
  7546. Dealer: 0,
  7547. Manufacturer: 0,
  7548. Type: 1,
  7549. IsSys: 1,
  7550. StorehouseId: houseConfig.StorehouseOutInfo,
  7551. IsCheck: 1,
  7552. }
  7553. err := service.AddSigleWarehouseOut(&warehouseOut)
  7554. if err != nil {
  7555. utils.TraceLog("创建出库单失败 err = %v", err)
  7556. return err
  7557. } else {
  7558. out = warehouseOut
  7559. }
  7560. }
  7561. for _, item := range goods {
  7562. var newCount int64 = 0
  7563. for _, it := range goodOne {
  7564. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7565. newCount = it.Count
  7566. }
  7567. }
  7568. prepare := models.DialysisBeforePrepare{
  7569. GoodTypeId: item.GoodTypeId,
  7570. GoodId: item.GoodId,
  7571. Count: item.Count,
  7572. StorehouseId: houseConfig.StorehouseOutInfo,
  7573. }
  7574. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7575. //增加出库数量
  7576. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7577. }
  7578. }
  7579. if len(goods_yc) > 0 {
  7580. for _, good_yc := range goods_yc {
  7581. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7582. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7583. }
  7584. }
  7585. return nil
  7586. }
  7587. // 耗材出库删除
  7588. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7589. // 先根据相关信息查询当天该耗材的出库信息
  7590. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7591. if err != nil {
  7592. return err
  7593. }
  7594. var delete_count int64 = 0
  7595. for _, ware := range warehouseOutInfos {
  7596. // 判断当前出库的数据和删除出库数量
  7597. if good_yc.Count <= ware.Count {
  7598. delete_count = good_yc.Count
  7599. } else {
  7600. delete_count = ware.Count
  7601. }
  7602. warehouseOutInfo := &models.WarehouseOutInfo{
  7603. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7604. WarehouseOutId: warehouseOut.ID,
  7605. Status: 1,
  7606. Ctime: time.Now().Unix(),
  7607. Remark: "",
  7608. OrgId: orgID,
  7609. Type: 1,
  7610. Manufacturer: 0,
  7611. Dealer: 0,
  7612. IsSys: 0,
  7613. SysRecordTime: record_time,
  7614. GoodTypeId: good_yc.GoodTypeId,
  7615. GoodId: good_yc.GoodId,
  7616. StorehouseId: warehouseOut.StorehouseId,
  7617. IsCheck: 1,
  7618. }
  7619. warehouseOutInfo.Count = delete_count
  7620. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7621. warehouseOutInfo.Price = stockInInfo.Price
  7622. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7623. if errOne != nil {
  7624. return errOne
  7625. }
  7626. // 删除出库完成后,要改变流水库存(有疑问)
  7627. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7628. fmt.Println("errOne", errOne)
  7629. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7630. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7631. //扣减出库数量
  7632. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7633. if errThree != nil {
  7634. return errThree
  7635. }
  7636. }
  7637. if good_yc.Count == 0 {
  7638. return nil
  7639. } else {
  7640. return errors.New("退库和出库数据不匹配")
  7641. }
  7642. }
  7643. func (this *DialysisAPIController) GetMobileScheduleList() {
  7644. limit, _ := this.GetInt64("limit")
  7645. page, _ := this.GetInt64("page")
  7646. type_options_visible, _ := this.GetInt64("type_options_visible")
  7647. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7648. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7649. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7650. }
  7651. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7652. newArr = make([]*models.HisPrescriptionProject, 0)
  7653. for i := 0; i < len(arr); i++ {
  7654. repeat := false
  7655. for j := i + 1; j < len(arr); j++ {
  7656. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  7657. repeat = true
  7658. break
  7659. }
  7660. }
  7661. if !repeat {
  7662. newArr = append(newArr, arr[i])
  7663. }
  7664. }
  7665. return
  7666. }
  7667. func (this *DialysisAPIController) GetRoleList() {
  7668. admin_user_id, _ := this.GetInt64("admin_user_id")
  7669. orgid := this.GetMobileAdminUserInfo().Org.Id
  7670. list, err := service.GetRoleList(orgid, admin_user_id)
  7671. fmt.Println(err)
  7672. this.ServeSuccessJSON(map[string]interface{}{
  7673. "list": list,
  7674. })
  7675. return
  7676. }
  7677. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7678. // 先根据相关信息查询当天该耗材的出库信息
  7679. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7680. if err != nil {
  7681. return err
  7682. }
  7683. var delete_count int64 = 0
  7684. delete_count = warehouseOutInfos.Count - count
  7685. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7686. // 删除出库完成后,要增加对应批次的库存数量
  7687. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7688. if errThree != nil {
  7689. return errThree
  7690. }
  7691. //增加退库数量
  7692. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7693. //扣减出库数量
  7694. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7695. //查询剩余库存
  7696. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7697. var sum_count int64
  7698. for _, item := range goodList {
  7699. sum_count += item.StockCount
  7700. }
  7701. // 在出库记录表里记录退库详情
  7702. warehouseOutInfo := &models.WarehouseOutInfo{
  7703. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7704. WarehouseOutId: warehouseOut.ID,
  7705. Status: 1,
  7706. Ctime: time.Now().Unix(),
  7707. OrgId: orgID,
  7708. Type: 1,
  7709. IsSys: 1,
  7710. SysRecordTime: record_time,
  7711. GoodTypeId: good_yc.GoodTypeId,
  7712. GoodId: good_yc.GoodId,
  7713. PatientId: good_yc.PatientId,
  7714. ConsumableType: 2,
  7715. StorehouseId: houseConfig.StorehouseOutInfo,
  7716. IsCheck: 1,
  7717. OverCount: sum_count,
  7718. }
  7719. warehouseOutInfo.Count = count
  7720. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7721. warehouseOutInfo.Price = stockInInfo.Price
  7722. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7723. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7724. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7725. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7726. warehouseOutInfo.Number = warehouseOutInfos.Number
  7727. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7728. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7729. //查找当天是否存在出库记录
  7730. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7731. if errcod == gorm.ErrRecordNotFound {
  7732. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7733. //插入详情明细表
  7734. if errOne != nil {
  7735. return errOne
  7736. }
  7737. //插入详情明细表
  7738. stockFlow := models.VmStockFlow{
  7739. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7740. WarehouseOutId: warehouseOut.ID,
  7741. GoodId: good_yc.GoodId,
  7742. Number: warehouseOutInfos.Number,
  7743. ProductDate: stockInInfo.ProductDate,
  7744. ExpireDate: stockInInfo.ExpiryDate,
  7745. Count: count,
  7746. Price: stockInInfo.Price,
  7747. Status: 1,
  7748. Ctime: record_time,
  7749. UserOrgId: good_yc.OrgId,
  7750. Manufacturer: stockInInfo.Manufacturer,
  7751. Dealer: stockInInfo.Dealer,
  7752. LicenseNumber: stockInInfo.LicenseNumber,
  7753. IsEdit: 2,
  7754. Creator: creater,
  7755. SystemTime: record_time,
  7756. ConsumableType: 3,
  7757. WarehousingDetailId: 0,
  7758. IsSys: 1,
  7759. UpdateCreator: creater,
  7760. PatientId: patient_id,
  7761. StorehouseId: houseConfig.StorehouseOutInfo,
  7762. OverCount: sum_count,
  7763. ProjectId: good_yc.ProjectId,
  7764. }
  7765. err := service.CreateStockFlowOne(stockFlow)
  7766. fmt.Println("err", err)
  7767. } else if errcod == nil {
  7768. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7769. }
  7770. //创建退库单
  7771. operation_time := time.Now().Unix()
  7772. //创建退库单
  7773. timeStr := time.Now().Format("2006-01-02")
  7774. timeArr := strings.Split(timeStr, "-")
  7775. total, _ := service.FindAllCancelStockTotal(orgID)
  7776. total = total + 1
  7777. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7778. cancelStock := models.CancelStock{
  7779. OrderNumber: orderNumber,
  7780. OperaTime: operation_time,
  7781. OrgId: orgID,
  7782. Creater: warehouseOut.Creater,
  7783. Ctime: time.Now().Unix(),
  7784. Status: 1,
  7785. ReturnTime: record_time,
  7786. Type: 1,
  7787. StorehouseId: stockInInfo.StorehouseId,
  7788. IsCheck: 1,
  7789. }
  7790. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7791. if msgerrkonde == gorm.ErrRecordNotFound {
  7792. service.AddSigleCancelStock(&cancelStock)
  7793. }
  7794. cancel, _ := service.GetLastCancelStockById(orgID)
  7795. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7796. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7797. cancelStockInfo := models.CancelStockInfo{
  7798. GoodId: stockInInfo.GoodId,
  7799. CancelStockId: cancel.ID,
  7800. GoodTypeId: stockInInfo.GoodTypeId,
  7801. Count: delete_count,
  7802. Price: stockInInfo.PackingPrice,
  7803. Total: 0,
  7804. ProductDate: stockInInfo.ProductDate,
  7805. ExpiryDate: stockInInfo.ExpiryDate,
  7806. Ctime: record_time,
  7807. Status: 1,
  7808. OrgId: orgID,
  7809. OrderNumber: cancel.OrderNumber,
  7810. Type: 0,
  7811. Dealer: deaerler.DealerName,
  7812. Manufacturer: manufacturer.ManufacturerName,
  7813. Number: stockInInfo.Number,
  7814. RegisterAccount: "",
  7815. Remark: "",
  7816. WarehouseInfoId: stockInInfo.ID,
  7817. PatientId: patient_id,
  7818. RecordDate: record_time,
  7819. StorehouseId: stockInInfo.StorehouseId,
  7820. IsCheck: 1,
  7821. }
  7822. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7823. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7824. flow := models.VmStockFlow{
  7825. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7826. GoodId: good_yc.GoodId,
  7827. Number: warehouseOutInfos.Number,
  7828. LicenseNumber: stockInInfo.LicenseNumber,
  7829. Count: delete_count,
  7830. UserOrgId: orgID,
  7831. PatientId: patient_id,
  7832. SystemTime: record_time,
  7833. ConsumableType: 7,
  7834. IsSys: 0,
  7835. WarehousingOrder: "",
  7836. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7837. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7838. IsEdit: 0,
  7839. CancelStockId: cancel.ID,
  7840. CancelOrderNumber: cancel.OrderNumber,
  7841. Manufacturer: manufacturer.ID,
  7842. Dealer: 0,
  7843. Creator: warehouseOut.Creater,
  7844. UpdateCreator: 0,
  7845. Status: 1,
  7846. Ctime: record_time,
  7847. Mtime: 0,
  7848. Price: stockInInfo.Price,
  7849. WarehousingDetailId: stockInInfo.ID,
  7850. WarehouseOutDetailId: warehouseOutInfos.ID,
  7851. CancelOutDetailId: cancelInfo.ID,
  7852. ProductDate: stockInInfo.ProductDate,
  7853. ExpireDate: stockInInfo.ExpiryDate,
  7854. StorehouseId: houseConfig.StorehouseOutInfo,
  7855. OverCount: sum_count,
  7856. }
  7857. service.CreateStockFlowOne(flow)
  7858. //更改自动出库的表格
  7859. details := models.BloodAutomaticReduceDetail{
  7860. WarehouseOutId: warehouseOutInfo.ID,
  7861. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7862. PatientId: patient_id,
  7863. Ctime: time.Now().Unix(),
  7864. Mtime: time.Now().Unix(),
  7865. Status: 1,
  7866. RecordTime: record_time,
  7867. OrgId: orgID,
  7868. GoodId: good_yc.GoodId,
  7869. GoodTypeId: good_yc.GoodTypeId,
  7870. Count: count,
  7871. StorehouseId: houseConfig.StorehouseOutInfo,
  7872. }
  7873. //查询当天耗材是否已经存在数据
  7874. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7875. if errcode == gorm.ErrRecordNotFound {
  7876. errTwo := service.CreateAutoReduceRecord(&details)
  7877. if errTwo != nil {
  7878. return errTwo
  7879. }
  7880. } else if errcode == nil {
  7881. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7882. service.CreateAutoReduceRecord(&details)
  7883. }
  7884. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7885. //增加出库库存数量
  7886. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7887. if good_yc.Count == 0 {
  7888. return nil
  7889. } else {
  7890. return errors.New("退库和出库数据不匹配")
  7891. }
  7892. }
  7893. func (this *DialysisAPIController) SavePatientSign() {
  7894. adminUserInfo := this.GetMobileAdminUserInfo()
  7895. patient_id, _ := this.GetInt64("patient_id")
  7896. dialysis_date, _ := this.GetInt64("dialysis_date")
  7897. orgid := adminUserInfo.Org.Id
  7898. var esdata models.DialysisOrder
  7899. var err error
  7900. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  7901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7902. return
  7903. }
  7904. esdata.Hash = esdata.Hash
  7905. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  7906. order := models.DialysisOrder{
  7907. Hash: esdata.Hash,
  7908. Url: esdata.Url,
  7909. }
  7910. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  7911. redis := service.RedisClient()
  7912. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7913. redis.Set(key, "", time.Second)
  7914. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7915. //清空key 值
  7916. redis.Set(keyOne, "", time.Second)
  7917. //scheduleDateStartOne := startDate.Format("2006-01-02")
  7918. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  7919. //redis.Set(keyTwo, "", time.Second)
  7920. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7921. redis.Set(keyThree, "", time.Second)
  7922. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7923. redis.Set(keyFour, "", time.Second)
  7924. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7925. redis.Set(keyFive, "", time.Second)
  7926. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7927. redis.Set(keySix, "", time.Second)
  7928. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  7929. redis.Set(keySeven, "", time.Second)
  7930. if err != nil {
  7931. fmt.Println(err)
  7932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7933. return
  7934. }
  7935. this.ServeSuccessJSON(map[string]interface{}{
  7936. "electronic_signature": esdata,
  7937. })
  7938. }
  7939. func (this *DialysisAPIController) GetPatientSign() {
  7940. patient_id, _ := this.GetInt64("patient_id")
  7941. dialysis_date, _ := this.GetInt64("dialysis_date")
  7942. adminUserInfo := this.GetMobileAdminUserInfo()
  7943. orgId := adminUserInfo.Org.Id
  7944. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  7945. if err != nil {
  7946. fmt.Println(err)
  7947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7948. return
  7949. }
  7950. this.ServeSuccessJSON(map[string]interface{}{
  7951. "dialysisOrder": dialysisOrder,
  7952. })
  7953. }
  7954. func (this *DialysisAPIController) GetScheduleByPatient() {
  7955. patient_id, _ := this.GetInt64("patient_id")
  7956. schedule_date, _ := this.GetInt64("schedule_date")
  7957. orgid := this.GetMobileAdminUserInfo().Org.Id
  7958. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  7959. this.ServeSuccessJSON(map[string]interface{}{
  7960. "schedule": schedule,
  7961. })
  7962. }
  7963. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  7964. org_id := this.GetMobileAdminUserInfo().Org.Id
  7965. patient_id, _ := this.GetInt64("patient_id")
  7966. schedule_date, _ := this.GetInt64("schedule_date")
  7967. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  7968. this.ServeSuccessJSON(map[string]interface{}{
  7969. "order": order,
  7970. })
  7971. }
  7972. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  7973. org_id := this.GetMobileAdminUserInfo().Org.Id
  7974. schedule_date := this.GetString("schedule_date")
  7975. schedule_type, _ := this.GetInt64("schedule_type")
  7976. timeLayout := "2006-01-02"
  7977. loc, _ := time.LoadLocation("Local")
  7978. var startdateunix int64
  7979. if len(schedule_date) > 0 {
  7980. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  7981. if err != nil {
  7982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7983. return
  7984. }
  7985. startdateunix = theTime.Unix()
  7986. }
  7987. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  7988. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  7989. devices, _ := service.GetAllDevicetByListSix(org_id)
  7990. for key, item := range scheduals {
  7991. // 床位信息
  7992. for _, device := range devices {
  7993. if item.BedId == device.ID {
  7994. scheduals[key].DeviceNumber = device
  7995. break
  7996. }
  7997. }
  7998. }
  7999. this.ServeSuccessJSON(map[string]interface{}{
  8000. "list": list,
  8001. "scheduals": scheduals,
  8002. })
  8003. }
  8004. func (this *DialysisAPIController) SavePatientPicture() {
  8005. patient_id, _ := this.GetInt64("patient_id")
  8006. dialysis_date, _ := this.GetInt64("schedule_date")
  8007. avatar := this.GetString("avatar")
  8008. fmt.Println("patient_id", patient_id)
  8009. orgId := this.GetMobileAdminUserInfo().Org.Id
  8010. order := models.DialysisOrder{
  8011. Url: avatar,
  8012. }
  8013. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8014. redis := service.RedisClient()
  8015. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8016. redis.Set(key, "", time.Second)
  8017. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8018. //清空key 值
  8019. redis.Set(keyOne, "", time.Second)
  8020. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8021. redis.Set(keyThree, "", time.Second)
  8022. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8023. redis.Set(keyFour, "", time.Second)
  8024. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8025. redis.Set(keyFive, "", time.Second)
  8026. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8027. redis.Set(keySix, "", time.Second)
  8028. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8029. redis.Set(keySeven, "", time.Second)
  8030. if err != nil {
  8031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8032. return
  8033. }
  8034. this.ServeSuccessJSON(map[string]interface{}{
  8035. "order": order,
  8036. })
  8037. }
  8038. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8039. ids := this.GetString("ids")
  8040. idSplit := strings.Split(ids, ",")
  8041. orgId := this.GetMobileAdminUserInfo().Org.Id
  8042. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8043. execution_time := this.GetString("exce_time")
  8044. timeLayout2 := "2006-01-02 15:04:05"
  8045. loc, _ := time.LoadLocation("Local")
  8046. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8047. if errs != nil {
  8048. utils.ErrorLog(errs.Error())
  8049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8050. return
  8051. }
  8052. //his客户
  8053. if config.IsOpen == 1 {
  8054. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8055. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8056. for _, item := range list {
  8057. for _, it := range adviceList {
  8058. if item.DrugId == it.DrugId {
  8059. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8060. }
  8061. }
  8062. }
  8063. for _, item := range list {
  8064. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8065. var sum_out_count int64
  8066. for _, itemThree := range item.ChildDoctorAdvice {
  8067. var prescribing_number int64
  8068. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8069. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8070. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8071. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8072. }
  8073. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8074. prescribing_number = parseIntPrescribingNumber
  8075. }
  8076. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8077. prescribing_number = parseIntPrescribingNumber
  8078. }
  8079. sum_out_count += prescribing_number
  8080. }
  8081. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8082. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8083. //库存不足
  8084. if sum_out_count > drugStockOut.FlushCount {
  8085. this.ServeSuccessJSON(map[string]interface{}{
  8086. "msg": "2",
  8087. "drug": medical,
  8088. "ids": ids,
  8089. })
  8090. return
  8091. }
  8092. }
  8093. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8094. //执行医嘱
  8095. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8096. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8097. for _, item := range advices {
  8098. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8099. redis := service.RedisClient()
  8100. //清空key 值
  8101. redis.Set(key, "", time.Second)
  8102. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8103. redis.Set(keyTwo, "", time.Second)
  8104. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8105. redis.Set(keyThree, "", time.Second)
  8106. recordDate := theTime.Format("2006-01-02")
  8107. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8108. redis.Set(keyFour, "", time.Second)
  8109. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8110. redis.Set(keyFive, "", time.Second)
  8111. defer redis.Close()
  8112. }
  8113. if errs == nil {
  8114. //药品管理信息
  8115. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8116. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8117. if drugStockConfig.IsOpen == 1 {
  8118. for _, item := range advices {
  8119. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8120. config, _ := service.GetDrugOpenConfigOne(orgId)
  8121. if config.IsOpen != 1 {
  8122. //查询该药品是否有库存
  8123. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8124. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8125. if medical.IsUse == 2 {
  8126. if config.IsOpen != 1 {
  8127. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8128. service.HisDrugsDelivery(orgId, creater, &advice)
  8129. if orgId == 3877 || orgId == 10265 {
  8130. //查询该药品是否有出库记录
  8131. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8132. if len(flowMap) == 0 {
  8133. errs := service.UpdateHisAdviceById(advice.ID)
  8134. if errs != nil {
  8135. drugError := models.XtDrugError{
  8136. UserOrgId: orgId,
  8137. DrugId: item.DrugId,
  8138. RecordDate: item.AdviceDate,
  8139. PatientId: item.PatientId,
  8140. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8141. Status: 1,
  8142. Ctime: time.Now().Unix(),
  8143. Mtime: 0,
  8144. SumCount: 0,
  8145. Prescribingnumber: advice.PrescribingNumber,
  8146. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8147. }
  8148. service.CreateDrugError(drugError)
  8149. }
  8150. this.ServeSuccessJSON(map[string]interface{}{
  8151. "msg": "2",
  8152. "drug": medical,
  8153. "ids": ids,
  8154. })
  8155. return
  8156. }
  8157. }
  8158. }
  8159. if pharmacyConfig.IsOpen != 1 {
  8160. service.HisDrugsDelivery(orgId, creater, &advice)
  8161. if orgId == 3877 || orgId == 10265 {
  8162. //查询该药品是否有出库记录
  8163. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8164. if len(flowMap) == 0 {
  8165. errs := service.UpdateHisAdviceById(advice.ID)
  8166. if errs != nil {
  8167. drugError := models.XtDrugError{
  8168. UserOrgId: orgId,
  8169. DrugId: item.DrugId,
  8170. RecordDate: item.AdviceDate,
  8171. PatientId: item.PatientId,
  8172. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8173. Status: 1,
  8174. Ctime: time.Now().Unix(),
  8175. Mtime: 0,
  8176. SumCount: 0,
  8177. Prescribingnumber: advice.PrescribingNumber,
  8178. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8179. }
  8180. service.CreateDrugError(drugError)
  8181. }
  8182. this.ServeSuccessJSON(map[string]interface{}{
  8183. "msg": "2",
  8184. "drug": medical,
  8185. "ids": ids,
  8186. })
  8187. return
  8188. }
  8189. }
  8190. }
  8191. //更新字典里面的库存
  8192. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8193. var sum_count int64
  8194. for _, its := range stockInfo {
  8195. if its.MaxUnit == medical.MaxUnit {
  8196. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8197. }
  8198. sum_count += its.StockMaxNumber + its.StockMinNumber
  8199. }
  8200. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8201. //剩余库存
  8202. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8203. }
  8204. }
  8205. }
  8206. }
  8207. }
  8208. this.ServeSuccessJSON(map[string]interface{}{
  8209. "msg": "1",
  8210. "ids": ids,
  8211. })
  8212. return
  8213. } else {
  8214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8215. }
  8216. }
  8217. //血透客户
  8218. if config.IsOpen == 2 || config.IsOpen == 0 {
  8219. //药品管理信息
  8220. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8221. if drugStockConfig.IsOpen == 1 {
  8222. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8223. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8224. for _, item := range list {
  8225. for _, it := range adviceList {
  8226. if item.DrugId == it.DrugId {
  8227. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8228. }
  8229. }
  8230. }
  8231. for _, item := range list {
  8232. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8233. var sum_out_count int64
  8234. for _, itemThree := range item.ChildDoctorAdvice {
  8235. var prescribing_number int64
  8236. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8237. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8238. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8239. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8240. }
  8241. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8242. prescribing_number = parseIntPrescribingNumber
  8243. }
  8244. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8245. prescribing_number = parseIntPrescribingNumber
  8246. }
  8247. sum_out_count += prescribing_number
  8248. }
  8249. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8250. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8251. //库存不足
  8252. if sum_out_count > drugStockOut.FlushCount {
  8253. this.ServeSuccessJSON(map[string]interface{}{
  8254. "msg": "2",
  8255. "drug": medical,
  8256. "ids": ids,
  8257. })
  8258. return
  8259. }
  8260. }
  8261. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8262. //执行医嘱
  8263. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8264. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8265. for _, item := range advices {
  8266. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8267. redis := service.RedisClient()
  8268. //清空key 值
  8269. redis.Set(key, "", time.Second)
  8270. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8271. redis.Set(keyTwo, "", time.Second)
  8272. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8273. redis.Set(keyThree, "", time.Second)
  8274. recordDate := theTime.Format("2006-01-02")
  8275. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8276. redis.Set(keyFour, "", time.Second)
  8277. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8278. redis.Set(keyFive, "", time.Second)
  8279. defer redis.Close()
  8280. }
  8281. if errs == nil {
  8282. for _, item := range advices {
  8283. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8284. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8285. //查询是否出库按钮开启
  8286. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8287. if adviceSetting.IsAdviceOpen == 1 {
  8288. //查询是否出库按钮开启
  8289. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8290. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8291. if prescriptionConfig.IsOpen == 1 {
  8292. if medical.IsUse == 2 {
  8293. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8294. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8295. }
  8296. if pharmacyConfig.IsOpen != 1 {
  8297. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8298. }
  8299. //更新字典里面的库存
  8300. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8301. var sum_count int64
  8302. for _, its := range stockInfo {
  8303. if its.MaxUnit == medical.MaxUnit {
  8304. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8305. }
  8306. sum_count += its.StockMaxNumber + its.StockMinNumber
  8307. }
  8308. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8309. //剩余库存
  8310. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8311. }
  8312. }
  8313. } else {
  8314. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8315. if medical.IsUse == 2 {
  8316. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8317. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8318. }
  8319. if pharmacyConfig.IsOpen != 1 {
  8320. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8321. }
  8322. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8323. var sum_count int64
  8324. for _, its := range stockInfo {
  8325. if its.MaxUnit == medical.MaxUnit {
  8326. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8327. }
  8328. sum_count += its.StockMaxNumber + its.StockMinNumber
  8329. }
  8330. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8331. //剩余库存
  8332. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8333. }
  8334. }
  8335. }
  8336. }
  8337. this.ServeSuccessJSON(map[string]interface{}{
  8338. "msg": "1",
  8339. "ids": ids,
  8340. })
  8341. return
  8342. } else {
  8343. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8344. //执行医嘱
  8345. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8346. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8347. for _, item := range advices {
  8348. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8349. redis := service.RedisClient()
  8350. //清空key 值
  8351. redis.Set(key, "", time.Second)
  8352. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8353. redis.Set(keyTwo, "", time.Second)
  8354. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8355. redis.Set(keyThree, "", time.Second)
  8356. recordDate := theTime.Format("2006-01-02")
  8357. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8358. redis.Set(keyFour, "", time.Second)
  8359. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8360. redis.Set(keyFive, "", time.Second)
  8361. defer redis.Close()
  8362. }
  8363. this.ServeSuccessJSON(map[string]interface{}{
  8364. "msg": "1",
  8365. "ids": ids,
  8366. })
  8367. return
  8368. }
  8369. }
  8370. }
  8371. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8372. ids := this.GetString("ids")
  8373. idSplit := strings.Split(ids, ",")
  8374. orgId := this.GetMobileAdminUserInfo().Org.Id
  8375. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8376. if config.IsOpen == 1 {
  8377. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8378. this.ServeSuccessJSON(map[string]interface{}{
  8379. "msg": "1",
  8380. "ids": ids,
  8381. })
  8382. return
  8383. }
  8384. if config.IsOpen == 0 || config.IsOpen == 2 {
  8385. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8386. this.ServeSuccessJSON(map[string]interface{}{
  8387. "msg": "1",
  8388. "ids": ids,
  8389. })
  8390. return
  8391. }
  8392. }
  8393. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8394. ids := this.GetString("ids")
  8395. idSplit := strings.Split(ids, ",")
  8396. orgId := this.GetMobileAdminUserInfo().Org.Id
  8397. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8398. //his
  8399. if config.IsOpen == 1 {
  8400. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8401. theTime := time.Now()
  8402. advices := models.HisDoctorAdviceThirty{
  8403. CheckTime: theTime.Unix(),
  8404. Checker: checker,
  8405. UpdatedTime: time.Now().Unix(),
  8406. }
  8407. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8408. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8409. for _, item := range list {
  8410. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8411. redis := service.RedisClient()
  8412. //清空key 值
  8413. redis.Set(key, "", time.Second)
  8414. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8415. redis.Set(keyTwo, "", time.Second)
  8416. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8417. redis.Set(keyThree, "", time.Second)
  8418. recordDate := theTime.Format("2006-01-02")
  8419. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8420. redis.Set(keyFour, "", time.Second)
  8421. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8422. redis.Set(keyFive, "", time.Second)
  8423. defer redis.Close()
  8424. }
  8425. this.ServeSuccessJSON(map[string]interface{}{
  8426. "msg": "1",
  8427. "ids": ids,
  8428. })
  8429. return
  8430. }
  8431. //血透
  8432. if config.IsOpen == 0 || config.IsOpen == 2 {
  8433. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8434. theTime := time.Now()
  8435. advices := models.DoctorAdvice{
  8436. CheckTime: theTime.Unix(),
  8437. Checker: checker,
  8438. UpdatedTime: time.Now().Unix(),
  8439. }
  8440. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8441. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8442. for _, item := range list {
  8443. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8444. redis := service.RedisClient()
  8445. //清空key 值
  8446. redis.Set(key, "", time.Second)
  8447. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8448. redis.Set(keyTwo, "", time.Second)
  8449. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8450. redis.Set(keyThree, "", time.Second)
  8451. recordDate := theTime.Format("2006-01-02")
  8452. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8453. redis.Set(keyFour, "", time.Second)
  8454. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8455. redis.Set(keyFive, "", time.Second)
  8456. defer redis.Close()
  8457. }
  8458. this.ServeSuccessJSON(map[string]interface{}{
  8459. "msg": "1",
  8460. "ids": ids,
  8461. })
  8462. return
  8463. }
  8464. }
  8465. func (this *DialysisAPIController) CheckSchedule() {
  8466. patientID, _ := this.GetInt64("patient_id")
  8467. recordDateStr := this.GetString("record_date")
  8468. nurseID, _ := this.GetInt64("start_nurse")
  8469. schedual_type, _ := this.GetInt64("schedual_type")
  8470. bedID, _ := this.GetInt64("bed")
  8471. start_time := this.GetString("start_time")
  8472. fmt.Println("patientID", patientID)
  8473. fmt.Println("recordDateStr", recordDateStr)
  8474. fmt.Println("nurseID", nurseID)
  8475. fmt.Println("schedual_type------", schedual_type)
  8476. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8478. return
  8479. }
  8480. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8481. if parseStartDateErr != nil {
  8482. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8484. return
  8485. }
  8486. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8487. if parseErr != nil {
  8488. this.ErrorLog("时间解析失败:%v", parseErr)
  8489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8490. return
  8491. }
  8492. adminUserInfo := this.GetMobileAdminUserInfo()
  8493. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8494. if getPatientErr != nil {
  8495. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8497. return
  8498. } else if patient == nil {
  8499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8500. return
  8501. }
  8502. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8503. if getNurseErr != nil {
  8504. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8506. return
  8507. } else if nurse == nil {
  8508. this.ErrorLog("护士不存在")
  8509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8510. return
  8511. }
  8512. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8513. if getDeviceNumberErr != nil {
  8514. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8516. return
  8517. } else if deviceNumber == nil {
  8518. this.ErrorLog("床位号不存在")
  8519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8520. return
  8521. }
  8522. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8523. if getRecordErr != nil {
  8524. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8526. return
  8527. } else if dialysisRecord != nil {
  8528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8529. return
  8530. }
  8531. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8532. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8533. timeLayout := "2006-01-02 15:04:05"
  8534. loc, _ := time.LoadLocation("Local")
  8535. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8536. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8537. schedulestartTime := theStartTime.Unix()
  8538. scheduleendTime := theEndTime.Unix()
  8539. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8540. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8541. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8542. //查询该床位是否有人用了
  8543. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8544. if err == nil {
  8545. if schedule.ID == 0 {
  8546. this.ServeSuccessJSON(map[string]interface{}{
  8547. "status": 0,
  8548. "msg": "请求失败",
  8549. })
  8550. } else {
  8551. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8552. if order.ID > 0 { //该机位被其他人占用了
  8553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8554. return
  8555. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8556. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8557. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8558. this.ServeSuccessJSON(map[string]interface{}{
  8559. "status": 1,
  8560. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8561. })
  8562. return
  8563. } else {
  8564. this.ServeSuccessJSON(map[string]interface{}{
  8565. "status": 0,
  8566. "msg": "",
  8567. })
  8568. }
  8569. }
  8570. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8571. this.ServeSuccessJSON(map[string]interface{}{
  8572. "status": 2,
  8573. "msg": "当前机位已有患者在使用,请重新选择!",
  8574. })
  8575. }
  8576. }
  8577. } else {
  8578. this.ServeSuccessJSON(map[string]interface{}{
  8579. "status": 0,
  8580. "msg": "",
  8581. })
  8582. }
  8583. }
  8584. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8585. orgId := this.GetMobileAdminUserInfo().Org.Id
  8586. schedule_type, _ := this.GetInt64("schedule_type")
  8587. partion_type, _ := this.GetInt64("partion_type")
  8588. start_time := this.GetString("start_time")
  8589. timeLayout := "2006-01-02"
  8590. loc, _ := time.LoadLocation("Local")
  8591. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8592. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8593. _, config := service.FindXTHisRecordByOrgId(orgId)
  8594. appId := this.GetMobileAdminUserInfo().App.Id
  8595. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8596. if err == nil {
  8597. this.ServeSuccessJSON(map[string]interface{}{
  8598. "list": list,
  8599. "config": config,
  8600. "doctorList": doctorList,
  8601. })
  8602. return
  8603. } else {
  8604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8605. return
  8606. }
  8607. }
  8608. func (this *DialysisAPIController) SaveMobileInformation() {
  8609. patient_id, _ := this.GetInt64("patient_id")
  8610. record_date, _ := this.GetInt64("record_date")
  8611. startTime := this.GetString("start_time")
  8612. module, _ := this.GetInt64("module")
  8613. remark := this.GetString("remark")
  8614. timeLayout := "2006-01-02 15:04"
  8615. loc, _ := time.LoadLocation("Local")
  8616. if len(startTime) == 0 {
  8617. utils.ErrorLog("len(start_time) == 0")
  8618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8619. return
  8620. }
  8621. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8622. if err != nil {
  8623. utils.ErrorLog(err.Error())
  8624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8625. return
  8626. }
  8627. StartTime := theTime.Unix()
  8628. fmt.Println("startime-------------", StartTime)
  8629. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8630. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8631. information := models.XtDialysisInformation{
  8632. Module: module,
  8633. PatientId: patient_id,
  8634. RecordDate: record_date,
  8635. ApplicationDate: StartTime,
  8636. Creater: creater,
  8637. ApplicationStatus: 2,
  8638. Checker: 0,
  8639. CheckTime: 0,
  8640. Remark: remark,
  8641. UserOrgId: user_org_id,
  8642. Ctime: time.Now().Unix(),
  8643. Status: 1,
  8644. Mtime: 0,
  8645. }
  8646. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8647. if infor.ID == 0 {
  8648. service.SaveDialysisInformation(information)
  8649. }
  8650. if infor.ID > 0 {
  8651. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8652. }
  8653. this.ServeSuccessJSON(map[string]interface{}{
  8654. "information": information,
  8655. })
  8656. return
  8657. }
  8658. func (this *DialysisAPIController) GetMobileInformation() {
  8659. limit, _ := this.GetInt64("limit")
  8660. page, _ := this.GetInt64("page")
  8661. orgid := this.GetMobileAdminUserInfo().Org.Id
  8662. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8663. appid := this.GetMobileAdminUserInfo().App.Id
  8664. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8665. patients, _ := service.GetAllpatientThirty(orgid)
  8666. this.ServeSuccessJSON(map[string]interface{}{
  8667. "information": information,
  8668. "total": total,
  8669. "doclist": doclist,
  8670. "patients": patients,
  8671. })
  8672. return
  8673. }
  8674. func (this *DialysisAPIController) GetMobileInformationOne() {
  8675. limit, _ := this.GetInt64("limit")
  8676. page, _ := this.GetInt64("page")
  8677. orgid := this.GetMobileAdminUserInfo().Org.Id
  8678. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8679. appid := this.GetMobileAdminUserInfo().App.Id
  8680. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8681. patients, _ := service.GetAllpatientThirty(orgid)
  8682. this.ServeSuccessJSON(map[string]interface{}{
  8683. "information": information,
  8684. "total": total,
  8685. "doclist": doclist,
  8686. "patients": patients,
  8687. })
  8688. return
  8689. }
  8690. func (this *DialysisAPIController) CheckMobileInformation() {
  8691. id, _ := this.GetInt64("id")
  8692. application_status, _ := this.GetInt64("application_status")
  8693. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8694. checktime := time.Now().Unix()
  8695. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8696. if err == nil {
  8697. this.ServeSuccessJSON(map[string]interface{}{
  8698. "msg": "ok",
  8699. })
  8700. return
  8701. }
  8702. }
  8703. func (c *DialysisAPIController) GetControlMonitorList() {
  8704. partition, _ := c.GetInt64("partition")
  8705. monitorDate := c.GetString("date")
  8706. patient_id, _ := c.GetInt64("patient_id")
  8707. pat_type, _ := c.GetInt64("pat_type")
  8708. timeLayout := "2006-01-02"
  8709. loc, _ := time.LoadLocation("Local")
  8710. var theStartTime int64
  8711. if len(monitorDate) > 0 {
  8712. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8713. if err != nil {
  8714. theStartTime = 0
  8715. }
  8716. theStartTime = theTime.Unix()
  8717. }
  8718. adminInfo := c.GetMobileAdminUserInfo()
  8719. orgID := adminInfo.Org.Id
  8720. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8721. if err != nil {
  8722. c.ErrorLog("获取排班信息失败:%v", err)
  8723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8724. } else {
  8725. if len(monitor) > 0 {
  8726. //获取所有床位
  8727. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8728. //获取所有分区
  8729. zoneList, _ := service.GetAllZoneByList(orgID)
  8730. //获取透析处方
  8731. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8732. //获取透前评估
  8733. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8734. //获取上机
  8735. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8736. //获取透后
  8737. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8738. //获取透后监测
  8739. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8740. //获取所有的患者
  8741. patients, _ := service.GetAllPatientListByListOne(orgID)
  8742. //获取所有透析模式
  8743. treatments, _ := service.GetAllTreatModeByList(orgID)
  8744. //获取所有医嘱
  8745. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8746. //获取双人核对
  8747. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8748. //治疗小结
  8749. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8750. //待消毒
  8751. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8752. for key, item := range monitor {
  8753. // 获取床位信息
  8754. for _, it := range numberList {
  8755. if item.BedId == it.ID {
  8756. monitor[key].DeviceNumber = it
  8757. break
  8758. }
  8759. }
  8760. //获取分区信息
  8761. for _, it := range zoneList {
  8762. if item.PartitionId == it.ID {
  8763. monitor[key].DeviceZone = it
  8764. }
  8765. }
  8766. for _, prescription := range prescriptions {
  8767. if item.PatientId == prescription.PatientId {
  8768. monitor[key].Prescription = prescription
  8769. break
  8770. }
  8771. }
  8772. for _, it := range checkList {
  8773. if item.PatientId == it.PatientId {
  8774. monitor[key].DoubleCheck = it
  8775. break
  8776. }
  8777. }
  8778. for _, it := range summaryList {
  8779. if item.PatientId == it.PatientId {
  8780. monitor[key].TreatmentSummaryForList = it
  8781. break
  8782. }
  8783. }
  8784. // 透前评估
  8785. for _, assessmentBefore := range assessmentBefores {
  8786. if item.PatientId == assessmentBefore.PatientId {
  8787. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8788. break
  8789. }
  8790. }
  8791. // 透析上下机
  8792. for _, dialysisOrder := range dialysisOrders {
  8793. if item.PatientId == dialysisOrder.PatientId {
  8794. monitor[key].DialysisOrder = dialysisOrder
  8795. break
  8796. }
  8797. }
  8798. // 治疗小节
  8799. for _, afterDislysis := range AssessmentAfterDislysis {
  8800. if item.PatientId == afterDislysis.PatientId {
  8801. monitor[key].AssessmentAfterDislysis = afterDislysis
  8802. break
  8803. }
  8804. }
  8805. for _, it := range monitorlist {
  8806. if item.PatientId == it.PatientId {
  8807. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8808. }
  8809. }
  8810. for _, it := range adviceList {
  8811. if item.PatientId == it.PatientId {
  8812. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8813. }
  8814. }
  8815. for _, patient := range patients {
  8816. if item.PatientId == patient.ID {
  8817. monitor[key].MonitorPatients = patient
  8818. break
  8819. }
  8820. }
  8821. for _, treatment := range treatments {
  8822. if item.ModeId == treatment.ID {
  8823. monitor[key].TreatmentMode = treatment
  8824. break
  8825. }
  8826. }
  8827. for _, infor := range informationList {
  8828. if item.PatientId == infor.PatientId {
  8829. monitor[key].NewDeviceInformation = infor
  8830. break
  8831. }
  8832. }
  8833. }
  8834. }
  8835. }
  8836. patients, err := service.GetAllpatientFourty(orgID)
  8837. var mds []*models.NewMonitorDialysisScheduleList
  8838. if pat_type == 0 {
  8839. for _, item := range monitor {
  8840. mds = append(mds, item)
  8841. }
  8842. }
  8843. //待医嘱核对
  8844. if pat_type == 1 {
  8845. for _, item := range monitor {
  8846. if len(item.AdviceList) > 0 {
  8847. mds = append(mds, item)
  8848. }
  8849. }
  8850. }
  8851. //待开小结
  8852. if pat_type == 2 {
  8853. for _, item := range monitor {
  8854. if item.TreatmentSummaryForList == nil {
  8855. mds = append(mds, item)
  8856. }
  8857. }
  8858. }
  8859. //待下机
  8860. if pat_type == 3 {
  8861. for _, item := range monitor {
  8862. if item.DialysisOrder != nil {
  8863. if item.DialysisOrder.ID > 0 {
  8864. mds = append(mds, item)
  8865. }
  8866. }
  8867. }
  8868. }
  8869. //待消毒
  8870. if pat_type == 4 {
  8871. for _, item := range monitor {
  8872. if item.NewDeviceInformation == nil {
  8873. mds = append(mds, item)
  8874. }
  8875. }
  8876. }
  8877. //待双人核对
  8878. if pat_type == 5 {
  8879. for _, item := range monitor {
  8880. if item.DoubleCheck == nil {
  8881. mds = append(mds, item)
  8882. }
  8883. }
  8884. }
  8885. //医嘱未执行
  8886. if pat_type == 6 {
  8887. for _, item := range monitor {
  8888. if len(item.AdviceList) > 0 {
  8889. mds = append(mds, item)
  8890. }
  8891. }
  8892. }
  8893. //患者未签名
  8894. if pat_type == 7 {
  8895. for _, item := range monitor {
  8896. if item.DialysisOrder != nil {
  8897. if item.DialysisOrder.ID > 0 {
  8898. mds = append(mds, item)
  8899. }
  8900. }
  8901. }
  8902. }
  8903. //目标超滤于实际超滤不同
  8904. if pat_type == 8 {
  8905. for _, item := range monitor {
  8906. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  8907. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  8908. mds = append(mds, item)
  8909. }
  8910. }
  8911. }
  8912. }
  8913. //血压少于5次
  8914. if pat_type == 9 {
  8915. for _, item := range monitor {
  8916. if len(item.MonitoringRecord) < 5 {
  8917. mds = append(mds, item)
  8918. }
  8919. }
  8920. }
  8921. if pat_type == 10 {
  8922. for _, item := range monitor {
  8923. if len(item.MonitoringRecord) == 0 {
  8924. mds = append(mds, item)
  8925. }
  8926. }
  8927. }
  8928. if pat_type == 11 {
  8929. for _, item := range monitor {
  8930. if len(item.MonitoringRecord) > 0 {
  8931. mds = append(mds, item)
  8932. }
  8933. }
  8934. }
  8935. if pat_type == 12 {
  8936. for _, item := range monitor {
  8937. if len(item.MonitoringRecord) > 0 {
  8938. mds = append(mds, item)
  8939. }
  8940. }
  8941. }
  8942. if err == nil {
  8943. c.ServeSuccessJSON(map[string]interface{}{
  8944. "monitor": mds,
  8945. "patients": patients,
  8946. })
  8947. } else {
  8948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8949. }
  8950. }
  8951. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  8952. admin_user_id, _ := c.GetInt64("admin_user_id")
  8953. timeStr := time.Now().Format("2006-01-02")
  8954. timeLayout := "2006-01-02 15:04:05"
  8955. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8956. timenow := timeStringToTime.Unix()
  8957. orgId := c.GetMobileAdminUserInfo().Org.Id
  8958. //查询当前护士的患者
  8959. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  8960. var patientIds []int64
  8961. for _, item := range orderList {
  8962. patientIds = append(patientIds, item.PatientId)
  8963. }
  8964. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  8965. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  8966. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  8967. //药品管理信息
  8968. _, drugStockConfig := service.FindHisConfig(orgId)
  8969. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  8970. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  8971. c.ServeSuccessJSON(map[string]interface{}{
  8972. "adviceList": adviceList,
  8973. "hisAdviceList": hisAdviceList,
  8974. "projectList": projectList,
  8975. "drugStockConfig": drugStockConfig,
  8976. "patientList": patientList,
  8977. "projectConfig": projectConfig,
  8978. })
  8979. }
  8980. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  8981. patient_id, _ := c.GetInt64("patient_id")
  8982. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  8983. c.ServeSuccessJSON(map[string]interface{}{
  8984. "recrods": recrods,
  8985. })
  8986. }
  8987. func (c *DialysisAPIController) ExMobileChangeSch() {
  8988. id_one, _ := c.GetInt64("id_one")
  8989. id_two, _ := c.GetInt64("id_two")
  8990. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  8991. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  8992. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  8993. //if order2.ID > 0 {
  8994. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  8995. // return
  8996. //}
  8997. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  8998. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  8999. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9000. if count > 0 {
  9001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9002. return
  9003. }
  9004. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9005. if count1 > 0 {
  9006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9007. return
  9008. }
  9009. }
  9010. err := service.UpdateScheduleThree(sch, sch_two)
  9011. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9012. if order.ID > 0 {
  9013. //查询该患者的排班机位
  9014. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9015. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9016. redis := service.RedisClient()
  9017. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9018. redis.Set(key, "", time.Second)
  9019. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9020. //清空key 值
  9021. redis.Set(keyOne, "", time.Second)
  9022. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9023. //return
  9024. }
  9025. if err == nil {
  9026. //去除当天患者排班中重复数据,保留最后一条数据
  9027. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9028. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9029. c.ServeSuccessJSON(map[string]interface{}{
  9030. "msg": "交换成功",
  9031. })
  9032. } else {
  9033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9034. return
  9035. }
  9036. }
  9037. func (c *DialysisAPIController) MobileCoverSch() {
  9038. id_one, _ := c.GetInt64("id_one")
  9039. id_two, _ := c.GetInt64("id_two")
  9040. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9041. //针对凤凰医院
  9042. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9043. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9044. if len(advice) > 0 {
  9045. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9046. }
  9047. }
  9048. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9049. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9050. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9051. if len(hisAdvice) > 0 {
  9052. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9053. }
  9054. if len(project) > 0 {
  9055. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9056. }
  9057. }
  9058. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9059. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9060. if order.ID > 0 {
  9061. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9062. redis := service.RedisClient()
  9063. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9064. redis.Set(key, "", time.Second)
  9065. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9066. //清空key 值
  9067. redis.Set(keyOne, "", time.Second)
  9068. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9069. //return
  9070. }
  9071. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9072. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9073. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9074. if count > 0 {
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9076. return
  9077. }
  9078. }
  9079. var new_sch models.Schedule
  9080. new_sch = sch
  9081. new_sch.BedId = sch_two.BedId
  9082. new_sch.ScheduleDate = sch_two.ScheduleDate
  9083. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9084. new_sch.PartitionId = sch_two.PartitionId
  9085. new_sch.ScheduleType = sch_two.ScheduleType
  9086. new_sch.ID = 0
  9087. //删除原来的排班
  9088. err := service.SaveSchTwo(sch, sch_two)
  9089. //生成新的排班
  9090. if err == nil {
  9091. err2 := service.SaveSch(&new_sch)
  9092. if err2 == nil {
  9093. //去除当天患者排班中重复数据,保留最后一条数据
  9094. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9095. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9096. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9097. c.ServeSuccessJSON(map[string]interface{}{
  9098. "msg": "覆盖成功",
  9099. "new_sch": new_sch,
  9100. })
  9101. } else {
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9103. return
  9104. }
  9105. } else {
  9106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9107. return
  9108. }
  9109. }
  9110. func (c *DialysisAPIController) BatchCheckAdvice() {
  9111. patient_id, _ := c.GetInt64("patient_id")
  9112. advice_date, _ := c.GetInt64("advice_date")
  9113. org_id := c.GetMobileAdminUserInfo().Org.Id
  9114. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9115. //查询是his系统还是血透系统
  9116. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9117. //his客户
  9118. if configs.IsOpen == 1 {
  9119. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9120. for _, item := range adviceList {
  9121. service.BatchCheckHisAdvice(item.ID, creater)
  9122. }
  9123. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9124. for _, item := range projectList {
  9125. service.BatchCheckProject(item.ID, creater)
  9126. }
  9127. c.ServeSuccessJSON(map[string]interface{}{
  9128. "adviceList": adviceList,
  9129. "projectList": projectList,
  9130. })
  9131. }
  9132. if configs.IsOpen != 1 {
  9133. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9134. for _, item := range adviceList {
  9135. service.BatchAdviceList(item.ID, creater)
  9136. }
  9137. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9138. for _, item := range projectList {
  9139. service.BatchCheckProject(item.ID, creater)
  9140. }
  9141. c.ServeSuccessJSON(map[string]interface{}{
  9142. "adviceList": adviceList,
  9143. "projectList": projectList,
  9144. })
  9145. }
  9146. return
  9147. }
  9148. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9149. org_id := c.GetMobileAdminUserInfo().Org.Id
  9150. drugList, _ := service.GetAllDrugList(org_id)
  9151. c.ServeSuccessJSON(map[string]interface{}{
  9152. "drugList": drugList,
  9153. })
  9154. }
  9155. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9156. org_id := c.GetMobileAdminUserInfo().Org.Id
  9157. dataBody := make(map[string]interface{}, 0)
  9158. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9159. if err != nil {
  9160. utils.ErrorLog(err.Error())
  9161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9162. return
  9163. }
  9164. timeLayout := "2006-01-02"
  9165. loc, _ := time.LoadLocation("Local")
  9166. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9167. utils.ErrorLog("advice_type")
  9168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9169. return
  9170. }
  9171. adviceType := int64(dataBody["advice_type"].(float64))
  9172. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9173. utils.ErrorLog("start_time")
  9174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9175. return
  9176. }
  9177. startTime2, _ := dataBody["start_time"].(string)
  9178. time_arr := strings.Split(startTime2, " ")
  9179. if len(time_arr) > 0 {
  9180. startTime2 = time_arr[0]
  9181. }
  9182. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9183. utils.ErrorLog("advice_date")
  9184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9185. return
  9186. }
  9187. advice_date, _ := dataBody["advice_date"].(string)
  9188. var advicedateunix int64
  9189. if len(advice_date) > 0 {
  9190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9191. if err != nil {
  9192. fmt.Println(err)
  9193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9194. return
  9195. }
  9196. advicedateunix = theTime.Unix()
  9197. }
  9198. adviceDate := startTime2
  9199. if len(adviceDate) == 0 {
  9200. utils.ErrorLog("len(adviceDate) == 0")
  9201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9202. return
  9203. }
  9204. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9205. if err != nil {
  9206. utils.ErrorLog(err.Error())
  9207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9208. return
  9209. }
  9210. AdviceDate := advicedateunix
  9211. RecordDate := advicedateunix
  9212. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9213. utils.ErrorLog("start_time")
  9214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9215. return
  9216. }
  9217. startTime, _ := dataBody["start_time"].(string)
  9218. if len(startTime) == 0 {
  9219. utils.ErrorLog("len(start_time) == 0")
  9220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9221. return
  9222. }
  9223. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9224. if err != nil {
  9225. utils.ErrorLog(err.Error())
  9226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9227. return
  9228. }
  9229. StartTime := theTime.Unix()
  9230. advice_name, _ := dataBody["advice_name"].(string)
  9231. advice_desc, _ := dataBody["advice_desc"].(string)
  9232. delivery_way, _ := dataBody["delivery_way"].(string)
  9233. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9234. frequency_type := int64(dataBody["frequency_type"].(float64))
  9235. frequency_week, _ := dataBody["frequency_week"].(string)
  9236. prescribing_number := dataBody["prescribing_number"].(float64)
  9237. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9238. remark := dataBody["remark"].(string)
  9239. single_dose := dataBody["single_dose"].(float64)
  9240. single_dose_unit := dataBody["single_dose_unit"].(string)
  9241. patient_id := int64(dataBody["patient_id"].(float64))
  9242. day_count := int64(dataBody["day_count"].(float64))
  9243. groupNo := int64(dataBody["group_no"].(float64))
  9244. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9245. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9246. if groupNo <= 0 {
  9247. group := service.GetMaxAdviceGroupID(org_id)
  9248. groupNo = group + 1
  9249. }
  9250. var template_id = ""
  9251. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9252. template_id = "M" + adviceLastId
  9253. advice := models.DoctorAdvice{
  9254. UserOrgId: org_id,
  9255. PatientId: patient_id,
  9256. AdviceType: adviceType,
  9257. AdviceDate: AdviceDate,
  9258. StartTime: StartTime,
  9259. AdviceName: advice_name,
  9260. AdviceDesc: advice_desc,
  9261. ReminderDate: 0,
  9262. SingleDose: single_dose,
  9263. SingleDoseUnit: single_dose_unit,
  9264. DrugSpec: 0,
  9265. DrugSpecUnit: "",
  9266. PrescribingNumber: prescribing_number,
  9267. PrescribingNumberUnit: prescribing_number_unit,
  9268. DeliveryWay: delivery_way,
  9269. ExecutionFrequency: execution_frequency,
  9270. AdviceDoctor: advice_doctor,
  9271. Status: 1,
  9272. CreatedTime: time.Now().Unix(),
  9273. UpdatedTime: 0,
  9274. AdviceAffirm: "",
  9275. Remark: remark,
  9276. StopTime: 0,
  9277. StopReason: "",
  9278. StopDoctor: 0,
  9279. StopState: 0,
  9280. ParentId: 0,
  9281. ExecutionTime: 0,
  9282. ExecutionStaff: 0,
  9283. ExecutionState: 0,
  9284. Checker: 0,
  9285. RecordDate: RecordDate,
  9286. DialysisOrderId: 0,
  9287. CheckTime: 0,
  9288. CheckState: 0,
  9289. AdviceId: 0,
  9290. RemindType: 0,
  9291. FrequencyType: frequency_type,
  9292. DayCount: day_count,
  9293. WeekDay: frequency_week,
  9294. ChildDoctorAdvice: nil,
  9295. TemplateId: template_id,
  9296. Modifier: 0,
  9297. IsCheck: 0,
  9298. Way: 0,
  9299. DrugId: 0,
  9300. DrugNameId: 0,
  9301. IsMedicine: 0,
  9302. PushStartTime: 0,
  9303. IsSettle: 0,
  9304. IsPrescription: 0,
  9305. GroupNo: groupNo,
  9306. }
  9307. service.CreateMobileAdivce(advice)
  9308. c.ServeSuccessJSON(map[string]interface{}{
  9309. "msg": "保存成功!",
  9310. })
  9311. }
  9312. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9313. patient_id, _ := c.GetInt64("patient_id")
  9314. org_id := c.GetMobileAdminUserInfo().Org.Id
  9315. app_id := c.GetMobileAdminUserInfo().App.Id
  9316. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9317. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9318. c.ServeSuccessJSON(map[string]interface{}{
  9319. "adviceList": adviceList,
  9320. "adminRoles": adminRoles,
  9321. })
  9322. }
  9323. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9324. org_id := c.GetMobileAdminUserInfo().Org.Id
  9325. dataBody := make(map[string]interface{}, 0)
  9326. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9327. if err != nil {
  9328. utils.ErrorLog(err.Error())
  9329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9330. return
  9331. }
  9332. timeLayout := "2006-01-02"
  9333. loc, _ := time.LoadLocation("Local")
  9334. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9335. utils.ErrorLog("start_time")
  9336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9337. return
  9338. }
  9339. startTime2, _ := dataBody["start_time"].(string)
  9340. time_arr := strings.Split(startTime2, " ")
  9341. if len(time_arr) > 0 {
  9342. startTime2 = time_arr[0]
  9343. }
  9344. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9345. utils.ErrorLog("advice_date")
  9346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9347. return
  9348. }
  9349. advice_date, _ := dataBody["advice_date"].(string)
  9350. var advicedateunix int64
  9351. if len(advice_date) > 0 {
  9352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9353. if err != nil {
  9354. fmt.Println(err)
  9355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9356. return
  9357. }
  9358. advicedateunix = theTime.Unix()
  9359. }
  9360. adviceDate := startTime2
  9361. if len(adviceDate) == 0 {
  9362. utils.ErrorLog("len(adviceDate) == 0")
  9363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9364. return
  9365. }
  9366. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9367. if err != nil {
  9368. utils.ErrorLog(err.Error())
  9369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9370. return
  9371. }
  9372. AdviceDate := advicedateunix
  9373. RecordDate := advicedateunix
  9374. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9375. utils.ErrorLog("start_time")
  9376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9377. return
  9378. }
  9379. startTime, _ := dataBody["start_time"].(string)
  9380. if len(startTime) == 0 {
  9381. utils.ErrorLog("len(start_time) == 0")
  9382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9383. return
  9384. }
  9385. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9386. if err != nil {
  9387. utils.ErrorLog(err.Error())
  9388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9389. return
  9390. }
  9391. StartTime := theTime.Unix()
  9392. advice_name, _ := dataBody["advice_name"].(string)
  9393. advice_desc, _ := dataBody["advice_desc"].(string)
  9394. delivery_way, _ := dataBody["delivery_way"].(string)
  9395. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9396. prescribing_number := dataBody["prescribing_number"].(float64)
  9397. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9398. remark := dataBody["remark"].(string)
  9399. single_dose := dataBody["single_dose"].(float64)
  9400. single_dose_unit := dataBody["single_dose_unit"].(string)
  9401. patient_id := int64(dataBody["patient_id"].(float64))
  9402. groupNo := int64(dataBody["group_no"].(float64))
  9403. parent_id := int64(dataBody["parent_id"].(float64))
  9404. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9405. advice := models.XtDoctorAdviceOne{
  9406. UserOrgId: org_id,
  9407. PatientId: patient_id,
  9408. AdviceType: 1,
  9409. AdviceDate: AdviceDate,
  9410. StartTime: StartTime,
  9411. AdviceName: advice_name,
  9412. AdviceDesc: advice_desc,
  9413. ReminderDate: 0,
  9414. SingleDose: single_dose,
  9415. SingleDoseUnit: single_dose_unit,
  9416. PrescribingNumber: prescribing_number,
  9417. PrescribingNumberUnit: prescribing_number_unit,
  9418. DeliveryWay: delivery_way,
  9419. ExecutionFrequency: execution_frequency,
  9420. AdviceDoctor: advice_doctor,
  9421. Status: 1,
  9422. CreatedTime: time.Now().Unix(),
  9423. UpdatedTime: time.Now().Unix(),
  9424. AdviceAffirm: "",
  9425. Remark: remark,
  9426. StopTime: 0,
  9427. StopReason: "",
  9428. StopDoctor: 0,
  9429. StopState: 0,
  9430. ParentId: parent_id,
  9431. ExecutionTime: 0,
  9432. ExecutionStaff: 0,
  9433. ExecutionState: 0,
  9434. Checker: 0,
  9435. RecordDate: RecordDate,
  9436. DialysisOrderId: 0,
  9437. CheckTime: 0,
  9438. CheckState: 0,
  9439. DrugSpec: 0,
  9440. DrugSpecUnit: "",
  9441. Groupno: groupNo,
  9442. RemindType: 0,
  9443. FrequencyType: 0,
  9444. DayCount: 0,
  9445. WeekDay: "",
  9446. TemplateId: "",
  9447. Modifier: 0,
  9448. }
  9449. service.CreateMobileAdivceOne(advice)
  9450. c.ServeSuccessJSON(map[string]interface{}{
  9451. "msg": "保存成功!",
  9452. })
  9453. }
  9454. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9455. id, _ := c.GetInt64("id")
  9456. service.DeleteSelfAdviceSubAdvice(id)
  9457. c.ServeSuccessJSON(map[string]interface{}{
  9458. "msg": "保存成功!",
  9459. })
  9460. }
  9461. func (c *DialysisAPIController) GetEditAdviceAction() {
  9462. id, _ := c.GetInt64("id")
  9463. org_id := c.GetMobileAdminUserInfo().Org.Id
  9464. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9465. drugList, _ := service.GetAllDrugList(org_id)
  9466. c.ServeSuccessJSON(map[string]interface{}{
  9467. "advice": advice,
  9468. "drugList": drugList,
  9469. })
  9470. }
  9471. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9472. dataBody := make(map[string]interface{}, 0)
  9473. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9474. if err != nil {
  9475. utils.ErrorLog(err.Error())
  9476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9477. return
  9478. }
  9479. timeLayout := "2006-01-02"
  9480. loc, _ := time.LoadLocation("Local")
  9481. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9482. utils.ErrorLog("start_time")
  9483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9484. return
  9485. }
  9486. startTime2, _ := dataBody["start_time"].(string)
  9487. time_arr := strings.Split(startTime2, " ")
  9488. if len(time_arr) > 0 {
  9489. startTime2 = time_arr[0]
  9490. }
  9491. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9492. utils.ErrorLog("advice_date")
  9493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9494. return
  9495. }
  9496. advice_date, _ := dataBody["advice_date"].(string)
  9497. var advicedateunix int64
  9498. if len(advice_date) > 0 {
  9499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9500. if err != nil {
  9501. fmt.Println(err)
  9502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9503. return
  9504. }
  9505. advicedateunix = theTime.Unix()
  9506. }
  9507. adviceDate := startTime2
  9508. if len(adviceDate) == 0 {
  9509. utils.ErrorLog("len(adviceDate) == 0")
  9510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9511. return
  9512. }
  9513. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9514. if err != nil {
  9515. utils.ErrorLog(err.Error())
  9516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9517. return
  9518. }
  9519. AdviceDate := advicedateunix
  9520. RecordDate := advicedateunix
  9521. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9522. utils.ErrorLog("start_time")
  9523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9524. return
  9525. }
  9526. startTime, _ := dataBody["start_time"].(string)
  9527. if len(startTime) == 0 {
  9528. utils.ErrorLog("len(start_time) == 0")
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9530. return
  9531. }
  9532. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9533. if err != nil {
  9534. utils.ErrorLog(err.Error())
  9535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9536. return
  9537. }
  9538. StartTime := theTime.Unix()
  9539. advice_name, _ := dataBody["advice_name"].(string)
  9540. advice_desc, _ := dataBody["advice_desc"].(string)
  9541. delivery_way, _ := dataBody["delivery_way"].(string)
  9542. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9543. prescribing_number := dataBody["prescribing_number"].(float64)
  9544. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9545. remark := dataBody["remark"].(string)
  9546. single_dose := dataBody["single_dose"].(float64)
  9547. single_dose_unit := dataBody["single_dose_unit"].(string)
  9548. id := int64(dataBody["id"].(float64))
  9549. frequency_type := int64(dataBody["frequency_type"].(float64))
  9550. frequency_week, _ := dataBody["frequency_week"].(string)
  9551. day_count := int64(dataBody["day_count"].(float64))
  9552. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9553. advice := models.XtDoctorAdviceOne{
  9554. AdviceDate: AdviceDate,
  9555. StartTime: StartTime,
  9556. AdviceName: advice_name,
  9557. AdviceDesc: advice_desc,
  9558. SingleDose: single_dose,
  9559. SingleDoseUnit: single_dose_unit,
  9560. PrescribingNumber: prescribing_number,
  9561. PrescribingNumberUnit: prescribing_number_unit,
  9562. DeliveryWay: delivery_way,
  9563. ExecutionFrequency: execution_frequency,
  9564. AdviceDoctor: advice_doctor,
  9565. Remark: remark,
  9566. RecordDate: RecordDate,
  9567. FrequencyType: frequency_type,
  9568. DayCount: day_count,
  9569. WeekDay: frequency_week,
  9570. }
  9571. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  9572. c.ServeSuccessJSON(map[string]interface{}{
  9573. "advice": advice,
  9574. })
  9575. }
  9576. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  9577. dataBody := make(map[string]interface{}, 0)
  9578. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9579. if err != nil {
  9580. utils.ErrorLog(err.Error())
  9581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9582. return
  9583. }
  9584. timeLayout := "2006-01-02"
  9585. loc, _ := time.LoadLocation("Local")
  9586. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9587. utils.ErrorLog("start_time")
  9588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9589. return
  9590. }
  9591. startTime2, _ := dataBody["start_time"].(string)
  9592. time_arr := strings.Split(startTime2, " ")
  9593. if len(time_arr) > 0 {
  9594. startTime2 = time_arr[0]
  9595. }
  9596. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9597. utils.ErrorLog("advice_date")
  9598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9599. return
  9600. }
  9601. advice_date, _ := dataBody["advice_date"].(string)
  9602. var advicedateunix int64
  9603. if len(advice_date) > 0 {
  9604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9605. if err != nil {
  9606. fmt.Println(err)
  9607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9608. return
  9609. }
  9610. advicedateunix = theTime.Unix()
  9611. }
  9612. adviceDate := startTime2
  9613. if len(adviceDate) == 0 {
  9614. utils.ErrorLog("len(adviceDate) == 0")
  9615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9616. return
  9617. }
  9618. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9619. if err != nil {
  9620. utils.ErrorLog(err.Error())
  9621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9622. return
  9623. }
  9624. AdviceDate := advicedateunix
  9625. RecordDate := advicedateunix
  9626. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9627. utils.ErrorLog("start_time")
  9628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9629. return
  9630. }
  9631. startTime, _ := dataBody["start_time"].(string)
  9632. if len(startTime) == 0 {
  9633. utils.ErrorLog("len(start_time) == 0")
  9634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9635. return
  9636. }
  9637. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9638. if err != nil {
  9639. utils.ErrorLog(err.Error())
  9640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9641. return
  9642. }
  9643. StartTime := theTime.Unix()
  9644. advice_name, _ := dataBody["advice_name"].(string)
  9645. advice_desc, _ := dataBody["advice_desc"].(string)
  9646. delivery_way, _ := dataBody["delivery_way"].(string)
  9647. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9648. prescribing_number := dataBody["prescribing_number"].(float64)
  9649. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9650. remark := dataBody["remark"].(string)
  9651. single_dose := dataBody["single_dose"].(float64)
  9652. single_dose_unit := dataBody["single_dose_unit"].(string)
  9653. id := int64(dataBody["id"].(float64))
  9654. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9655. advice := models.XtDoctorAdviceOne{
  9656. AdviceDate: AdviceDate,
  9657. StartTime: StartTime,
  9658. AdviceName: advice_name,
  9659. AdviceDesc: advice_desc,
  9660. SingleDose: single_dose,
  9661. SingleDoseUnit: single_dose_unit,
  9662. PrescribingNumber: prescribing_number,
  9663. PrescribingNumberUnit: prescribing_number_unit,
  9664. DeliveryWay: delivery_way,
  9665. ExecutionFrequency: execution_frequency,
  9666. AdviceDoctor: advice_doctor,
  9667. Remark: remark,
  9668. RecordDate: RecordDate,
  9669. }
  9670. service.UpdateMobileDoctorAdviceById(id, advice)
  9671. c.ServeSuccessJSON(map[string]interface{}{
  9672. "advice": advice,
  9673. })
  9674. }
  9675. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  9676. dataBody := make(map[string]interface{}, 0)
  9677. timeLayout := "2006-01-02"
  9678. loc, _ := time.LoadLocation("Local")
  9679. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9680. if err != nil {
  9681. utils.ErrorLog(err.Error())
  9682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9683. return
  9684. }
  9685. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9686. utils.ErrorLog("start_time")
  9687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9688. return
  9689. }
  9690. startTime2, _ := dataBody["start_time"].(string)
  9691. time_arr := strings.Split(startTime2, " ")
  9692. if len(time_arr) > 0 {
  9693. startTime2 = time_arr[0]
  9694. }
  9695. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9696. utils.ErrorLog("advice_date")
  9697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9698. return
  9699. }
  9700. advice_date, _ := dataBody["advice_date"].(string)
  9701. var advicedateunix int64
  9702. if len(advice_date) > 0 {
  9703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9704. if err != nil {
  9705. fmt.Println(err)
  9706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9707. return
  9708. }
  9709. advicedateunix = theTime.Unix()
  9710. }
  9711. adviceDate := startTime2
  9712. if len(adviceDate) == 0 {
  9713. utils.ErrorLog("len(adviceDate) == 0")
  9714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9715. return
  9716. }
  9717. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9718. if err != nil {
  9719. utils.ErrorLog(err.Error())
  9720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9721. return
  9722. }
  9723. RecordDate := advicedateunix
  9724. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9725. utils.ErrorLog("start_time")
  9726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9727. return
  9728. }
  9729. startTime, _ := dataBody["start_time"].(string)
  9730. if len(startTime) == 0 {
  9731. utils.ErrorLog("len(start_time) == 0")
  9732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9733. return
  9734. }
  9735. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9736. if err != nil {
  9737. utils.ErrorLog(err.Error())
  9738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9739. return
  9740. }
  9741. StartTime := theTime.Unix()
  9742. patient_id := int64(dataBody["patient_id"].(float64))
  9743. group_no := int64(dataBody["group_no"].(float64))
  9744. org_id := c.GetMobileAdminUserInfo().Org.Id
  9745. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9746. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  9747. utils.ErrorLog("advices")
  9748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9749. return
  9750. }
  9751. adviceNames := dataBody["advices"].([]interface{})
  9752. var advices []*models.GroupAdvice
  9753. for _, adviceNameMap := range adviceNames {
  9754. var advice models.GroupAdvice
  9755. adviceNameM := adviceNameMap.(map[string]interface{})
  9756. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  9757. utils.ErrorLog("advice_name")
  9758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9759. return
  9760. }
  9761. adviceName, _ := adviceNameM["advice_name"].(string)
  9762. if len(adviceName) == 0 {
  9763. utils.ErrorLog("len(advice_name) == 0")
  9764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9765. return
  9766. }
  9767. advice.AdviceName = adviceName
  9768. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  9769. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  9770. advice.DrugSpec = drugSpec
  9771. }
  9772. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  9773. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  9774. advice.AdviceDesc = adviceDesc
  9775. }
  9776. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  9777. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  9778. advice.DrugSpecUnit = drugSpecUnit
  9779. }
  9780. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  9781. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  9782. advice.SingleDose = singleDose
  9783. }
  9784. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  9785. singleDose := adviceNameM["single_dose"].(float64)
  9786. advice.SingleDose = singleDose
  9787. }
  9788. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  9789. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  9790. advice.SingleDoseUnit = singleDoseUnit
  9791. }
  9792. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  9793. tmp := adviceNameM["single_dose_unit"].(float64)
  9794. singleDoseUnit := service.TypeConversion(tmp)
  9795. advice.SingleDoseUnit = singleDoseUnit
  9796. }
  9797. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  9798. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  9799. advice.PrescribingNumber = prescribingNumber
  9800. }
  9801. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  9802. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  9803. advice.PrescribingNumber = prescribingNumber
  9804. }
  9805. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  9806. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  9807. advice.PrescribingNumberUnit = prescribingNumberUnit
  9808. }
  9809. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  9810. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  9811. advice.DeliveryWay = deliveryWay
  9812. }
  9813. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  9814. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  9815. advice.ExecutionFrequency = executionFrequency
  9816. }
  9817. remark, _ := adviceNameM["remark"].(string)
  9818. advice.Remark = remark
  9819. advice.AdviceType = 1
  9820. advice.StartTime = StartTime
  9821. advice.RecordDate = RecordDate
  9822. advice.PatientId = patient_id
  9823. advice.UserOrgId = org_id
  9824. advice.AdviceDoctor = advice_doctor
  9825. advices = append(advices, &advice)
  9826. }
  9827. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  9828. c.ServeSuccessJSON(map[string]interface{}{
  9829. "advice": newAdvices,
  9830. })
  9831. }