patient_api_controller.go 248KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. // "fmt"
  12. "reflect"
  13. "strconv"
  14. "time"
  15. )
  16. type PatientApiController struct {
  17. MobileBaseAPIAuthController
  18. }
  19. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  20. id, _ := c.GetInt64("patient", 0)
  21. if id <= 0 {
  22. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  23. return
  24. }
  25. adminUserInfo := c.GetMobileAdminUserInfo()
  26. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  27. if patient.ID == 0 {
  28. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  29. return
  30. }
  31. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  32. if err != nil {
  33. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. return
  35. }
  36. if Registrars != nil {
  37. patient.Registrars = Registrars.Name
  38. }
  39. c.ServeSuccessJSON(map[string]interface{}{
  40. "patient": patient,
  41. })
  42. return
  43. }
  44. func (c *PatientApiController) CreateDialysisSolution() {
  45. id, _ := c.GetInt64("patient", 0)
  46. if id <= 0 {
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. adminUserInfo := c.GetMobileAdminUserInfo()
  51. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  52. if patient.ID == 0 {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  54. return
  55. }
  56. //根据路由来做权限
  57. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  58. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  59. //if template.TemplateId == 2 || template.TemplateId == 6 {
  60. // if appRole.UserType == 3 {
  61. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  62. // if getPermissionErr != nil {
  63. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  64. // return
  65. // } else if headNursePermission == nil {
  66. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  67. // return
  68. // }
  69. // }
  70. //}
  71. var solution models.DialysisSolution
  72. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  73. if code > 0 {
  74. c.ServeFailJSONWithSGJErrorCode(code)
  75. return
  76. }
  77. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  78. solution.Doctor = adminUserInfo.AdminUser.Id
  79. solution.Status = 1
  80. solution.PatientId = id
  81. solution.CreatedTime = time.Now().Unix()
  82. solution.UserOrgId = adminUserInfo.Org.Id
  83. solution.UpdatedTime = time.Now().Unix()
  84. solution.SubName = ""
  85. solution.ParentId = 0
  86. err := service.CreatePatientDialysisSolution(&solution)
  87. if err != nil {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  89. return
  90. }
  91. c.ServeSuccessJSON(map[string]interface{}{
  92. "msg": "ok",
  93. "solution": solution,
  94. })
  95. return
  96. }
  97. func (c *PatientApiController) EditDialysisSolution() {
  98. id, _ := c.GetInt64("id", 0)
  99. if id <= 0 {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. adminUserInfo := c.GetMobileAdminUserInfo()
  104. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  105. if solution.ID == 0 {
  106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  107. return
  108. }
  109. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  111. // if getPermissionErr != nil {
  112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. // return
  114. // } else if headNursePermission == nil {
  115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  116. // return
  117. // }
  118. //}
  119. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  120. if code > 0 {
  121. c.ServeFailJSONWithSGJErrorCode(code)
  122. return
  123. }
  124. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  125. solution.Doctor = adminUserInfo.AdminUser.Id
  126. solution.Status = 1
  127. // solution.PatientId = id
  128. // solution.CreatedTime = time.Now().Unix()
  129. // solution.UserOrgId = adminUserInfo.Org.Id
  130. solution.UpdatedTime = time.Now().Unix()
  131. // solution.SubName = ""
  132. // solution.ParentId = 0
  133. err := service.UpdatePatientDialysisSolution(&solution)
  134. if err != nil {
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  136. return
  137. }
  138. c.ServeSuccessJSON(map[string]interface{}{
  139. "msg": "ok",
  140. "solution": solution,
  141. })
  142. return
  143. }
  144. func (c *PatientApiController) CreateDoctorAdvice() {
  145. patient, _ := c.GetInt64("id", 0)
  146. if patient <= 0 {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. adminUserInfo := c.GetMobileAdminUserInfo()
  151. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  152. if patientInfo.ID == 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  154. return
  155. }
  156. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  157. //if appRole.UserType == 3{
  158. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  159. // return
  160. //}
  161. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  162. //
  163. //if appRole.UserType == 3 {
  164. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  165. // if getPermissionErr != nil {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. // return
  168. // } else if headNursePermission == nil {
  169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  170. // return
  171. // }
  172. //}
  173. var advice models.DoctorAdvice
  174. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  175. if code > 0 {
  176. c.ServeFailJSONWithSGJErrorCode(code)
  177. return
  178. }
  179. if advice.ParentId > 0 {
  180. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  181. if old.ID == 0 || old.PatientId != patient {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  183. return
  184. }
  185. if old.StopState == 1 || old.ExecutionState == 1 {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  187. return
  188. }
  189. if old.ParentId > 0 {
  190. advice.ParentId = old.ParentId
  191. }
  192. advice.StartTime = old.StartTime
  193. advice.AdviceDoctor = old.AdviceDoctor
  194. advice.DeliveryWay = old.DeliveryWay
  195. advice.ExecutionFrequency = old.ExecutionFrequency
  196. advice.GroupNo = old.GroupNo
  197. }
  198. advice.Status = 1
  199. advice.CreatedTime = time.Now().Unix()
  200. advice.UpdatedTime = time.Now().Unix()
  201. advice.StopState = 2
  202. advice.ExecutionState = 2
  203. advice.UserOrgId = adminUserInfo.Org.Id
  204. advice.PatientId = patient
  205. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  206. err := service.CreateDoctorAdvice(&advice)
  207. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  208. redis := service.RedisClient()
  209. defer redis.Close()
  210. redis.Set(key, "", time.Second)
  211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  212. redis.Set(keyOne, "", time.Second)
  213. if err != nil {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  215. return
  216. }
  217. c.ServeSuccessJSON(map[string]interface{}{
  218. "msg": "ok",
  219. "advice": advice,
  220. })
  221. return
  222. }
  223. func (c *PatientApiController) EditDoctorAdvice() {
  224. id, _ := c.GetInt64("id", 0)
  225. patient_id, _ := c.GetInt64("patient_id")
  226. doc_advice_date, _ := c.GetInt64("advice_date")
  227. if id <= 0 {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. redis := service.RedisClient()
  232. adminUserInfo := c.GetMobileAdminUserInfo()
  233. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //
  236. //if appRole.UserType == 3 {
  237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  238. // if getPermissionErr != nil {
  239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. // return
  241. // } else if headNursePermission == nil {
  242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  243. // return
  244. // }
  245. //}
  246. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  247. if advice.ID == 0 {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  249. return
  250. }
  251. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  252. if code > 0 {
  253. c.ServeFailJSONWithSGJErrorCode(code)
  254. return
  255. }
  256. advice.Status = 1
  257. advice.UpdatedTime = time.Now().Unix()
  258. advice.UserOrgId = adminUserInfo.Org.Id
  259. advice.Modifier = adminUserInfo.AdminUser.Id
  260. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 && infor.WeekDay > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  338. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  339. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  340. defer redis.Close()
  341. redis.Set(key, "", time.Second)
  342. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  343. redis.Set(keyOne, "", time.Second)
  344. isChangeGroup = true
  345. }
  346. }
  347. } else {
  348. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  349. if infor.ID > 0 {
  350. var cha_time int64
  351. timeNowStr := time.Now().Format("2006-01-02")
  352. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  353. //今日的日期减去设置的日期
  354. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  355. if cha_time >= advice.AdviceDate {
  356. //查询审核是否允许
  357. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  358. //申请状态不允许的情况 拒绝修改
  359. if infor.ApplicationStatus != 1 {
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  361. return
  362. }
  363. }
  364. }
  365. isChangeGroup = false
  366. err = service.UpdateDoctorAdvice(&advice)
  367. redis := service.RedisClient()
  368. defer redis.Close()
  369. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  370. redis.Set(key, "", time.Second)
  371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  372. redis.Set(keyOne, "", time.Second)
  373. }
  374. if err != nil {
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  376. return
  377. }
  378. if !isChangeGroup {
  379. c.ServeSuccessJSON(map[string]interface{}{
  380. "msg": "ok",
  381. "advice": advice,
  382. "isChange": isChangeGroup, //方便前端处理数据
  383. })
  384. } else {
  385. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  386. if err != nil {
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  388. return
  389. }
  390. c.ServeSuccessJSON(map[string]interface{}{
  391. "msg": "ok",
  392. "advice": newGroupAdvice,
  393. "isChange": isChangeGroup, //方便前端处理数据
  394. })
  395. }
  396. return
  397. }
  398. func (c *PatientApiController) StopDoctorAdvice() {
  399. id, _ := c.GetInt64("id", 0)
  400. if id <= 0 {
  401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. adminUserInfo := c.GetMobileAdminUserInfo()
  405. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  406. if advice.ID == 0 {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  408. return
  409. }
  410. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  411. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  412. // return
  413. //}
  414. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  415. //
  416. //if appRole.UserType == 3 {
  417. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  418. // if getPermissionErr != nil {
  419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  420. // return
  421. // } else if headNursePermission == nil {
  422. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  423. // return
  424. // }
  425. //}
  426. if advice.StopState == 1 {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  428. return
  429. }
  430. dataBody := make(map[string]interface{}, 0)
  431. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  432. if err != nil {
  433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  434. return
  435. }
  436. timeLayout := "2006-01-02"
  437. loc, _ := time.LoadLocation("Local")
  438. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  439. utils.ErrorLog("stop_time")
  440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  441. return
  442. }
  443. stopTime, _ := dataBody["stop_time"].(string)
  444. if len(stopTime) == 0 {
  445. utils.ErrorLog("len(stop_time) == 0")
  446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  447. return
  448. }
  449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  450. if err != nil {
  451. utils.ErrorLog(err.Error())
  452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  453. return
  454. }
  455. advice.StopTime = theTime.Unix()
  456. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  457. utils.ErrorLog("stop_reason")
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. stopReason, _ := dataBody["stop_reason"].(string)
  462. if len(stopReason) == 0 {
  463. utils.ErrorLog("len(stop_reason) == 0")
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. advice.StopReason = stopReason
  468. advice.Status = 1
  469. advice.UpdatedTime = time.Now().Unix()
  470. advice.StopDoctor = adminUserInfo.AdminUser.Id
  471. advice.StopState = 1
  472. advice.StopTime = time.Now().Unix()
  473. advice.Modifier = adminUserInfo.AdminUser.Id
  474. err = service.StopDoctorAdvice(&advice)
  475. if err != nil {
  476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  477. return
  478. }
  479. c.ServeSuccessJSON(map[string]interface{}{
  480. "msg": "ok",
  481. "advice": advice,
  482. })
  483. return
  484. }
  485. func (c *PatientApiController) DeleteDoctorAdvice() {
  486. id, _ := c.GetInt64("id", 0)
  487. if id <= 0 {
  488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  489. return
  490. }
  491. adminUserInfo := c.GetMobileAdminUserInfo()
  492. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  493. if advice.ID == 0 {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  495. return
  496. }
  497. //自备药
  498. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  499. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  500. //查询库存是否是自备药
  501. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  502. if selfBasedrug.IsSelfDrug == 1 {
  503. creater := adminUserInfo.AdminUser.Id
  504. //退库
  505. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  506. }
  507. }
  508. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  509. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  510. // return
  511. //}
  512. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  513. //
  514. //if appRole.UserType == 3 {
  515. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  516. // if getPermissionErr != nil {
  517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. // return
  519. // } else if headNursePermission == nil {
  520. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  521. // return
  522. // }
  523. //}
  524. advice.UpdatedTime = time.Now().Unix()
  525. advice.Status = 0
  526. advice.Modifier = adminUserInfo.AdminUser.Id
  527. err := service.DeleteDoctorAdvice(&advice)
  528. if err != nil {
  529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  530. return
  531. }
  532. c.ServeSuccessJSON(map[string]interface{}{
  533. "msg": "ok",
  534. })
  535. return
  536. }
  537. func (c *PatientApiController) ExecDoctorAdvice() {
  538. execution_time := c.GetString("execution_time")
  539. origin, _ := c.GetInt64("origin", 0)
  540. groupno, _ := c.GetInt64("groupno", -1)
  541. record_date, _ := c.GetInt64("record_date")
  542. if origin != 2 {
  543. adminUserInfo := c.GetMobileAdminUserInfo()
  544. execution_staff := adminUserInfo.AdminUser.Id
  545. var ids []string
  546. advice_ids := c.GetString("advice_id")
  547. if groupno == 0 {
  548. ids = strings.Split(advice_ids, ",")
  549. }
  550. if groupno < 0 {
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. if len(execution_time) <= 0 {
  555. utils.ErrorLog("execution_time")
  556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  557. return
  558. }
  559. timeLayout2 := "2006-01-02 15:04:05"
  560. loc, _ := time.LoadLocation("Local")
  561. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  562. if errs != nil {
  563. utils.ErrorLog(errs.Error())
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. var advice models.DoctorAdvice
  568. if groupno > 0 {
  569. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  570. for _, item := range advices {
  571. //自备药
  572. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  573. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  574. //查询库存是否
  575. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  576. if selfBasedrug.IsSelfDrug == 1 {
  577. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  578. var prescribing_number_total_one int64
  579. //判断单位是否相等
  580. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  581. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  582. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  583. //转化为最小单位
  584. prescribing_number_total_one = count * selfBasedrug.MinNumber
  585. }
  586. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  587. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  588. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  589. prescribing_number_total_one = count
  590. }
  591. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  592. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  593. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  594. prescribing_number_total_one = count
  595. }
  596. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  597. c.ServeSuccessJSON(map[string]interface{}{
  598. "msg": "2",
  599. "advice": advice,
  600. "ids": ids,
  601. })
  602. return
  603. }
  604. }
  605. }
  606. //恒泰中医院
  607. if item.UserOrgId == 10490 || item.UserOrgId == 10602 || item.UserOrgId == 10697 {
  608. if item.DrugId == 0 || item.DrugNameId == 0 {
  609. //从字典里面查找
  610. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  611. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  612. }
  613. }
  614. if item.ExecutionState == 2 {
  615. advice = item
  616. }
  617. //记录日志
  618. byterequest, _ := json.Marshal(item)
  619. adviceLog := models.XtDoctorAdviceLog{
  620. UserOrgId: item.UserOrgId,
  621. PatientId: item.PatientId,
  622. AdminUserId: adminUserInfo.AdminUser.Id,
  623. Module: 2,
  624. ErrLog: string(byterequest),
  625. Status: 1,
  626. Ctime: time.Now().Unix(),
  627. Mtime: 0,
  628. Source: "手机端执行医嘱",
  629. RecordDate: item.AdviceDate,
  630. }
  631. service.CreateDoctorAdviceLog(adviceLog)
  632. }
  633. advicesOne, _ := service.FindAllDoctorAdviceByGoroupNoOne(adminUserInfo.Org.Id, groupno)
  634. for _, item := range advicesOne {
  635. //自备药
  636. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  637. if selfPrescriptionOutOpen.IsOpen == 1 {
  638. db := service.XTWriteDB()
  639. tx := db.Begin()
  640. defer func() {
  641. if r := recover(); r != nil {
  642. tx.Rollback()
  643. } else {
  644. tx.Commit()
  645. }
  646. }()
  647. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  648. if selfBasedrug.IsSelfDrug == 1 {
  649. //查询是否有库存
  650. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  651. var total_count int64
  652. var prescribing_number_total int64
  653. for _, items := range infoList {
  654. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  655. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  656. }
  657. total_count += items.StockMaxNumber + items.StockMinNumber
  658. }
  659. if total_count == 0 {
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "msg": "2",
  662. "advice": item,
  663. "ids": ids,
  664. })
  665. return
  666. }
  667. //判断单位是否相等
  668. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  669. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  670. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  671. //转化为最小单位
  672. prescribing_number_total = count * selfBasedrug.MinNumber
  673. }
  674. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  675. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  676. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  677. prescribing_number_total = count
  678. }
  679. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  680. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  681. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  682. prescribing_number_total = count
  683. }
  684. if prescribing_number_total > total_count {
  685. c.ServeSuccessJSON(map[string]interface{}{
  686. "msg": "3",
  687. "advice": item,
  688. })
  689. return
  690. }
  691. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  692. //出库
  693. if prescribing_number_total <= total_count {
  694. timeStr := time.Now().Format("2006-01-02")
  695. timeArr := strings.Split(timeStr, "-")
  696. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  697. total = total + 1
  698. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  699. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  700. number = number + total
  701. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  702. operation_time := time.Now().Unix()
  703. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  704. //创建一个出库单
  705. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  706. WarehouseOutOrderNumber: warehousing_out_order,
  707. OperationTime: operation_time,
  708. OrgId: adminUserInfo.Org.Id,
  709. Creater: creater,
  710. Ctime: time.Now().Unix(),
  711. Status: 1,
  712. WarehouseOutTime: item.AdviceDate,
  713. Type: 0,
  714. PatientId: advice.PatientId,
  715. IsCheck: 1,
  716. IsSys: 1,
  717. }
  718. //查询今日是否有出库数据
  719. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  720. if lastWarehouseOut.ID == 0 {
  721. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  722. }
  723. //查询今日是否有出库数据
  724. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  725. var warehousing_out_order_str string
  726. if lastWarehouseOut.ID == 0 {
  727. warehousing_out_order_str = warehousing_out_order
  728. } else {
  729. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  730. }
  731. //出库
  732. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  733. WarehouseOutId: lastWarehouseOutOne.ID,
  734. WarehouseOutOrderNumber: warehousing_out_order_str,
  735. DrugId: item.DrugId,
  736. Count: prescribing_number_total,
  737. Price: 0,
  738. TotalPrice: 0,
  739. Status: 1,
  740. Ctime: item.AdviceDate,
  741. Mtime: item.AdviceDate,
  742. Remark: "",
  743. OrgId: item.UserOrgId,
  744. Type: 0,
  745. Manufacturer: selfBasedrug.Manufacturer,
  746. Dealer: selfBasedrug.Dealer,
  747. RetailPrice: 0,
  748. RetailTotalPrice: 0,
  749. CountUnit: selfBasedrug.MinUnit,
  750. ExpiryDate: 0,
  751. ProductDate: 0,
  752. Number: "",
  753. BatchNumber: "",
  754. IsSys: 0,
  755. WarehouseInfoId: 0,
  756. AdminUserId: 0,
  757. StockCount: "",
  758. IsCheck: 1,
  759. SysRecordTime: item.AdviceDate,
  760. PatientId: item.PatientId,
  761. AdviceId: item.ID,
  762. ClassType: "",
  763. }
  764. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  765. for _, it := range warehousingOutInfo {
  766. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  767. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  768. //出库逻辑
  769. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  770. //查询剩余库存
  771. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  772. var sum_count int64
  773. for _, its := range stockInfo {
  774. if its.MaxUnit == medical.MaxUnit {
  775. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  776. }
  777. sum_count += its.StockMaxNumber + its.StockMinNumber
  778. }
  779. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  780. }
  781. }
  782. }
  783. }
  784. }
  785. } else {
  786. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  787. for _, item := range advices {
  788. //自备药
  789. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  790. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  791. //查询库存是否
  792. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  793. if selfBasedrug.IsSelfDrug == 1 {
  794. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  795. var prescribing_number_total_one int64
  796. //判断单位是否相等
  797. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  798. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  799. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  800. //转化为最小单位
  801. prescribing_number_total_one = count * selfBasedrug.MinNumber
  802. }
  803. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  804. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  805. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  806. prescribing_number_total_one = count
  807. }
  808. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  809. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  810. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  811. prescribing_number_total_one = count
  812. }
  813. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  814. c.ServeSuccessJSON(map[string]interface{}{
  815. "msg": "2",
  816. "advice": advice,
  817. "ids": ids,
  818. })
  819. return
  820. }
  821. }
  822. }
  823. //恒泰中医院
  824. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  825. if item.DrugId == 0 || item.DrugNameId == 0 {
  826. //从字典里面查找
  827. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  828. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  829. }
  830. }
  831. if item.ExecutionState == 2 {
  832. advice = item
  833. }
  834. }
  835. advicesOne, _ := service.FindDoctorAdviceByIdsOne(adminUserInfo.Org.Id, ids)
  836. for _, item := range advicesOne {
  837. //自备药
  838. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  839. if selfPrescriptionOutOpen.IsOpen == 1 {
  840. db := service.XTWriteDB()
  841. tx := db.Begin()
  842. defer func() {
  843. if r := recover(); r != nil {
  844. tx.Rollback()
  845. } else {
  846. tx.Commit()
  847. }
  848. }()
  849. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  850. if selfBasedrug.IsSelfDrug == 1 {
  851. //查询是否有库存
  852. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  853. var total_count int64
  854. var prescribing_number_total int64
  855. for _, items := range infoList {
  856. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  857. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  858. }
  859. total_count += items.StockMaxNumber + items.StockMinNumber
  860. }
  861. if total_count == 0 {
  862. c.ServeSuccessJSON(map[string]interface{}{
  863. "msg": "2",
  864. "advice": item,
  865. "ids": ids,
  866. })
  867. return
  868. }
  869. //判断单位是否相等
  870. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  871. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  872. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  873. //转化为最小单位
  874. prescribing_number_total = count * selfBasedrug.MinNumber
  875. }
  876. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  877. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  878. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  879. prescribing_number_total = count
  880. }
  881. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  882. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  883. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  884. prescribing_number_total = count
  885. }
  886. if prescribing_number_total > total_count {
  887. c.ServeSuccessJSON(map[string]interface{}{
  888. "msg": "3",
  889. "advice": item,
  890. })
  891. return
  892. }
  893. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  894. //出库
  895. if prescribing_number_total <= total_count {
  896. timeStr := time.Now().Format("2006-01-02")
  897. timeArr := strings.Split(timeStr, "-")
  898. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  899. total = total + 1
  900. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  901. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  902. number = number + total
  903. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  904. operation_time := time.Now().Unix()
  905. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  906. //创建一个出库单
  907. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  908. WarehouseOutOrderNumber: warehousing_out_order,
  909. OperationTime: operation_time,
  910. OrgId: adminUserInfo.Org.Id,
  911. Creater: creater,
  912. Ctime: time.Now().Unix(),
  913. Status: 1,
  914. WarehouseOutTime: item.AdviceDate,
  915. Type: 0,
  916. PatientId: advice.PatientId,
  917. IsCheck: 1,
  918. IsSys: 1,
  919. }
  920. //查询今日是否有出库数据
  921. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  922. if lastWarehouseOut.ID == 0 {
  923. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  924. }
  925. //查询今日是否有出库数据
  926. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  927. var warehousing_out_order_str string
  928. if lastWarehouseOut.ID == 0 {
  929. warehousing_out_order_str = warehousing_out_order
  930. } else {
  931. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  932. }
  933. //出库
  934. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  935. WarehouseOutId: lastWarehouseOutOne.ID,
  936. WarehouseOutOrderNumber: warehousing_out_order_str,
  937. DrugId: item.DrugId,
  938. Count: prescribing_number_total,
  939. Price: 0,
  940. TotalPrice: 0,
  941. Status: 1,
  942. Ctime: item.AdviceDate,
  943. Mtime: item.AdviceDate,
  944. Remark: "",
  945. OrgId: item.UserOrgId,
  946. Type: 0,
  947. Manufacturer: selfBasedrug.Manufacturer,
  948. Dealer: selfBasedrug.Dealer,
  949. RetailPrice: 0,
  950. RetailTotalPrice: 0,
  951. CountUnit: selfBasedrug.MinUnit,
  952. ExpiryDate: 0,
  953. ProductDate: 0,
  954. Number: "",
  955. BatchNumber: "",
  956. IsSys: 0,
  957. WarehouseInfoId: 0,
  958. AdminUserId: 0,
  959. StockCount: "",
  960. IsCheck: 1,
  961. SysRecordTime: item.AdviceDate,
  962. PatientId: item.PatientId,
  963. AdviceId: item.ID,
  964. ClassType: "",
  965. }
  966. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  967. for _, it := range warehousingOutInfo {
  968. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  969. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  970. //出库逻辑
  971. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  972. //查询剩余库存
  973. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  974. var sum_count int64
  975. for _, its := range stockInfo {
  976. if its.MaxUnit == medical.MaxUnit {
  977. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  978. }
  979. sum_count += its.StockMaxNumber + its.StockMinNumber
  980. }
  981. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  982. }
  983. }
  984. }
  985. }
  986. }
  987. }
  988. if advice.ExecutionState == 1 {
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  990. return
  991. }
  992. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  994. return
  995. }
  996. //针对普宁
  997. if adminUserInfo.Org.Id != 10599 {
  998. if advice.StartTime > theTime.Unix() {
  999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1000. return
  1001. }
  1002. }
  1003. advices := models.DoctorAdvice{
  1004. ExecutionStaff: execution_staff,
  1005. ExecutionTime: theTime.Unix(),
  1006. UpdatedTime: time.Now().Unix(),
  1007. }
  1008. var err error
  1009. if groupno > 0 {
  1010. // 查询信息规挡的设置天数
  1011. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1012. if infor.ID > 0 && infor.WeekDay > 0 {
  1013. var cha_time int64
  1014. timeNowStr := time.Now().Format("2006-01-02")
  1015. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1016. //今日的日期减去设置的日期
  1017. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1018. if cha_time >= record_date {
  1019. //查询审核是否允许
  1020. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1021. //申请状态不允许的情况 拒绝修改
  1022. if infor.ApplicationStatus != 1 {
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1024. return
  1025. }
  1026. }
  1027. }
  1028. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1029. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1030. redis := service.RedisClient()
  1031. //清空key 值
  1032. redis.Set(key, "", time.Second)
  1033. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1034. redis.Set(keyTwo, "", time.Second)
  1035. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1036. redis.Set(keyThree, "", time.Second)
  1037. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1038. theTime := toTime.Format("2006-01-02")
  1039. fmt.Println("theTIME", theTime)
  1040. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyFour, "", time.Second)
  1042. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1043. redis.Set(keyFive, "", time.Second)
  1044. defer redis.Close()
  1045. } else {
  1046. // 查询信息规挡的设置天数
  1047. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1048. if infor.ID > 0 {
  1049. var cha_time int64
  1050. timeNowStr := time.Now().Format("2006-01-02")
  1051. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1052. //今日的日期减去设置的日期
  1053. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1054. if cha_time >= record_date {
  1055. //查询审核是否允许
  1056. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1057. //申请状态不允许的情况 拒绝修改
  1058. if infor.ApplicationStatus != 1 {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1060. return
  1061. }
  1062. }
  1063. }
  1064. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  1065. //记录日志
  1066. byterequest, _ := json.Marshal(advice)
  1067. adviceLog := models.XtDoctorAdviceLog{
  1068. UserOrgId: advice.UserOrgId,
  1069. PatientId: advice.PatientId,
  1070. AdminUserId: adminUserInfo.AdminUser.Id,
  1071. Module: 2,
  1072. ErrLog: string(byterequest),
  1073. Status: 1,
  1074. Ctime: time.Now().Unix(),
  1075. Mtime: 0,
  1076. Source: "手机端执行医嘱",
  1077. RecordDate: advices.RecordDate,
  1078. }
  1079. service.CreateDoctorAdviceLog(adviceLog)
  1080. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1081. redis := service.RedisClient()
  1082. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1083. redis.Set(keyTwo, "", time.Second)
  1084. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1085. redis.Set(keyThree, "", time.Second)
  1086. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1087. theTime := toTime.Format("2006-01-02")
  1088. fmt.Println("theTIME", theTime)
  1089. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1090. redis.Set(keyFour, "", time.Second)
  1091. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1092. redis.Set(keySix, "", time.Second)
  1093. defer redis.Close()
  1094. //清空key 值
  1095. redis.Set(key, "", time.Second)
  1096. }
  1097. if err != nil {
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1099. return
  1100. }
  1101. advice.ExecutionStaff = execution_staff
  1102. advice.ExecutionTime = theTime.Unix()
  1103. advice.ExecutionState = 1
  1104. advice.Modifier = adminUserInfo.AdminUser.Id
  1105. //处理出库相关逻辑
  1106. //1.判断是否启用药品管理和自备药出库功能
  1107. //药品管理信息
  1108. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1109. //自备药信息
  1110. //privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  1111. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  1112. if drugStockConfig.IsOpen == 1 {
  1113. if groupno > 0 {
  1114. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  1115. if len(advices) > 0 {
  1116. var total int64
  1117. var prescribing_number_total int64
  1118. //出库
  1119. for _, item := range advices {
  1120. if item.Way == 1 {
  1121. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1122. //查询该药品的剩余库存
  1123. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1124. //查询改药品信息
  1125. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1126. //判断单位是否相等
  1127. if medical.MaxUnit == item.PrescribingNumberUnit {
  1128. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1129. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1130. //转化为最小单位
  1131. total = list.Count * medical.MinNumber
  1132. prescribing_number_total = count * medical.MinNumber
  1133. }
  1134. if medical.MinUnit == item.PrescribingNumberUnit {
  1135. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1136. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1137. total = list.Count*medical.MinNumber + list.StockMinNumber
  1138. prescribing_number_total = count
  1139. }
  1140. if medical.IsUse == 1 {
  1141. c.ServeSuccessJSON(map[string]interface{}{
  1142. "msg": "1",
  1143. "advice": advice,
  1144. "ids": ids,
  1145. })
  1146. return
  1147. }
  1148. if medical.IsUse != 1 {
  1149. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1150. if advice.UserOrgId != 10278 {
  1151. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1152. advice.ExecutionTime = 0
  1153. advice.ExecutionState = 2
  1154. advice.ExecutionStaff = 0
  1155. }
  1156. c.ServeSuccessJSON(map[string]interface{}{
  1157. "msg": "3",
  1158. "advice": advice,
  1159. "ids": ids,
  1160. })
  1161. return
  1162. }
  1163. if prescribing_number_total > total {
  1164. if advice.UserOrgId != 10278 {
  1165. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1166. advice.ExecutionTime = 0
  1167. advice.ExecutionState = 2
  1168. advice.ExecutionStaff = 0
  1169. }
  1170. c.ServeSuccessJSON(map[string]interface{}{
  1171. "msg": "2",
  1172. "advice": advice,
  1173. "ids": ids,
  1174. })
  1175. return
  1176. }
  1177. }
  1178. //查询是否出库按钮开启
  1179. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  1180. if adviceSetting.IsAdviceOpen == 1 {
  1181. //查询是否出库按钮开启
  1182. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  1183. //患者发药
  1184. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1185. if prescriptionConfig.IsOpen == 1 {
  1186. if medical.IsUse == 2 {
  1187. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1188. //查询今日是否出库
  1189. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1190. if drugOutInfo.ID == 0 {
  1191. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1192. }
  1193. }
  1194. if pharmacyConfig.IsOpen != 1 {
  1195. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1196. if drugOutInfo.ID == 0 {
  1197. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1198. }
  1199. }
  1200. //更新字典里面的库存
  1201. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1202. var sum_count int64
  1203. for _, its := range stockInfo {
  1204. if its.MaxUnit == medical.MaxUnit {
  1205. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1206. }
  1207. sum_count += its.StockMaxNumber + its.StockMinNumber
  1208. }
  1209. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1210. //剩余库存
  1211. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1212. }
  1213. }
  1214. } else {
  1215. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1216. if medical.IsUse == 2 {
  1217. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1218. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1219. if drugOutInfo.ID == 0 {
  1220. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1221. }
  1222. }
  1223. if pharmacyConfig.IsOpen != 1 {
  1224. drugError := models.XtDrugError{
  1225. ID: 0,
  1226. UserOrgId: item.UserOrgId,
  1227. DrugId: item.DrugId,
  1228. RecordDate: item.AdviceDate,
  1229. PatientId: item.PatientId,
  1230. Remark: "恒泰中医院出库开始",
  1231. Status: 1,
  1232. Ctime: time.Now().Unix(),
  1233. Mtime: 0,
  1234. Prescribingnumber: item.PrescribingNumber,
  1235. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1236. SumCount: 0,
  1237. }
  1238. service.CreateDrugError(drugError)
  1239. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1240. if drugOutInfo.ID == 0 {
  1241. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1242. }
  1243. }
  1244. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1245. var sum_count int64
  1246. for _, its := range stockInfo {
  1247. if its.MaxUnit == medical.MaxUnit {
  1248. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1249. }
  1250. sum_count += its.StockMaxNumber + its.StockMinNumber
  1251. }
  1252. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1253. //剩余库存
  1254. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. c.ServeSuccessJSON(map[string]interface{}{
  1261. "msg": "1",
  1262. "advice": advice,
  1263. "ids": ids,
  1264. })
  1265. return
  1266. } else {
  1267. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  1268. if len(advices) > 0 {
  1269. var total int64
  1270. var prescribing_number_total int64
  1271. for _, item := range advices {
  1272. if item.Way == 1 {
  1273. //查询改药品信息
  1274. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1275. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1276. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1277. //查询该药品的剩余库存
  1278. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1279. //判断单位是否相等
  1280. if medical.MaxUnit == item.PrescribingNumberUnit {
  1281. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1282. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1283. //转化为最小单位
  1284. total = list.Count*medical.MinNumber + list.StockMinNumber
  1285. prescribing_number_total = count * medical.MinNumber
  1286. }
  1287. if medical.MinUnit == item.PrescribingNumberUnit {
  1288. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1289. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1290. total = list.Count*medical.MinNumber + list.StockMinNumber
  1291. prescribing_number_total = count
  1292. }
  1293. if medical.IsUse == 1 {
  1294. c.ServeSuccessJSON(map[string]interface{}{
  1295. "msg": "1",
  1296. "advice": advice,
  1297. "ids": ids,
  1298. })
  1299. return
  1300. }
  1301. if medical.IsUse != 1 {
  1302. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1303. if advice.UserOrgId != 10278 {
  1304. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1305. advice.ExecutionTime = 0
  1306. advice.ExecutionState = 2
  1307. advice.ExecutionStaff = 0
  1308. }
  1309. c.ServeSuccessJSON(map[string]interface{}{
  1310. "msg": "3",
  1311. "advice": advice,
  1312. "ids": ids,
  1313. })
  1314. return
  1315. }
  1316. if prescribing_number_total > total {
  1317. if advice.UserOrgId != 10278 {
  1318. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1319. advice.ExecutionTime = 0
  1320. advice.ExecutionState = 2
  1321. advice.ExecutionStaff = 0
  1322. }
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "msg": "2",
  1325. "advice": advice,
  1326. "ids": ids,
  1327. })
  1328. return
  1329. }
  1330. }
  1331. if medical.IsUse == 2 {
  1332. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1333. //查询今日是否出库
  1334. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1335. if drugOutInfo.ID == 0 {
  1336. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1337. }
  1338. }
  1339. if pharmacyConfig.IsOpen != 1 {
  1340. //查询今日是否出库
  1341. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1342. if drugOutInfo.ID == 0 {
  1343. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1344. }
  1345. }
  1346. //更新字典里面的库存
  1347. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1348. var sum_count int64
  1349. for _, its := range stockInfo {
  1350. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1351. if its.MaxUnit == baseDrug.MaxUnit {
  1352. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1353. }
  1354. sum_count += its.StockMaxNumber + its.StockMinNumber
  1355. }
  1356. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1357. //剩余库存
  1358. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1359. }
  1360. if medical.IsUse == 1 {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "msg": "1",
  1363. "advice": advice,
  1364. "ids": ids,
  1365. })
  1366. return
  1367. }
  1368. }
  1369. }
  1370. }
  1371. c.ServeSuccessJSON(map[string]interface{}{
  1372. "msg": "1",
  1373. "advice": advice,
  1374. "ids": ids,
  1375. })
  1376. return
  1377. }
  1378. }
  1379. //if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1380. // if groupno > 0 {
  1381. // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1382. // for _, item := range advices {
  1383. //
  1384. // if item.ExecutionState == 1 && item.Way == 2 {
  1385. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1386. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1387. //
  1388. // timeStr := time.Now().Format("2006-01-02")
  1389. // timeArr := strings.Split(timeStr, "-")
  1390. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1391. //
  1392. // total = total + 1
  1393. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1394. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1395. // number = number + total
  1396. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1397. // //插入自备药出库单
  1398. // outStock := models.XtSelfOutStock{
  1399. // DrugName: item.AdviceName,
  1400. // DrugNameId: item.DrugNameId,
  1401. // DrugSpec: item.AdviceDesc,
  1402. // OutstoreNumber: count,
  1403. // AdminUserId: adminUserInfo.AdminUser.Id,
  1404. // StorckTime: item.AdviceDate,
  1405. // UserOrgId: adminUserInfo.Org.Id,
  1406. // CreatedTime: time.Now().Unix(),
  1407. // Status: 1,
  1408. // PatientId: item.PatientId,
  1409. // ExitMode: 2,
  1410. // MedicId: item.DrugId,
  1411. // StockOutNumber: warehousing_out_order,
  1412. // }
  1413. // //查询 该患者是否已出库
  1414. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1415. //
  1416. // if errcode == gorm.ErrRecordNotFound {
  1417. // service.CreateOutStock(&outStock)
  1418. // } else if errcode == nil {
  1419. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1420. // fmt.Println("err", err)
  1421. // }
  1422. // }
  1423. // }
  1424. // } else {
  1425. //
  1426. // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1427. // for _, item := range advices {
  1428. //
  1429. // if item.ExecutionState == 1 && item.Way == 2 {
  1430. //
  1431. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1432. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1433. //
  1434. // timeStr := time.Now().Format("2006-01-02")
  1435. // timeArr := strings.Split(timeStr, "-")
  1436. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1437. //
  1438. // total = total + 1
  1439. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1440. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1441. // number = number + total
  1442. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1443. //
  1444. // //插入自备药出库单
  1445. // outStock := models.XtSelfOutStock{
  1446. // DrugName: item.AdviceName,
  1447. // DrugNameId: item.DrugNameId,
  1448. // DrugSpec: item.AdviceDesc,
  1449. // OutstoreNumber: count,
  1450. // AdminUserId: adminUserInfo.AdminUser.Id,
  1451. // StorckTime: item.AdviceDate,
  1452. // UserOrgId: adminUserInfo.Org.Id,
  1453. // CreatedTime: time.Now().Unix(),
  1454. // Status: 1,
  1455. // PatientId: item.PatientId,
  1456. // ExitMode: 2,
  1457. // MedicId: item.DrugId,
  1458. // StockOutNumber: warehousing_out_order,
  1459. // }
  1460. //
  1461. // //查询 该患者是否已出库
  1462. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1463. //
  1464. // if errcode == gorm.ErrRecordNotFound {
  1465. // service.CreateOutStock(&outStock)
  1466. // } else if errcode == nil {
  1467. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1468. // fmt.Println("err", err)
  1469. // }
  1470. // }
  1471. // }
  1472. // c.ServeSuccessJSON(map[string]interface{}{
  1473. // "msg": "1",
  1474. // "advice": advice,
  1475. // "ids": ids,
  1476. // })
  1477. // return
  1478. // }
  1479. //}
  1480. c.ServeSuccessJSON(map[string]interface{}{
  1481. "msg": "1",
  1482. "advice": advice,
  1483. "ids": ids,
  1484. })
  1485. return
  1486. } else if origin == 2 {
  1487. // 开始主事务
  1488. db := service.XTWriteDB()
  1489. tx := db.Begin()
  1490. // 在函数结束时处理事务回滚
  1491. defer func() {
  1492. if r := recover(); r != nil {
  1493. tx.Rollback()
  1494. }
  1495. }()
  1496. adminInfo := c.GetMobileAdminUserInfo()
  1497. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1498. var ids []string
  1499. advice_ids := c.GetString("advice_id")
  1500. ids = strings.Split(advice_ids, ",")
  1501. if len(execution_time) <= 0 {
  1502. utils.ErrorLog("execution_time")
  1503. tx.Rollback()
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. timeLayout2 := "2006-01-02 15:04:05"
  1508. loc, _ := time.LoadLocation("Local")
  1509. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1510. if errs != nil {
  1511. utils.ErrorLog(errs.Error())
  1512. tx.Rollback()
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1517. var err error
  1518. for _, item := range advices {
  1519. if item.ExecutionState == 1 {
  1520. tx.Rollback()
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1522. return
  1523. }
  1524. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1525. tx.Rollback()
  1526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1527. return
  1528. }
  1529. if item.StartTime > theTime.Unix() {
  1530. tx.Rollback()
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1532. return
  1533. }
  1534. item.ExecutionState = 1
  1535. item.ExecutionStaff = adminInfo.AdminUser.Id
  1536. item.ExecutionTime = theTime.Unix()
  1537. item.IsMobile = 1
  1538. // 查询信息规挡的设置天数
  1539. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1540. if infor.ID > 0 {
  1541. var cha_time int64
  1542. timeNowStr := time.Now().Format("2006-01-02")
  1543. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1544. //今日的日期减去设置的日期
  1545. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1546. if cha_time >= item.AdviceDate {
  1547. //查询审核是否允许
  1548. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1549. //申请状态不允许的情况 拒绝修改
  1550. if infor.ApplicationStatus != 1 {
  1551. tx.Rollback()
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. service.SaveHisDoctorAdviceOne(item, tx)
  1558. //记录日志
  1559. byterequest, _ := json.Marshal(item)
  1560. adviceLog := models.XtDoctorAdviceLog{
  1561. UserOrgId: item.UserOrgId,
  1562. PatientId: item.PatientId,
  1563. AdminUserId: item.ExecutionStaff,
  1564. Module: 2,
  1565. ErrLog: string(byterequest),
  1566. Status: 1,
  1567. Ctime: time.Now().Unix(),
  1568. Mtime: 0,
  1569. Source: "手机端执行his医嘱",
  1570. RecordDate: item.AdviceDate,
  1571. }
  1572. service.CreateDoctorAdviceLog(adviceLog)
  1573. if err == nil {
  1574. drugError := models.XtDrugError{
  1575. UserOrgId: adminInfo.Org.Id,
  1576. DrugId: item.DrugId,
  1577. RecordDate: item.AdviceDate,
  1578. PatientId: item.PatientId,
  1579. Remark: "执行成功",
  1580. Status: 1,
  1581. Ctime: time.Now().Unix(),
  1582. Mtime: 0,
  1583. SumCount: 0,
  1584. Prescribingnumber: item.PrescribingNumber,
  1585. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1586. }
  1587. service.CreateDrugError(drugError)
  1588. }
  1589. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1590. redis := service.RedisClient()
  1591. //清空key 值
  1592. redis.Set(key, "", time.Second)
  1593. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1594. redis.Set(keyTwo, "", time.Second)
  1595. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1596. redis.Set(keyThree, "", time.Second)
  1597. recordDate := theTime.Format("2006-01-02")
  1598. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1599. redis.Set(keyFour, "", time.Second)
  1600. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1601. redis.Set(keyFive, "", time.Second)
  1602. defer redis.Close()
  1603. }
  1604. //药品管理信息
  1605. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1606. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1607. if drugStockConfig.IsOpen == 1 {
  1608. for _, item := range advices {
  1609. //查询改药品信息
  1610. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1611. //判断单位是否合格
  1612. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1613. //查询该药品是否有出库记录
  1614. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1615. if len(flowMap) == 0 {
  1616. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1617. if errs != nil {
  1618. drugError := models.XtDrugError{
  1619. UserOrgId: adminInfo.Org.Id,
  1620. DrugId: item.DrugId,
  1621. RecordDate: item.AdviceDate,
  1622. PatientId: item.PatientId,
  1623. Remark: "单位不统一,执行失败",
  1624. Status: 1,
  1625. Ctime: time.Now().Unix(),
  1626. Mtime: 0,
  1627. SumCount: 0,
  1628. Prescribingnumber: item.PrescribingNumber,
  1629. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1630. }
  1631. service.CreateDrugError(drugError)
  1632. }
  1633. }
  1634. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1635. tx.Rollback()
  1636. c.ServeSuccessJSON(map[string]interface{}{
  1637. "msg": "7",
  1638. "advice": advice,
  1639. "ids": ids,
  1640. })
  1641. return
  1642. }
  1643. //查询这个患者这个患者这个药已经出库的所有数量
  1644. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1645. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1646. var total_count int64
  1647. var drug_count int64
  1648. for _, it := range advicelist {
  1649. if it.PrescribingNumberUnit == medical.MaxUnit {
  1650. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1651. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1652. total_count += prenumber * medical.MinNumber
  1653. }
  1654. if it.PrescribingNumberUnit == medical.MinUnit {
  1655. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1656. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1657. total_count += prenumber
  1658. }
  1659. }
  1660. for _, its := range drugoutlist {
  1661. if its.CountUnit == medical.MaxUnit {
  1662. drug_count += its.Count * medical.MinNumber
  1663. }
  1664. if its.CountUnit == medical.MinUnit {
  1665. drug_count += its.Count
  1666. }
  1667. }
  1668. if total_count == drug_count {
  1669. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1670. tx.Commit()
  1671. c.ServeSuccessJSON(map[string]interface{}{
  1672. "msg": "1",
  1673. "advice": advice,
  1674. "ids": ids,
  1675. })
  1676. return
  1677. }
  1678. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1679. var total int64
  1680. var prescribing_number_total int64
  1681. //保存处方出库
  1682. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1683. if config.IsOpen != 1 {
  1684. //查询该药品是否有库存
  1685. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1686. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1687. //判断单位是否相等
  1688. if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1689. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1690. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1691. //转化为最小单位
  1692. total = list.Count*medical.MinNumber + list.StockMinNumber
  1693. prescribing_number_total = count * medical.MinNumber
  1694. }
  1695. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1696. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1697. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1698. total = list.Count*medical.MinNumber + list.StockMinNumber
  1699. prescribing_number_total = count
  1700. }
  1701. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
  1702. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1703. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1704. total = list.Count*medical.MinNumber + list.StockMinNumber
  1705. prescribing_number_total = count
  1706. }
  1707. if medical.IsUse == 1 {
  1708. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1709. drugError := models.XtDrugError{
  1710. UserOrgId: adminInfo.Org.Id,
  1711. DrugId: item.DrugId,
  1712. RecordDate: item.AdviceDate,
  1713. PatientId: item.PatientId,
  1714. Remark: "零用药品库存不足",
  1715. Status: 1,
  1716. Ctime: time.Now().Unix(),
  1717. Mtime: 0,
  1718. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1719. Prescribingnumber: advice.PrescribingNumber,
  1720. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1721. }
  1722. service.CreateDrugError(drugError)
  1723. tx.Rollback()
  1724. c.ServeSuccessJSON(map[string]interface{}{
  1725. "msg": "1",
  1726. "advice": advice,
  1727. "ids": ids,
  1728. })
  1729. return
  1730. }
  1731. }
  1732. if medical.IsUse != 1 {
  1733. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1734. drugError := models.XtDrugError{
  1735. UserOrgId: adminInfo.Org.Id,
  1736. DrugId: item.DrugId,
  1737. RecordDate: item.AdviceDate,
  1738. PatientId: item.PatientId,
  1739. Remark: "药品库存不足",
  1740. Status: 1,
  1741. Ctime: time.Now().Unix(),
  1742. Mtime: 0,
  1743. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1744. Prescribingnumber: advice.PrescribingNumber,
  1745. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1746. }
  1747. service.CreateDrugError(drugError)
  1748. tx.Rollback()
  1749. c.ServeSuccessJSON(map[string]interface{}{
  1750. "msg": "3",
  1751. "advice": advice,
  1752. "ids": ids,
  1753. })
  1754. return
  1755. }
  1756. if prescribing_number_total > total {
  1757. drugError := models.XtDrugError{
  1758. UserOrgId: adminInfo.Org.Id,
  1759. DrugId: item.DrugId,
  1760. RecordDate: item.AdviceDate,
  1761. PatientId: item.PatientId,
  1762. Remark: "出库数量大于库存",
  1763. Status: 1,
  1764. Ctime: time.Now().Unix(),
  1765. Mtime: 0,
  1766. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1767. Prescribingnumber: advice.PrescribingNumber,
  1768. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1769. }
  1770. service.CreateDrugError(drugError)
  1771. tx.Rollback()
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "msg": "2",
  1774. "advice": advice,
  1775. "ids": ids,
  1776. })
  1777. return
  1778. }
  1779. }
  1780. if prescribing_number_total <= total {
  1781. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1782. //判断药品是否零用
  1783. if medical.IsUse == 2 {
  1784. if config.IsOpen != 1 {
  1785. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1786. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1787. //查询该药品是否有出库记录
  1788. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1789. if len(flowMap) == 0 {
  1790. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1791. if errs != nil {
  1792. drugError := models.XtDrugError{
  1793. UserOrgId: adminInfo.Org.Id,
  1794. DrugId: item.DrugId,
  1795. RecordDate: item.AdviceDate,
  1796. PatientId: item.PatientId,
  1797. Remark: "出库记录为空,更新执行人失败",
  1798. Status: 1,
  1799. Ctime: time.Now().Unix(),
  1800. Mtime: 0,
  1801. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1802. Prescribingnumber: advice.PrescribingNumber,
  1803. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1804. }
  1805. service.CreateDrugError(drugError)
  1806. }
  1807. tx.Rollback()
  1808. c.ServeSuccessJSON(map[string]interface{}{
  1809. "msg": "6",
  1810. "advice": advice,
  1811. "ids": ids,
  1812. })
  1813. return
  1814. }
  1815. }
  1816. }
  1817. if pharmacyConfig.IsOpen != 1 {
  1818. //查询已经出库数量
  1819. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1820. var out_count int64
  1821. if len(outListExport) > 0 {
  1822. for _, item := range outListExport {
  1823. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1824. out_count = item.Count * medical.MinNumber
  1825. }
  1826. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1827. out_count = item.Count
  1828. }
  1829. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1830. out_count = item.Count * medical.MinNumber
  1831. }
  1832. }
  1833. }
  1834. newadviceInfo := &models.HisDoctorAdviceInfo{
  1835. ID: advice.ID,
  1836. UserOrgId: advice.UserOrgId,
  1837. PatientId: advice.PatientId,
  1838. HisPatientId: advice.HisPatientId,
  1839. AdviceType: advice.AdviceType,
  1840. AdviceDate: advice.AdviceDate,
  1841. StartTime: advice.StartTime,
  1842. AdviceName: advice.AdviceName,
  1843. AdviceDesc: advice.AdviceDesc,
  1844. ReminderDate: advice.ReminderDate,
  1845. SingleDose: advice.SingleDose,
  1846. SingleDoseUnit: advice.SingleDoseUnit,
  1847. PrescribingNumber: advice.PrescribingNumber,
  1848. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1849. DeliveryWay: advice.DeliveryWay,
  1850. ExecutionFrequency: advice.ExecutionFrequency,
  1851. AdviceDoctor: advice.AdviceDoctor,
  1852. Status: advice.Status,
  1853. CreatedTime: advice.CreatedTime,
  1854. UpdatedTime: advice.UpdatedTime,
  1855. AdviceAffirm: advice.AdviceAffirm,
  1856. Remark: advice.Remark,
  1857. StopTime: advice.StopTime,
  1858. StopReason: advice.StopReason,
  1859. StopDoctor: advice.StopDoctor,
  1860. StopState: advice.StopState,
  1861. ParentId: advice.ParentId,
  1862. ExecutionTime: advice.ExecutionTime,
  1863. ExecutionStaff: advice.ExecutionStaff,
  1864. ExecutionState: advice.ExecutionState,
  1865. Checker: advice.Checker,
  1866. RecordDate: advice.RecordDate,
  1867. DialysisOrderId: advice.DialysisOrderId,
  1868. CheckTime: advice.CheckTime,
  1869. CheckState: advice.CheckState,
  1870. DrugSpec: advice.DrugSpec,
  1871. DrugSpecUnit: advice.DrugSpecUnit,
  1872. Groupno: advice.Groupno,
  1873. RemindType: advice.RemindType,
  1874. FrequencyType: advice.FrequencyType,
  1875. DayCount: advice.DayCount,
  1876. WeekDay: advice.WeekDay,
  1877. TemplateId: advice.TemplateId,
  1878. Modifier: advice.Modifier,
  1879. DrugId: advice.DrugId,
  1880. Price: advice.Price,
  1881. PrescriptionId: advice.PrescriptionId,
  1882. MedListCodg: advice.MedListCodg,
  1883. FeedetlSn: advice.FeedetlSn,
  1884. Day: advice.DayCount,
  1885. ChildDoctorAdvice: nil,
  1886. Drug: models.Drug{},
  1887. Diagnosis: advice.Diagnosis,
  1888. Way: advice.Way,
  1889. HospApprFlag: advice.HospApprFlag,
  1890. LmtUsedFlag: advice.LmtUsedFlag,
  1891. HisOrderInfo: models.HisOrderInfo{},
  1892. IsMedicine: advice.IsMedicine,
  1893. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1894. Child: nil,
  1895. IsSettle: advice.IsSettle,
  1896. IsMobile: advice.IsMobile,
  1897. IsSelfDrug: advice.IsSelfDrug,
  1898. DrugWayCount: advice.DrugWayCount,
  1899. }
  1900. //如果当前医嘱数量大于历史出库数据则需要出库
  1901. if prescribing_number_total > out_count {
  1902. //按最小单位出库
  1903. var cha_count = prescribing_number_total - out_count
  1904. newadviceInfo.PrescribingNumber = float64(cha_count)
  1905. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1906. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1907. }
  1908. //如果当前医嘱数量小于历史出库数据则需要退库
  1909. if prescribing_number_total < out_count {
  1910. var cha_count = out_count - prescribing_number_total
  1911. drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
  1912. service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1913. service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1914. }
  1915. if prescribing_number_total == out_count {
  1916. if out_count == 0 {
  1917. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1918. }
  1919. }
  1920. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1921. //查询该药品是否有出库记录
  1922. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1923. if len(flowMap) == 0 {
  1924. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1925. if errs != nil {
  1926. drugError := models.XtDrugError{
  1927. UserOrgId: adminInfo.Org.Id,
  1928. DrugId: item.DrugId,
  1929. RecordDate: item.AdviceDate,
  1930. PatientId: item.PatientId,
  1931. Remark: "出库记录为空,更新执行人失败",
  1932. Status: 1,
  1933. Ctime: time.Now().Unix(),
  1934. Mtime: 0,
  1935. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1936. Prescribingnumber: advice.PrescribingNumber,
  1937. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1938. }
  1939. service.CreateDrugError(drugError)
  1940. }
  1941. tx.Rollback()
  1942. c.ServeSuccessJSON(map[string]interface{}{
  1943. "msg": "6",
  1944. "advice": advice,
  1945. "ids": ids,
  1946. })
  1947. return
  1948. }
  1949. }
  1950. }
  1951. //更新字典里面的库存
  1952. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1953. var sum_count int64
  1954. for _, its := range stockInfo {
  1955. if its.MaxUnit == medical.MaxUnit {
  1956. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1957. }
  1958. sum_count += its.StockMaxNumber + its.StockMinNumber
  1959. }
  1960. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1961. //剩余库存
  1962. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1963. }
  1964. }
  1965. }
  1966. }
  1967. //自备药
  1968. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminInfo.Org.Id)
  1969. if selfPrescriptionOutOpen.IsOpen == 1 {
  1970. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  1971. if selfBasedrug.IsSelfDrug == 1 {
  1972. //查询是否有库存
  1973. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  1974. if len(info) > 0 {
  1975. var total_count int64
  1976. var prescribing_number_total int64
  1977. for _, item := range info {
  1978. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1979. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  1980. }
  1981. total_count += item.StockMaxNumber + item.StockMinNumber
  1982. }
  1983. //判断单位是否相等
  1984. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1985. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1986. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1987. //转化为最小单位
  1988. prescribing_number_total = count * selfBasedrug.MinNumber
  1989. }
  1990. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1991. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1992. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1993. prescribing_number_total = count
  1994. }
  1995. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  1996. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1997. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1998. prescribing_number_total = count
  1999. }
  2000. if prescribing_number_total > total_count {
  2001. c.ServeSuccessJSON(map[string]interface{}{
  2002. "msg": "3",
  2003. "advice": advice,
  2004. })
  2005. return
  2006. }
  2007. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2008. //出库
  2009. if prescribing_number_total <= total_count {
  2010. timeStr := time.Now().Format("2006-01-02")
  2011. timeArr := strings.Split(timeStr, "-")
  2012. total, _ := service.FindAllSelfDrugWarehouseOut(adminInfo.Org.Id, tx)
  2013. total = total + 1
  2014. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2015. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2016. number = number + total
  2017. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2018. operation_time := time.Now().Unix()
  2019. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  2020. //创建一个出库单
  2021. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2022. WarehouseOutOrderNumber: warehousing_out_order,
  2023. OperationTime: operation_time,
  2024. OrgId: adminInfo.Org.Id,
  2025. Creater: creater,
  2026. Ctime: time.Now().Unix(),
  2027. Status: 1,
  2028. WarehouseOutTime: advice.AdviceDate,
  2029. Type: 0,
  2030. PatientId: advice.PatientId,
  2031. IsCheck: 1,
  2032. IsSys: 1,
  2033. }
  2034. //查询今日是否有出库数据
  2035. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2036. if lastWarehouseOut.ID == 0 {
  2037. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2038. }
  2039. //查询今日是否有出库数据
  2040. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2041. //出库
  2042. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2043. WarehouseOutId: lastWarehouseOutOne.ID,
  2044. WarehouseOutOrderNumber: warehousing_out_order,
  2045. DrugId: advice.DrugId,
  2046. Count: prescribing_number_total,
  2047. Price: 0,
  2048. TotalPrice: 0,
  2049. Status: 1,
  2050. Ctime: advice.AdviceDate,
  2051. Mtime: advice.AdviceDate,
  2052. Remark: "",
  2053. OrgId: advice.UserOrgId,
  2054. Type: 0,
  2055. Manufacturer: selfBasedrug.Manufacturer,
  2056. Dealer: selfBasedrug.Dealer,
  2057. RetailPrice: 0,
  2058. RetailTotalPrice: 0,
  2059. CountUnit: selfBasedrug.MinUnit,
  2060. ExpiryDate: 0,
  2061. ProductDate: 0,
  2062. Number: "",
  2063. BatchNumber: "",
  2064. IsSys: 0,
  2065. WarehouseInfoId: 0,
  2066. AdminUserId: 0,
  2067. StockCount: "",
  2068. IsCheck: 1,
  2069. SysRecordTime: advice.AdviceDate,
  2070. PatientId: advice.PatientId,
  2071. AdviceId: advice.ID,
  2072. ClassType: "",
  2073. }
  2074. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2075. for _, it := range warehousingOutInfo {
  2076. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2077. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2078. //出库逻辑
  2079. service.AutoSelfDrugDeliverInfoFourtyTwo(adminInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2080. //查询剩余库存
  2081. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2082. var sum_count int64
  2083. for _, its := range stockInfo {
  2084. if its.MaxUnit == medical.MaxUnit {
  2085. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2086. }
  2087. sum_count += its.StockMaxNumber + its.StockMinNumber
  2088. }
  2089. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2090. }
  2091. }
  2092. } else {
  2093. c.ServeSuccessJSON(map[string]interface{}{
  2094. "msg": "3",
  2095. "advice": advice,
  2096. })
  2097. return
  2098. }
  2099. }
  2100. }
  2101. //针对异常未出库问题的脚本
  2102. //if adminInfo.Org.Id == 10265 {
  2103. //
  2104. // newadviceInfo := &models.HisDoctorAdviceInfo{
  2105. // ID: advice.ID,
  2106. // UserOrgId: advice.UserOrgId,
  2107. // PatientId: advice.PatientId,
  2108. // HisPatientId: advice.HisPatientId,
  2109. // AdviceType: advice.AdviceType,
  2110. // AdviceDate: advice.AdviceDate,
  2111. // StartTime: advice.StartTime,
  2112. // AdviceName: advice.AdviceName,
  2113. // AdviceDesc: advice.AdviceDesc,
  2114. // ReminderDate: advice.ReminderDate,
  2115. // SingleDose: advice.SingleDose,
  2116. // SingleDoseUnit: advice.SingleDoseUnit,
  2117. // PrescribingNumber: advice.PrescribingNumber,
  2118. // PrescribingNumberUnit: advice.PrescribingNumberUnit,
  2119. // DeliveryWay: advice.DeliveryWay,
  2120. // ExecutionFrequency: advice.ExecutionFrequency,
  2121. // AdviceDoctor: advice.AdviceDoctor,
  2122. // Status: advice.Status,
  2123. // CreatedTime: advice.CreatedTime,
  2124. // UpdatedTime: advice.UpdatedTime,
  2125. // AdviceAffirm: advice.AdviceAffirm,
  2126. // Remark: advice.Remark,
  2127. // StopTime: advice.StopTime,
  2128. // StopReason: advice.StopReason,
  2129. // StopDoctor: advice.StopDoctor,
  2130. // StopState: advice.StopState,
  2131. // ParentId: advice.ParentId,
  2132. // ExecutionTime: advice.ExecutionTime,
  2133. // ExecutionStaff: advice.ExecutionStaff,
  2134. // ExecutionState: advice.ExecutionState,
  2135. // Checker: advice.Checker,
  2136. // RecordDate: advice.RecordDate,
  2137. // DialysisOrderId: advice.DialysisOrderId,
  2138. // CheckTime: advice.CheckTime,
  2139. // CheckState: advice.CheckState,
  2140. // DrugSpec: advice.DrugSpec,
  2141. // DrugSpecUnit: advice.DrugSpecUnit,
  2142. // Groupno: advice.Groupno,
  2143. // RemindType: advice.RemindType,
  2144. // FrequencyType: advice.FrequencyType,
  2145. // DayCount: advice.DayCount,
  2146. // WeekDay: advice.WeekDay,
  2147. // TemplateId: advice.TemplateId,
  2148. // Modifier: advice.Modifier,
  2149. // DrugId: advice.DrugId,
  2150. // Price: advice.Price,
  2151. // PrescriptionId: advice.PrescriptionId,
  2152. // MedListCodg: advice.MedListCodg,
  2153. // FeedetlSn: advice.FeedetlSn,
  2154. // Day: advice.DayCount,
  2155. // ChildDoctorAdvice: nil,
  2156. // Drug: models.Drug{},
  2157. // Diagnosis: advice.Diagnosis,
  2158. // Way: advice.Way,
  2159. // HospApprFlag: advice.HospApprFlag,
  2160. // LmtUsedFlag: advice.LmtUsedFlag,
  2161. // HisOrderInfo: models.HisOrderInfo{},
  2162. // IsMedicine: advice.IsMedicine,
  2163. // ExecutionFrequencyId: advice.ExecutionFrequencyId,
  2164. // Child: nil,
  2165. // IsSettle: advice.IsSettle,
  2166. // IsMobile: advice.IsMobile,
  2167. // IsSelfDrug: advice.IsSelfDrug,
  2168. // DrugWayCount: advice.DrugWayCount,
  2169. // }
  2170. // outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  2171. // fmt.Println(outListExport)
  2172. // //var out_count int64
  2173. // //if len(outListExport) > 0 {
  2174. // // for _, item := range outListExport {
  2175. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2176. // // out_count = item.Count * medical.MinNumber
  2177. // // }
  2178. // // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2179. // // out_count = item.Count
  2180. // // }
  2181. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2182. // // out_count = item.Count * medical.MinNumber
  2183. // // }
  2184. // //
  2185. // // }
  2186. // //}
  2187. // //按最小单位出库
  2188. // //var cha_count = total_count - out_count
  2189. //
  2190. // var cha_count = 40
  2191. //
  2192. // newadviceInfo.PrescribingNumber = float64(cha_count)
  2193. // newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2194. // service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  2195. //
  2196. // //查询剩余库存
  2197. // stockInfo, _ := service.GetSelfDrugAllStockInfo(newadviceInfo.PatientId, newadviceInfo.UserOrgId, newadviceInfo.DrugId, tx)
  2198. // var sum_count int64
  2199. // for _, its := range stockInfo {
  2200. // if its.MaxUnit == medical.MaxUnit {
  2201. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2202. // }
  2203. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2204. // }
  2205. // service.UpdateSelfDrugStockCount(newadviceInfo.DrugId, newadviceInfo.UserOrgId, newadviceInfo.PatientId, sum_count, tx)
  2206. //}
  2207. }
  2208. }
  2209. tx.Commit()
  2210. for _, item := range advices {
  2211. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  2212. c.ServeSuccessJSON(map[string]interface{}{
  2213. "msg": "1",
  2214. "advice": advice,
  2215. "ids": ids,
  2216. })
  2217. }
  2218. }
  2219. }
  2220. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  2221. execution_time := c.GetString("execution_time")
  2222. fmt.Println("execution_time", execution_time)
  2223. groupno, _ := c.GetInt64("groupno", -1)
  2224. //patient_id, _ := c.GetInt64("patient_id")
  2225. advice_date, _ := c.GetInt64("advice_date")
  2226. var ids []string
  2227. if groupno == 0 {
  2228. advice_ids := c.GetString("advice_id")
  2229. ids = strings.Split(advice_ids, ",")
  2230. }
  2231. if groupno < 0 {
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. if len(execution_time) <= 0 {
  2236. utils.ErrorLog("execution_time")
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. return
  2239. }
  2240. timeLayout2 := "2006-01-02 15:04:05"
  2241. loc, _ := time.LoadLocation("Local")
  2242. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2243. if errs != nil {
  2244. utils.ErrorLog(errs.Error())
  2245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2246. return
  2247. }
  2248. adminUserInfo := c.GetMobileAdminUserInfo()
  2249. var advice models.DoctorAdvice
  2250. if groupno > 0 {
  2251. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2252. for _, item := range advices {
  2253. if item.ExecutionState == 1 {
  2254. advice = item
  2255. }
  2256. }
  2257. } else {
  2258. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2259. for _, item := range advices {
  2260. if item.ExecutionState == 1 {
  2261. advice = item
  2262. }
  2263. }
  2264. }
  2265. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  2266. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2267. // if getPermissionErr != nil {
  2268. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2269. // return
  2270. // } else if headNursePermission == nil {
  2271. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2272. // return
  2273. // }
  2274. //}
  2275. if advice.StartTime > theTime.Unix() {
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2277. return
  2278. }
  2279. advices := models.DoctorAdvice{
  2280. ExecutionTime: theTime.Unix(),
  2281. UpdatedTime: time.Now().Unix(),
  2282. }
  2283. var err error
  2284. if groupno > 0 {
  2285. // 查询信息规挡的设置天数
  2286. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2287. if infor.ID > 0 {
  2288. var cha_time int64
  2289. timeNowStr := time.Now().Format("2006-01-02")
  2290. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2291. //今日的日期减去设置的日期
  2292. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2293. if cha_time >= advices.AdviceDate {
  2294. //查询审核是否允许
  2295. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2296. //申请状态不允许的情况 拒绝修改
  2297. if infor.ApplicationStatus != 1 {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2304. //记录日志
  2305. byterequest, _ := json.Marshal(advices)
  2306. adviceLog := models.XtDoctorAdviceLog{
  2307. UserOrgId: adminUserInfo.Org.Id,
  2308. PatientId: advices.PatientId,
  2309. AdminUserId: adminUserInfo.AdminUser.Id,
  2310. Module: 1,
  2311. ErrLog: string(byterequest),
  2312. Status: 1,
  2313. Ctime: time.Now().Unix(),
  2314. Mtime: 0,
  2315. Source: "手机端编辑医嘱",
  2316. RecordDate: advices.AdviceDate,
  2317. }
  2318. service.CreateDoctorAdviceLog(adviceLog)
  2319. redis := service.RedisClient()
  2320. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2321. redis.Set(key, "", time.Second)
  2322. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2323. redis.Set(keyOne, "", time.Second)
  2324. defer redis.Close()
  2325. } else {
  2326. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2327. if infor.ID > 0 {
  2328. var cha_time int64
  2329. timeNowStr := time.Now().Format("2006-01-02")
  2330. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2331. //今日的日期减去设置的日期
  2332. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2333. if cha_time >= advices.AdviceDate {
  2334. //查询审核是否允许
  2335. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2336. //申请状态不允许的情况 拒绝修改
  2337. if infor.ApplicationStatus != 1 {
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2339. return
  2340. }
  2341. }
  2342. }
  2343. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  2344. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  2345. //记录日志
  2346. byterequest, _ := json.Marshal(advices)
  2347. adviceLog := models.XtDoctorAdviceLog{
  2348. UserOrgId: adminUserInfo.Org.Id,
  2349. PatientId: advices.PatientId,
  2350. AdminUserId: adminUserInfo.AdminUser.Id,
  2351. Module: 1,
  2352. ErrLog: string(byterequest),
  2353. Status: 1,
  2354. Ctime: time.Now().Unix(),
  2355. Mtime: 0,
  2356. Source: "手机端编辑执行医嘱",
  2357. RecordDate: advices.AdviceDate,
  2358. }
  2359. service.CreateDoctorAdviceLog(adviceLog)
  2360. redis := service.RedisClient()
  2361. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2362. redis.Set(key, "", time.Second)
  2363. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  2364. redis.Set(keyOne, "", time.Second)
  2365. defer redis.Close()
  2366. }
  2367. //判断是否开启his
  2368. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2369. //如果开启去修改执行时间
  2370. if config.IsOpen == 1 {
  2371. advicesinfo := models.HisDoctorAdviceInfo{
  2372. ExecutionTime: theTime.Unix(),
  2373. UpdatedTime: time.Now().Unix(),
  2374. }
  2375. var advicehis models.HisDoctorAdviceInfo
  2376. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  2377. //记录日志
  2378. byterequest, _ := json.Marshal(advicesinfo)
  2379. adviceLog := models.XtDoctorAdviceLog{
  2380. UserOrgId: adminUserInfo.Org.Id,
  2381. PatientId: advices.PatientId,
  2382. AdminUserId: adminUserInfo.AdminUser.Id,
  2383. Module: 1,
  2384. ErrLog: string(byterequest),
  2385. Status: 1,
  2386. Ctime: time.Now().Unix(),
  2387. Mtime: 0,
  2388. Source: "手机端his编辑医嘱",
  2389. RecordDate: advices.AdviceDate,
  2390. }
  2391. service.CreateDoctorAdviceLog(adviceLog)
  2392. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  2393. for _, item := range his_advices {
  2394. if item.ExecutionState == 1 {
  2395. advicehis = item
  2396. }
  2397. }
  2398. redis := service.RedisClient()
  2399. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  2400. redis.Set(keyThree, "", time.Second)
  2401. recordDate := theTime.Format("2006-01-02")
  2402. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2403. redis.Set(keyFour, "", time.Second)
  2404. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  2405. redis.Set(keyFive, "", time.Second)
  2406. defer redis.Close()
  2407. project := models.HisPrescriptionProject{
  2408. ExecutionTime: theTime.Unix(),
  2409. Mtime: time.Now().Unix(),
  2410. }
  2411. service.ModifyHisPrescriptionProject(&project, ids)
  2412. //记录日志
  2413. projectquerst, _ := json.Marshal(project)
  2414. projectLog := models.XtDoctorAdviceLog{
  2415. UserOrgId: adminUserInfo.Org.Id,
  2416. PatientId: advices.PatientId,
  2417. AdminUserId: adminUserInfo.AdminUser.Id,
  2418. Module: 1,
  2419. ErrLog: string(projectquerst),
  2420. Status: 1,
  2421. Ctime: time.Now().Unix(),
  2422. Mtime: 0,
  2423. Source: "手机端his编辑项目医嘱",
  2424. RecordDate: advices.AdviceDate,
  2425. }
  2426. service.CreateDoctorAdviceLog(projectLog)
  2427. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  2428. redis.Set(keyEnd, "", time.Second)
  2429. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2430. redis.Set(keyFours, "", time.Second)
  2431. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  2432. redis.Set(keyFives, "", time.Second)
  2433. defer redis.Close()
  2434. }
  2435. if err != nil {
  2436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2437. return
  2438. }
  2439. advice.ExecutionTime = theTime.Unix()
  2440. c.ServeSuccessJSON(map[string]interface{}{
  2441. "msg": "ok",
  2442. "advice": advice,
  2443. "ids": ids,
  2444. })
  2445. return
  2446. }
  2447. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  2448. origin, _ := c.GetInt64("origin", 0)
  2449. record_date, _ := c.GetInt64("record_date")
  2450. patient_id, _ := c.GetInt64("patient_id")
  2451. check_time := c.GetString("check_time")
  2452. if len(check_time) <= 0 {
  2453. utils.ErrorLog("check_time")
  2454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2455. return
  2456. }
  2457. timeLayout2 := "2006-01-02 15:04:05"
  2458. loc, _ := time.LoadLocation("Local")
  2459. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  2460. fmt.Println("theTimewowowow", theTime)
  2461. if errs != nil {
  2462. utils.ErrorLog(errs.Error())
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2464. return
  2465. }
  2466. if origin != 2 {
  2467. groupno, _ := c.GetInt64("groupno", -1)
  2468. var ids []string
  2469. if groupno == 0 {
  2470. advice_ids := c.GetString("advice_id")
  2471. if advice_ids == "" {
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2473. return
  2474. } else {
  2475. ids = strings.Split(advice_ids, ",")
  2476. if len(ids) <= 0 {
  2477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2478. return
  2479. }
  2480. }
  2481. }
  2482. if groupno < 0 {
  2483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2484. return
  2485. }
  2486. adminUserInfo := c.GetMobileAdminUserInfo()
  2487. var advice models.DoctorAdvice
  2488. if groupno > 0 {
  2489. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2490. for _, item := range advices {
  2491. if item.CheckState == 0 {
  2492. advice = item
  2493. }
  2494. //记录日志
  2495. byterequest, _ := json.Marshal(advices)
  2496. adviceLog := models.XtDoctorAdviceLog{
  2497. UserOrgId: adminUserInfo.Org.Id,
  2498. PatientId: item.PatientId,
  2499. AdminUserId: adminUserInfo.AdminUser.Id,
  2500. Module: 3,
  2501. ErrLog: string(byterequest),
  2502. Status: 1,
  2503. Ctime: time.Now().Unix(),
  2504. Mtime: 0,
  2505. Source: "手机端核对医嘱",
  2506. RecordDate: item.AdviceDate,
  2507. }
  2508. service.CreateDoctorAdviceLog(adviceLog)
  2509. }
  2510. if advice.CheckState == 1 {
  2511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2512. return
  2513. }
  2514. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2516. return
  2517. }
  2518. } else {
  2519. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2520. for _, item := range advices {
  2521. if item.CheckState == 0 {
  2522. advice = item
  2523. }
  2524. //记录日志
  2525. byterequest, _ := json.Marshal(advices)
  2526. adviceLog := models.XtDoctorAdviceLog{
  2527. UserOrgId: adminUserInfo.Org.Id,
  2528. PatientId: item.PatientId,
  2529. AdminUserId: adminUserInfo.AdminUser.Id,
  2530. Module: 3,
  2531. ErrLog: string(byterequest),
  2532. Status: 1,
  2533. Ctime: time.Now().Unix(),
  2534. Mtime: 0,
  2535. Source: "手机端核对医嘱",
  2536. RecordDate: item.AdviceDate,
  2537. }
  2538. service.CreateDoctorAdviceLog(adviceLog)
  2539. }
  2540. if advice.CheckState == 1 {
  2541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2542. return
  2543. }
  2544. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2546. return
  2547. }
  2548. }
  2549. checker := adminUserInfo.AdminUser.Id
  2550. advices := models.DoctorAdvice{
  2551. CheckTime: theTime.Unix(),
  2552. Checker: checker,
  2553. UpdatedTime: time.Now().Unix(),
  2554. }
  2555. fmt.Println("groupnowowowowoowowow", groupno)
  2556. var err error
  2557. if groupno > 0 {
  2558. // 查询信息规挡的设置天数
  2559. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2560. if infor.ID > 0 && infor.WeekDay > 0 {
  2561. var cha_time int64
  2562. timeNowStr := time.Now().Format("2006-01-02")
  2563. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2564. //今日的日期减去设置的日期
  2565. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2566. if cha_time >= record_date {
  2567. //查询审核是否允许
  2568. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2569. //申请状态不允许的情况 拒绝修改
  2570. if infor.ApplicationStatus != 1 {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2572. return
  2573. }
  2574. }
  2575. }
  2576. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2577. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2578. redis := service.RedisClient()
  2579. //清空key 值
  2580. redis.Set(key, "", time.Second)
  2581. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2582. redis.Set(keyTwo, "", time.Second)
  2583. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2584. redis.Set(keyThree, "", time.Second)
  2585. recordDate := theTime.Format("2006-01-02")
  2586. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2587. redis.Set(keyFour, "", time.Second)
  2588. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2589. redis.Set(keyFive, "", time.Second)
  2590. defer redis.Close()
  2591. } else {
  2592. if len(ids[0]) <= 0 {
  2593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2594. return
  2595. } else {
  2596. //t := time.Now().Format("2006-01-02")/**/
  2597. //timeLayout2 := "2006-01-02"
  2598. //loc, _ := time.LoadLocation("Local")
  2599. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2600. // 查询信息规挡的设置天数
  2601. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2602. if infor.ID > 0 {
  2603. var cha_time int64
  2604. timeNowStr := time.Now().Format("2006-01-02")
  2605. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2606. //今日的日期减去设置的日期
  2607. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2608. if cha_time >= advices.AdviceDate {
  2609. //查询审核是否允许
  2610. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2611. //申请状态不允许的情况 拒绝修改
  2612. if infor.ApplicationStatus != 1 {
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2614. return
  2615. }
  2616. }
  2617. }
  2618. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2619. //记录日志
  2620. byterequest, _ := json.Marshal(advices)
  2621. adviceLog := models.XtDoctorAdviceLog{
  2622. UserOrgId: adminUserInfo.Org.Id,
  2623. PatientId: advices.PatientId,
  2624. AdminUserId: advices.Checker,
  2625. Module: 3,
  2626. ErrLog: string(byterequest),
  2627. Status: 1,
  2628. Ctime: time.Now().Unix(),
  2629. Mtime: 0,
  2630. Source: "手机端核对医嘱",
  2631. RecordDate: advices.AdviceDate,
  2632. }
  2633. service.CreateDoctorAdviceLog(adviceLog)
  2634. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2635. redis := service.RedisClient()
  2636. //清空key 值
  2637. redis.Set(key, "", time.Second)
  2638. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2639. redis.Set(keyTwo, "", time.Second)
  2640. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2641. redis.Set(keyThree, "", time.Second)
  2642. recordDate := theTime.Format("2006-01-02")
  2643. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2644. redis.Set(keyFour, "", time.Second)
  2645. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2646. redis.Set(keyFive, "", time.Second)
  2647. defer redis.Close()
  2648. }
  2649. }
  2650. if err != nil {
  2651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2652. return
  2653. }
  2654. advice.Checker = checker
  2655. advice.CheckTime = theTime.Unix()
  2656. advice.CheckState = 1
  2657. c.ServeSuccessJSON(map[string]interface{}{
  2658. "msg": "ok",
  2659. "advice": advice,
  2660. })
  2661. }
  2662. return
  2663. }
  2664. func (c *PatientApiController) CheckDoctorAdvice() {
  2665. origin, _ := c.GetInt64("origin", 0)
  2666. record_date, _ := c.GetInt64("record_date")
  2667. patient_id, _ := c.GetInt64("patient_id")
  2668. if origin != 2 {
  2669. groupno, _ := c.GetInt64("groupno", -1)
  2670. var ids []string
  2671. if groupno == 0 {
  2672. advice_ids := c.GetString("advice_id")
  2673. if advice_ids == "" {
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2675. return
  2676. } else {
  2677. ids = strings.Split(advice_ids, ",")
  2678. if len(ids) <= 0 {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. }
  2683. }
  2684. if groupno < 0 {
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. adminUserInfo := c.GetMobileAdminUserInfo()
  2689. var advice models.DoctorAdvice
  2690. if groupno > 0 {
  2691. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2692. for _, item := range advices {
  2693. if item.CheckState == 0 {
  2694. advice = item
  2695. }
  2696. //记录日志
  2697. byterequest, _ := json.Marshal(advices)
  2698. adviceLog := models.XtDoctorAdviceLog{
  2699. UserOrgId: adminUserInfo.Org.Id,
  2700. PatientId: item.PatientId,
  2701. AdminUserId: adminUserInfo.AdminUser.Id,
  2702. Module: 3,
  2703. ErrLog: string(byterequest),
  2704. Status: 1,
  2705. Ctime: time.Now().Unix(),
  2706. Mtime: 0,
  2707. Source: "手机端核对医嘱",
  2708. RecordDate: item.AdviceDate,
  2709. }
  2710. service.CreateDoctorAdviceLog(adviceLog)
  2711. }
  2712. if advice.CheckState == 1 {
  2713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2714. return
  2715. }
  2716. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2718. return
  2719. }
  2720. } else {
  2721. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2722. for _, item := range advices {
  2723. if item.CheckState == 0 {
  2724. advice = item
  2725. }
  2726. //记录日志
  2727. byterequest, _ := json.Marshal(advices)
  2728. adviceLog := models.XtDoctorAdviceLog{
  2729. UserOrgId: adminUserInfo.Org.Id,
  2730. PatientId: item.PatientId,
  2731. AdminUserId: adminUserInfo.AdminUser.Id,
  2732. Module: 3,
  2733. ErrLog: string(byterequest),
  2734. Status: 1,
  2735. Ctime: time.Now().Unix(),
  2736. Mtime: 0,
  2737. Source: "手机端核对医嘱",
  2738. RecordDate: item.AdviceDate,
  2739. }
  2740. service.CreateDoctorAdviceLog(adviceLog)
  2741. }
  2742. if advice.CheckState == 1 {
  2743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2744. return
  2745. }
  2746. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2748. return
  2749. }
  2750. }
  2751. checker := adminUserInfo.AdminUser.Id
  2752. theTime := time.Now()
  2753. advices := models.DoctorAdvice{
  2754. CheckTime: theTime.Unix(),
  2755. Checker: checker,
  2756. UpdatedTime: time.Now().Unix(),
  2757. }
  2758. var err error
  2759. if groupno > 0 {
  2760. // 查询信息规挡的设置天数
  2761. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2762. if infor.ID > 0 && infor.WeekDay > 0 {
  2763. var cha_time int64
  2764. timeNowStr := time.Now().Format("2006-01-02")
  2765. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2766. //今日的日期减去设置的日期
  2767. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2768. if cha_time >= record_date {
  2769. //查询审核是否允许
  2770. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2771. //申请状态不允许的情况 拒绝修改
  2772. if infor.ApplicationStatus != 1 {
  2773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2774. return
  2775. }
  2776. }
  2777. }
  2778. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2779. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2780. redis := service.RedisClient()
  2781. //清空key 值
  2782. redis.Set(key, "", time.Second)
  2783. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2784. redis.Set(keyTwo, "", time.Second)
  2785. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2786. redis.Set(keyThree, "", time.Second)
  2787. recordDate := theTime.Format("2006-01-02")
  2788. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2789. redis.Set(keyFour, "", time.Second)
  2790. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2791. redis.Set(keyFive, "", time.Second)
  2792. defer redis.Close()
  2793. } else {
  2794. if len(ids[0]) <= 0 {
  2795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2796. return
  2797. } else {
  2798. //t := time.Now().Format("2006-01-02")/**/
  2799. //timeLayout2 := "2006-01-02"
  2800. //loc, _ := time.LoadLocation("Local")
  2801. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2802. // 查询信息规挡的设置天数
  2803. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2804. if infor.ID > 0 {
  2805. var cha_time int64
  2806. timeNowStr := time.Now().Format("2006-01-02")
  2807. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2808. //今日的日期减去设置的日期
  2809. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2810. if cha_time >= advices.AdviceDate {
  2811. //查询审核是否允许
  2812. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2813. //申请状态不允许的情况 拒绝修改
  2814. if infor.ApplicationStatus != 1 {
  2815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2816. return
  2817. }
  2818. }
  2819. }
  2820. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2821. //记录日志
  2822. byterequest, _ := json.Marshal(advices)
  2823. adviceLog := models.XtDoctorAdviceLog{
  2824. UserOrgId: adminUserInfo.Org.Id,
  2825. PatientId: advices.PatientId,
  2826. AdminUserId: advices.Checker,
  2827. Module: 3,
  2828. ErrLog: string(byterequest),
  2829. Status: 1,
  2830. Ctime: time.Now().Unix(),
  2831. Mtime: 0,
  2832. Source: "手机端核对医嘱",
  2833. RecordDate: advices.AdviceDate,
  2834. }
  2835. service.CreateDoctorAdviceLog(adviceLog)
  2836. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2837. redis := service.RedisClient()
  2838. //清空key 值
  2839. redis.Set(key, "", time.Second)
  2840. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2841. redis.Set(keyTwo, "", time.Second)
  2842. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2843. redis.Set(keyThree, "", time.Second)
  2844. recordDate := theTime.Format("2006-01-02")
  2845. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2846. redis.Set(keyFour, "", time.Second)
  2847. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2848. redis.Set(keyFive, "", time.Second)
  2849. defer redis.Close()
  2850. }
  2851. }
  2852. if err != nil {
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2854. return
  2855. }
  2856. advice.Checker = checker
  2857. advice.CheckTime = theTime.Unix()
  2858. advice.CheckState = 1
  2859. c.ServeSuccessJSON(map[string]interface{}{
  2860. "msg": "ok",
  2861. "advice": advice,
  2862. })
  2863. } else if origin == 2 {
  2864. adminInfo := c.GetMobileAdminUserInfo()
  2865. var ids []string
  2866. advice_ids := c.GetString("advice_id")
  2867. ids = strings.Split(advice_ids, ",")
  2868. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2869. var err error
  2870. for _, item := range advices {
  2871. if item.CheckState == 1 {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2873. return
  2874. }
  2875. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2877. return
  2878. }
  2879. item.Checker = adminInfo.AdminUser.Id
  2880. item.CheckTime = time.Now().Unix()
  2881. item.CheckState = 1
  2882. // 查询信息规挡的设置天数
  2883. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2884. if infor.ID > 0 {
  2885. var cha_time int64
  2886. timeNowStr := time.Now().Format("2006-01-02")
  2887. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2888. //今日的日期减去设置的日期
  2889. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2890. if cha_time >= record_date {
  2891. //查询审核是否允许
  2892. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2893. //申请状态不允许的情况 拒绝修改
  2894. if infor.ApplicationStatus != 1 {
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2896. return
  2897. }
  2898. }
  2899. }
  2900. err = service.SaveHisDoctorAdvice(item)
  2901. //记录日志
  2902. byterequest, _ := json.Marshal(advices)
  2903. adviceLog := models.XtDoctorAdviceLog{
  2904. UserOrgId: adminInfo.Org.Id,
  2905. PatientId: item.PatientId,
  2906. AdminUserId: item.Checker,
  2907. Module: 3,
  2908. ErrLog: string(byterequest),
  2909. Status: 1,
  2910. Ctime: time.Now().Unix(),
  2911. Mtime: 0,
  2912. Source: "手机端核对His医嘱",
  2913. RecordDate: item.AdviceDate,
  2914. }
  2915. service.CreateDoctorAdviceLog(adviceLog)
  2916. redis := service.RedisClient()
  2917. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2918. //清空key 值
  2919. redis.Set(key, "", time.Second)
  2920. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2921. redis.Set(keyTwo, "", time.Second)
  2922. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2923. redis.Set(keyThree, "", time.Second)
  2924. theTime := time.Now()
  2925. recordDate := theTime.Format("2006-01-02")
  2926. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2927. redis.Set(keyFour, "", time.Second)
  2928. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2929. redis.Set(keyFive, "", time.Second)
  2930. defer redis.Close()
  2931. }
  2932. if err == nil {
  2933. c.ServeSuccessJSON(map[string]interface{}{
  2934. "msg": "ok",
  2935. "advice": advices,
  2936. })
  2937. } else {
  2938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2939. return
  2940. }
  2941. }
  2942. return
  2943. }
  2944. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2945. id, _ := c.GetInt64("patient", 0)
  2946. assessmentDate := c.GetString("assessment_date", "")
  2947. if id <= 0 || len(assessmentDate) != 10 {
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2949. return
  2950. }
  2951. timeLayout := "2006-01-02"
  2952. loc, _ := time.LoadLocation("Local")
  2953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2954. if err != nil {
  2955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2956. return
  2957. }
  2958. theAssessmentDateTime := theTime.Unix()
  2959. adminUserInfo := c.GetMobileAdminUserInfo()
  2960. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2961. if patient.ID == 0 {
  2962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2963. return
  2964. }
  2965. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2966. if getPEErr != nil {
  2967. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2969. return
  2970. }
  2971. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2972. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2973. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2974. var evaluation models.PredialysisEvaluation
  2975. if theEvaluation != nil {
  2976. evaluation = *theEvaluation
  2977. }
  2978. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2979. if code > 0 {
  2980. c.ServeFailJSONWithSGJErrorCode(code)
  2981. return
  2982. }
  2983. if theEvaluation == nil {
  2984. evaluation.CreatedTime = time.Now().Unix()
  2985. evaluation.Status = 1
  2986. evaluation.AssessmentDate = theAssessmentDateTime
  2987. evaluation.PatientId = id
  2988. evaluation.UserOrgId = adminUserInfo.Org.Id
  2989. if appRole.UserType == 2 || appRole.UserType == 1 {
  2990. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2991. evaluation.AssessmentTime = time.Now().Unix()
  2992. } else {
  2993. evaluation.Creater = adminUserInfo.AdminUser.Id
  2994. }
  2995. } else {
  2996. evaluation.UpdatedTime = time.Now().Unix()
  2997. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2998. if appRole.UserType == 2 || appRole.UserType == 1 {
  2999. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3000. evaluation.AssessmentTime = time.Now().Unix()
  3001. } else {
  3002. evaluation.Modifier = adminUserInfo.AdminUser.Id
  3003. if evaluation.Creater == 0 {
  3004. evaluation.Creater = adminUserInfo.AdminUser.Id
  3005. }
  3006. }
  3007. }
  3008. //新增逻辑
  3009. var dewater_amount float64
  3010. dewater_amount = 0
  3011. if evaluation.DryWeight > 0 {
  3012. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3013. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  3014. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  3015. dewater_amount = dewater_amount * 1000
  3016. }
  3017. }
  3018. if dewater_amount <= 0 {
  3019. dewater_amount = 0
  3020. }
  3021. } else {
  3022. dewater_amount = 0
  3023. }
  3024. // 计算透析处方的相关超滤量
  3025. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  3026. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  3027. var lastDialysisPrescribe *models.DialysisPrescription
  3028. var dialysisSolution *models.DialysisSolution
  3029. var dialysisPrescribe *models.DialysisPrescription
  3030. var system_dialysisPrescribe *models.SystemPrescription
  3031. var mode_id int64
  3032. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3033. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3034. if schedual != nil {
  3035. // 获取透析模版
  3036. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3037. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  3038. mode_id = schedual.ModeId
  3039. } else {
  3040. // 获取透析模版
  3041. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  3042. if dialysisPrescribe == nil && dialysisSolution != nil {
  3043. mode_id = dialysisSolution.ModeId
  3044. }
  3045. if dialysisPrescribe == nil && dialysisSolution == nil {
  3046. mode_id = 0
  3047. }
  3048. }
  3049. // 插入透析处方
  3050. if dialysisPrescribe == nil && dialysisSolution != nil {
  3051. var newprescribe models.DialysisPrescription
  3052. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3053. newprescribe.PatientId = id
  3054. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3055. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3056. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3057. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3058. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3059. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3060. newprescribe.ModeId = dialysisSolution.ModeId
  3061. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3062. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3063. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3064. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3065. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3066. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3067. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3068. newprescribe.Glucose = dialysisSolution.Glucose
  3069. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3070. newprescribe.Kalium = dialysisSolution.Kalium
  3071. newprescribe.Sodium = dialysisSolution.Sodium
  3072. newprescribe.Calcium = dialysisSolution.Calcium
  3073. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3074. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3075. newprescribe.Conductivity = dialysisSolution.Conductivity
  3076. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3077. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3078. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3079. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3080. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3081. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3082. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3083. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3084. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3085. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3086. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3087. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3088. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3089. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3090. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3091. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3092. newprescribe.CreatedTime = time.Now().Unix()
  3093. newprescribe.UpdatedTime = time.Now().Unix()
  3094. newprescribe.RecordDate = theAssessmentDateTime
  3095. newprescribe.DewaterAmount = dewater_amount
  3096. newprescribe.TargetUltrafiltration = dewater_amount
  3097. newprescribe.PrescriptionWater = dewater_amount
  3098. newprescribe.Status = 1
  3099. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  3100. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  3101. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3102. newprescribe.Remark = lastDialysisPrescription.Remark
  3103. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3104. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3105. newprescribe.ID = dialysisPrescription.ID
  3106. if dialysisPrescription.ID == 0 {
  3107. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3108. newprescribe.Sodium = 138
  3109. newprescribe.Bicarbonate = 31.1
  3110. newprescribe.DialysateFlow = 500
  3111. newprescribe.PrescribingNumber = 1
  3112. }
  3113. if adminUserInfo.Org.Id == 10579 {
  3114. newprescribe.Modifier = 0
  3115. newprescribe.Creater = 0
  3116. newprescribe.PrescriptionDoctor = 0
  3117. }
  3118. err := service.AddSigleRecord(&newprescribe)
  3119. //记录日志
  3120. byterequest, _ := json.Marshal(newprescribe)
  3121. prescriptionLog := models.XtDialysisPrescriptionLog{
  3122. UserOrgId: adminUserInfo.Org.Id,
  3123. Ctime: time.Now().Unix(),
  3124. Mtime: 0,
  3125. ErrLog: string(byterequest),
  3126. AdminUserId: adminUserInfo.AdminUser.Id,
  3127. RecordDate: newprescribe.RecordDate,
  3128. PatientId: id,
  3129. Source: "手机端新增透前评估插入处方",
  3130. Status: 1,
  3131. }
  3132. service.CreatePrescriptionLog(prescriptionLog)
  3133. //获取key,清空redis
  3134. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3135. redis := service.RedisClient()
  3136. //清空key 值
  3137. redis.Set(key, "", time.Second)
  3138. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3139. //清空key 值
  3140. redis.Set(keyOne, "", time.Second)
  3141. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3142. //清空key 值
  3143. redis.Set(keyTwo, "", time.Second)
  3144. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3145. redis.Set(keySix, "", time.Second)
  3146. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3147. redis.Set(keySeven, "", time.Second)
  3148. if err != nil {
  3149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3150. }
  3151. } else {
  3152. if adminUserInfo.Org.Id == 10340 {
  3153. newprescribe.Sodium = 138
  3154. newprescribe.Bicarbonate = 31.1
  3155. newprescribe.DialysateFlow = 500
  3156. }
  3157. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3158. //
  3159. if appRole.UserType == 2 || appRole.UserType == 1 {
  3160. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3161. if adminUserInfo.Org.Id == 9882 {
  3162. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3163. }
  3164. }
  3165. err := service.UpDateDialysisPrescription(&newprescribe)
  3166. //记录日志
  3167. byterequest, _ := json.Marshal(newprescribe)
  3168. prescriptionLog := models.XtDialysisPrescriptionLog{
  3169. UserOrgId: adminUserInfo.Org.Id,
  3170. Ctime: time.Now().Unix(),
  3171. Mtime: 0,
  3172. ErrLog: string(byterequest),
  3173. AdminUserId: adminUserInfo.AdminUser.Id,
  3174. RecordDate: newprescribe.RecordDate,
  3175. PatientId: id,
  3176. Source: "手机端新增透前评估插入处方",
  3177. Status: 1,
  3178. }
  3179. service.CreatePrescriptionLog(prescriptionLog)
  3180. //获取key,清空redis
  3181. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3182. redis := service.RedisClient()
  3183. //清空key 值
  3184. redis.Set(key, "", time.Second)
  3185. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3186. //清空key 值
  3187. redis.Set(keyOne, "", time.Second)
  3188. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3189. //清空key 值
  3190. redis.Set(keyTwo, "", time.Second)
  3191. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3192. redis.Set(keySix, "", time.Second)
  3193. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3194. redis.Set(keySeven, "", time.Second)
  3195. if err != nil {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3197. }
  3198. }
  3199. }
  3200. if dialysisPrescribe == nil && dialysisSolution == nil {
  3201. if lastDialysisPrescribe != nil {
  3202. var newprescribe models.DialysisPrescription
  3203. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3204. newprescribe.PatientId = id
  3205. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3206. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3207. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3208. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3209. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3210. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3211. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3212. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3213. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3214. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3215. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3216. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3217. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3218. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3219. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3220. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3221. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3222. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3223. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3224. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3225. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3226. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3227. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3228. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3229. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3230. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3231. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3232. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3233. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3234. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3235. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3236. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3237. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3238. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3239. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3240. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3241. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3242. newprescribe.CreatedTime = time.Now().Unix()
  3243. newprescribe.UpdatedTime = time.Now().Unix()
  3244. newprescribe.RecordDate = theAssessmentDateTime
  3245. newprescribe.DewaterAmount = dewater_amount
  3246. newprescribe.TargetUltrafiltration = dewater_amount
  3247. newprescribe.PrescriptionWater = dewater_amount
  3248. newprescribe.Status = 1
  3249. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  3250. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  3251. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  3252. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3253. }
  3254. newprescribe.Remark = lastDialysisPrescription.Remark
  3255. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3256. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3257. newprescribe.ID = dialysisPrescription.ID
  3258. if dialysisPrescription.ID == 0 {
  3259. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3260. newprescribe.Sodium = 138
  3261. newprescribe.Bicarbonate = 31.1
  3262. newprescribe.DialysateFlow = 500
  3263. }
  3264. if adminUserInfo.Org.Id == 10579 {
  3265. newprescribe.Modifier = 0
  3266. newprescribe.Creater = 0
  3267. newprescribe.PrescriptionDoctor = 0
  3268. }
  3269. err := service.AddSigleRecord(&newprescribe)
  3270. //记录日志
  3271. byterequest, _ := json.Marshal(newprescribe)
  3272. prescriptionLog := models.XtDialysisPrescriptionLog{
  3273. UserOrgId: adminUserInfo.Org.Id,
  3274. Ctime: time.Now().Unix(),
  3275. Mtime: 0,
  3276. ErrLog: string(byterequest),
  3277. AdminUserId: adminUserInfo.AdminUser.Id,
  3278. RecordDate: newprescribe.RecordDate,
  3279. PatientId: id,
  3280. Source: "手机端新增透前评估插入处方",
  3281. Status: 1,
  3282. }
  3283. service.CreatePrescriptionLog(prescriptionLog)
  3284. //获取key,清空redis
  3285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3286. redis := service.RedisClient()
  3287. //清空key 值
  3288. redis.Set(key, "", time.Second)
  3289. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3290. //清空key 值
  3291. redis.Set(keyOne, "", time.Second)
  3292. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3293. //清空key 值
  3294. redis.Set(keyTwo, "", time.Second)
  3295. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3296. redis.Set(keySix, "", time.Second)
  3297. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3298. redis.Set(keySeven, "", time.Second)
  3299. if err != nil {
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3301. }
  3302. } else {
  3303. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3304. //
  3305. if appRole.UserType == 2 || appRole.UserType == 1 {
  3306. if adminUserInfo.Org.Id == 10579 {
  3307. newprescribe.Modifier = 0
  3308. newprescribe.Creater = 0
  3309. newprescribe.PrescriptionDoctor = 0
  3310. } else {
  3311. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3312. }
  3313. if adminUserInfo.Org.Id == 9882 {
  3314. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3315. }
  3316. }
  3317. err := service.UpDateDialysisPrescription(&newprescribe)
  3318. //记录日志
  3319. byterequest, _ := json.Marshal(newprescribe)
  3320. prescriptionLog := models.XtDialysisPrescriptionLog{
  3321. UserOrgId: adminUserInfo.Org.Id,
  3322. Ctime: time.Now().Unix(),
  3323. Mtime: 0,
  3324. ErrLog: string(byterequest),
  3325. AdminUserId: adminUserInfo.AdminUser.Id,
  3326. RecordDate: newprescribe.RecordDate,
  3327. PatientId: id,
  3328. Source: "手机端新增透前评估插入处方",
  3329. Status: 1,
  3330. }
  3331. service.CreatePrescriptionLog(prescriptionLog)
  3332. //获取key,清空redis
  3333. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3334. redis := service.RedisClient()
  3335. //清空key 值
  3336. redis.Set(key, "", time.Second)
  3337. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3338. //清空key 值
  3339. redis.Set(keyOne, "", time.Second)
  3340. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3341. //清空key 值
  3342. redis.Set(keyTwo, "", time.Second)
  3343. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3344. redis.Set(keySix, "", time.Second)
  3345. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3346. redis.Set(keySeven, "", time.Second)
  3347. if err != nil {
  3348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3349. }
  3350. }
  3351. if err != nil {
  3352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3353. }
  3354. } else if system_dialysisPrescribe != nil {
  3355. var newprescribe models.DialysisPrescription
  3356. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3357. newprescribe.PatientId = id
  3358. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  3359. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  3360. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  3361. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  3362. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  3363. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  3364. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  3365. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  3366. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  3367. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  3368. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  3369. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  3370. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  3371. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  3372. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  3373. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  3374. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  3375. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  3376. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  3377. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  3378. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  3379. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  3380. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  3381. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  3382. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  3383. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  3384. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  3385. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  3386. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  3387. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  3388. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  3389. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  3390. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  3391. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  3392. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  3393. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  3394. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  3395. newprescribe.CreatedTime = time.Now().Unix()
  3396. newprescribe.UpdatedTime = time.Now().Unix()
  3397. newprescribe.RecordDate = theAssessmentDateTime
  3398. newprescribe.DewaterAmount = dewater_amount
  3399. newprescribe.TargetUltrafiltration = dewater_amount
  3400. newprescribe.PrescriptionWater = dewater_amount
  3401. newprescribe.Status = 1
  3402. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  3403. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  3404. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3405. newprescribe.Remark = lastDialysisPrescription.Remark
  3406. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3407. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3408. newprescribe.ID = dialysisPrescription.ID
  3409. if dialysisPrescription.ID == 0 {
  3410. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3411. newprescribe.Sodium = 138
  3412. newprescribe.Bicarbonate = 31.1
  3413. newprescribe.DialysateFlow = 500
  3414. }
  3415. if adminUserInfo.Org.Id == 10579 {
  3416. newprescribe.Modifier = 0
  3417. newprescribe.Creater = 0
  3418. newprescribe.PrescriptionDoctor = 0
  3419. }
  3420. err := service.AddSigleRecord(&newprescribe)
  3421. //记录日志
  3422. byterequest, _ := json.Marshal(newprescribe)
  3423. prescriptionLog := models.XtDialysisPrescriptionLog{
  3424. UserOrgId: adminUserInfo.Org.Id,
  3425. Ctime: time.Now().Unix(),
  3426. Mtime: 0,
  3427. ErrLog: string(byterequest),
  3428. AdminUserId: adminUserInfo.AdminUser.Id,
  3429. RecordDate: newprescribe.RecordDate,
  3430. PatientId: id,
  3431. Source: "手机端新增透前评估插入处方",
  3432. Status: 1,
  3433. }
  3434. service.CreatePrescriptionLog(prescriptionLog)
  3435. //获取key,清空redis
  3436. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3437. redis := service.RedisClient()
  3438. //清空key 值
  3439. redis.Set(key, "", time.Second)
  3440. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3441. //清空key 值
  3442. redis.Set(keyOne, "", time.Second)
  3443. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3444. //清空key 值
  3445. redis.Set(keyTwo, "", time.Second)
  3446. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3447. redis.Set(keySix, "", time.Second)
  3448. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3449. redis.Set(keySeven, "", time.Second)
  3450. if err != nil {
  3451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3452. }
  3453. } else {
  3454. if adminUserInfo.Org.Id == 10340 {
  3455. newprescribe.Sodium = 138
  3456. newprescribe.Bicarbonate = 31.1
  3457. newprescribe.DialysateFlow = 500
  3458. }
  3459. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3460. //
  3461. if appRole.UserType == 2 || appRole.UserType == 1 {
  3462. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3463. if adminUserInfo.Org.Id == 9882 {
  3464. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3465. }
  3466. }
  3467. err := service.UpDateDialysisPrescription(&newprescribe)
  3468. //记录日志
  3469. byterequest, _ := json.Marshal(newprescribe)
  3470. prescriptionLog := models.XtDialysisPrescriptionLog{
  3471. UserOrgId: adminUserInfo.Org.Id,
  3472. Ctime: time.Now().Unix(),
  3473. Mtime: 0,
  3474. ErrLog: string(byterequest),
  3475. AdminUserId: adminUserInfo.AdminUser.Id,
  3476. RecordDate: newprescribe.RecordDate,
  3477. PatientId: id,
  3478. Source: "手机端新增透前评估插入处方",
  3479. Status: 1,
  3480. }
  3481. service.CreatePrescriptionLog(prescriptionLog)
  3482. //获取key,清空redis
  3483. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3484. redis := service.RedisClient()
  3485. //清空key 值
  3486. redis.Set(key, "", time.Second)
  3487. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3488. //清空key 值
  3489. redis.Set(keyOne, "", time.Second)
  3490. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3491. //清空key 值
  3492. redis.Set(keyTwo, "", time.Second)
  3493. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3494. redis.Set(keySix, "", time.Second)
  3495. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3496. redis.Set(keySeven, "", time.Second)
  3497. if err != nil {
  3498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3499. }
  3500. }
  3501. if err != nil {
  3502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3503. }
  3504. } else {
  3505. var newprescribe models.DialysisPrescription
  3506. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3507. newprescribe.PatientId = id
  3508. newprescribe.ModeId = mode_id
  3509. newprescribe.CreatedTime = time.Now().Unix()
  3510. newprescribe.UpdatedTime = time.Now().Unix()
  3511. newprescribe.RecordDate = theAssessmentDateTime
  3512. newprescribe.DewaterAmount = dewater_amount
  3513. newprescribe.TargetUltrafiltration = dewater_amount
  3514. newprescribe.Status = 1
  3515. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3516. if dialysisPrescription.ID > 0 {
  3517. newprescribe.ID = dialysisPrescription.ID
  3518. }
  3519. if dialysisPrescription.ID == 0 {
  3520. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3521. newprescribe.Sodium = 138
  3522. newprescribe.Bicarbonate = 31.1
  3523. newprescribe.DialysateFlow = 500
  3524. }
  3525. if adminUserInfo.Org.Id == 10579 {
  3526. newprescribe.Modifier = 0
  3527. newprescribe.Creater = 0
  3528. newprescribe.PrescriptionDoctor = 0
  3529. }
  3530. err := service.AddSigleRecord(&newprescribe)
  3531. //获取key,清空redis
  3532. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3533. redis := service.RedisClient()
  3534. //清空key 值
  3535. redis.Set(key, "", time.Second)
  3536. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3537. //清空key 值
  3538. redis.Set(keyOne, "", time.Second)
  3539. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3540. //清空key 值
  3541. redis.Set(keyTwo, "", time.Second)
  3542. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3543. redis.Set(keySix, "", time.Second)
  3544. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3545. redis.Set(keySeven, "", time.Second)
  3546. if err != nil {
  3547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3548. }
  3549. } else {
  3550. if adminUserInfo.Org.Id == 10340 {
  3551. newprescribe.Sodium = 138
  3552. newprescribe.Bicarbonate = 31.1
  3553. newprescribe.DialysateFlow = 500
  3554. }
  3555. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3556. //
  3557. if appRole.UserType == 2 || appRole.UserType == 1 {
  3558. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3559. if adminUserInfo.Org.Id == 9882 {
  3560. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3561. }
  3562. }
  3563. if adminUserInfo.Org.Id == 10579 {
  3564. newprescribe.Modifier = 0
  3565. newprescribe.Creater = 0
  3566. newprescribe.PrescriptionDoctor = 0
  3567. }
  3568. err := service.UpDateDialysisPrescription(&newprescribe)
  3569. //记录日志
  3570. byterequest, _ := json.Marshal(newprescribe)
  3571. prescriptionLog := models.XtDialysisPrescriptionLog{
  3572. UserOrgId: adminUserInfo.Org.Id,
  3573. Ctime: time.Now().Unix(),
  3574. Mtime: 0,
  3575. ErrLog: string(byterequest),
  3576. AdminUserId: adminUserInfo.AdminUser.Id,
  3577. RecordDate: newprescribe.RecordDate,
  3578. PatientId: id,
  3579. Source: "手机端新增透前评估插入处方",
  3580. Status: 1,
  3581. }
  3582. service.CreatePrescriptionLog(prescriptionLog)
  3583. //获取key,清空redis
  3584. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3585. redis := service.RedisClient()
  3586. //清空key 值
  3587. redis.Set(key, "", time.Second)
  3588. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3589. //清空key 值
  3590. redis.Set(keyOne, "", time.Second)
  3591. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3592. //清空key 值
  3593. redis.Set(keyTwo, "", time.Second)
  3594. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3595. redis.Set(keySix, "", time.Second)
  3596. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3597. redis.Set(keySeven, "", time.Second)
  3598. if err != nil {
  3599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3600. }
  3601. }
  3602. if err != nil {
  3603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3604. }
  3605. }
  3606. }
  3607. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3608. // if dialysisPrescribe != nil {
  3609. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3610. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3611. // dialysisPrescribe.DewaterAmount = dewater_amount
  3612. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3613. // dialysisPrescribe.Status = 1
  3614. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3615. // if updateErr != nil {
  3616. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3617. // }
  3618. // }
  3619. // 查询信息规挡的设置天数
  3620. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3621. if infor.ID > 0 && infor.WeekDay > 0 {
  3622. var cha_time int64
  3623. timeNowStr := time.Now().Format("2006-01-02")
  3624. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3625. //今日的日期减去设置的日期
  3626. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3627. if cha_time >= evaluation.AssessmentDate {
  3628. //查询审核是否允许
  3629. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3630. //申请状态不允许的情况 拒绝修改
  3631. if infor.ApplicationStatus != 1 {
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3633. return
  3634. }
  3635. }
  3636. }
  3637. //针对长沙南雅的问题
  3638. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3639. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3640. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3641. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3642. }
  3643. }
  3644. //针对孝昌康桥超滤率计算问题
  3645. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10635 {
  3646. if evaluation.ID == 0 {
  3647. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3648. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3649. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3650. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3651. }
  3652. }
  3653. if evaluation.ID > 0 {
  3654. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3655. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3656. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3657. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3658. }
  3659. }
  3660. }
  3661. err = service.UpadatePredialysisEvaluation(&evaluation)
  3662. //记录日志
  3663. byterequest, _ := json.Marshal(evaluation)
  3664. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3665. UserOrgId: evaluation.UserOrgId,
  3666. AdminUserId: adminUserInfo.AdminUser.Id,
  3667. ErrLog: string(byterequest),
  3668. PatientId: evaluation.PatientId,
  3669. RecordDate: evaluation.AssessmentDate,
  3670. Ctime: time.Now().Unix(),
  3671. Mtime: 0,
  3672. Status: 1,
  3673. Source: "手机端保存透前评估",
  3674. }
  3675. service.CreateBeforLog(beforeDislysisLog)
  3676. finish := models.XtDialysisFinish{
  3677. IsFinish: 1,
  3678. UserOrgId: adminUserInfo.Org.Id,
  3679. Status: 1,
  3680. Ctime: time.Now().Unix(),
  3681. Mtime: 0,
  3682. Module: 3,
  3683. RecordDate: evaluation.AssessmentDate,
  3684. Sourse: 1,
  3685. PatientId: id,
  3686. }
  3687. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3688. if dialysisFinish.ID == 0 {
  3689. service.CreateDialysisFinish(finish)
  3690. }
  3691. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3692. redis := service.RedisClient()
  3693. defer redis.Close()
  3694. //清空key 值
  3695. redis.Set(key, "", time.Second)
  3696. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3697. redis.Set(keyOne, "", time.Second)
  3698. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3699. redis.Set(keyTwo, "", time.Second)
  3700. if err != nil {
  3701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3702. return
  3703. }
  3704. c.ServeSuccessJSON(map[string]interface{}{
  3705. "msg": "ok",
  3706. "evaluation": evaluation,
  3707. })
  3708. return
  3709. }
  3710. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3711. dataBody := make(map[string]interface{}, 0)
  3712. err := json.Unmarshal(data, &dataBody)
  3713. utils.InfoLog(string(data))
  3714. if err != nil {
  3715. utils.ErrorLog(err.Error())
  3716. code = enums.ErrorCodeParamWrong
  3717. return
  3718. }
  3719. // if method == "create" {
  3720. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3721. utils.ErrorLog("mode")
  3722. code = enums.ErrorCodeParamWrong
  3723. return
  3724. }
  3725. mode := int64(dataBody["mode"].(float64))
  3726. if mode <= 0 {
  3727. utils.ErrorLog("mode <= 0")
  3728. code = enums.ErrorCodeParamWrong
  3729. return
  3730. }
  3731. solution.ModeId = mode
  3732. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3733. utils.ErrorLog("mode_name")
  3734. code = enums.ErrorCodeParamWrong
  3735. return
  3736. }
  3737. modeName, _ := dataBody["mode_name"].(string)
  3738. if len(modeName) == 0 {
  3739. utils.ErrorLog("len(mode_name) == 0")
  3740. code = enums.ErrorCodeParamWrong
  3741. return
  3742. }
  3743. solution.ModeName = modeName
  3744. solution.Name = modeName
  3745. // }
  3746. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3747. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3748. solution.DialysisDuration = dialysisDuration
  3749. }
  3750. if dataBody["dialysis_duration"] != nil {
  3751. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3752. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3753. solution.DialysisDuration = dialysisDuration
  3754. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3755. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3756. solution.DialysisDuration = dialysisDuration
  3757. }
  3758. }
  3759. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3760. dialyzer := int64(dataBody["dialyzer"].(float64))
  3761. solution.Dialyzer = dialyzer
  3762. }
  3763. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3764. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3765. solution.PerfusionApparatus = perfusionApparatus
  3766. }
  3767. if dataBody["blood_flow_volume"] != nil {
  3768. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3769. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3770. solution.BloodFlowVolume = bloodFlowVolume
  3771. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3772. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3773. solution.BloodFlowVolume = bloodFlowVolume
  3774. }
  3775. }
  3776. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3777. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3778. solution.HemodialysisMachine = hemodialysisMachine
  3779. }
  3780. if dataBody["dewater"] != nil {
  3781. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3782. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3783. solution.Dewater = dewater
  3784. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3785. dewater := dataBody["dewater"].(float64)
  3786. solution.Dewater = dewater
  3787. }
  3788. }
  3789. if dataBody["replacement_total"] != nil {
  3790. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3791. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3792. solution.ReplacementTotal = replacementTotal
  3793. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3794. replacementTotal := dataBody["replacement_total"].(float64)
  3795. solution.ReplacementTotal = replacementTotal
  3796. }
  3797. }
  3798. if dataBody["displace_liqui"] != nil {
  3799. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3800. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3801. solution.DisplaceLiqui = displaceLiqui
  3802. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3803. displaceLiqui := dataBody["displace_liqui"].(float64)
  3804. solution.DisplaceLiqui = displaceLiqui
  3805. }
  3806. }
  3807. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3808. replacementWay := int64(dataBody["replacement_way"].(float64))
  3809. solution.ReplacementWay = replacementWay
  3810. }
  3811. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3812. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3813. solution.Anticoagulant = anticoagulant
  3814. }
  3815. if dataBody["anticoagulant_shouji"] != nil {
  3816. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3817. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3818. solution.AnticoagulantShouji = anticoagulantShouji
  3819. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3820. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3821. solution.AnticoagulantShouji = anticoagulantShouji
  3822. }
  3823. }
  3824. if dataBody["anticoagulant_weichi"] != nil {
  3825. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3826. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3827. solution.AnticoagulantWeichi = anticoagulantWeichi
  3828. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3829. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3830. solution.AnticoagulantWeichi = anticoagulantWeichi
  3831. }
  3832. }
  3833. if dataBody["anticoagulant_zongliang"] != nil {
  3834. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3835. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3836. solution.AnticoagulantZongliang = anticoagulantZongliang
  3837. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3838. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3839. solution.AnticoagulantZongliang = anticoagulantZongliang
  3840. }
  3841. }
  3842. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3843. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3844. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3845. }
  3846. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3847. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3848. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3849. }
  3850. if dataBody["kalium"] != nil {
  3851. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3852. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3853. solution.Kalium = kalium
  3854. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3855. kalium := dataBody["kalium"].(float64)
  3856. solution.Kalium = kalium
  3857. }
  3858. }
  3859. if dataBody["sodium"] != nil {
  3860. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3861. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3862. solution.Sodium = sodium
  3863. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3864. sodium := dataBody["sodium"].(float64)
  3865. solution.Sodium = sodium
  3866. }
  3867. }
  3868. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3869. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3870. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3871. solution.Calcium = calcium
  3872. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3873. calcium := dataBody["calcium"].(float64)
  3874. solution.Calcium = calcium
  3875. }
  3876. }
  3877. if dataBody["bicarbonate"] != nil {
  3878. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3879. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3880. solution.Bicarbonate = bicarbonate
  3881. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3882. bicarbonate := dataBody["bicarbonate"].(float64)
  3883. solution.Bicarbonate = bicarbonate
  3884. }
  3885. }
  3886. if dataBody["glucose"] != nil {
  3887. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3888. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3889. solution.Glucose = glucose
  3890. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3891. glucose := dataBody["glucose"].(float64)
  3892. solution.Glucose = glucose
  3893. }
  3894. }
  3895. // if dataBody["dry_weight"] != nil {
  3896. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3897. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3898. // solution.DryWeight = dryWeight
  3899. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3900. // dryWeight := dataBody["dry_weight"].(float64)
  3901. // solution.DryWeight = dryWeight
  3902. // }
  3903. // }
  3904. if dataBody["dialysate_flow"] != nil {
  3905. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3906. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3907. solution.DialysateFlow = dialysateFlow
  3908. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3909. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3910. solution.DialysateFlow = dialysateFlow
  3911. }
  3912. }
  3913. if dataBody["dialysate_temperature"] != nil {
  3914. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3915. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3916. solution.DialysateTemperature = dialysateTemperature
  3917. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3918. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3919. solution.DialysateTemperature = dialysateTemperature
  3920. }
  3921. }
  3922. if dataBody["conductivity"] != nil {
  3923. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3924. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3925. solution.Conductivity = conductivity
  3926. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3927. conductivity := dataBody["conductivity"].(float64)
  3928. solution.Conductivity = conductivity
  3929. }
  3930. }
  3931. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3932. remark := dataBody["remark"].(string)
  3933. solution.Remark = remark
  3934. }
  3935. if dataBody["dialysis_duration_hour"] != nil {
  3936. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3937. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3938. solution.DialysisDurationHour = dialysisDurationHour
  3939. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3940. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3941. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3942. }
  3943. }
  3944. if dataBody["dialysis_duration_minute"] != nil {
  3945. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3946. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3947. solution.DialysisDurationMinute = dialysisDurationMinute
  3948. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3949. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3950. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3951. }
  3952. }
  3953. if dataBody["target_ultrafiltration"] != nil {
  3954. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3955. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3956. solution.TargetUltrafiltration = targetUltrafiltration
  3957. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3958. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3959. solution.TargetUltrafiltration = targetUltrafiltration
  3960. }
  3961. }
  3962. if dataBody["dialysate_formulation"] != nil {
  3963. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3964. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3965. solution.DialysateFormulation = dialysateFormulation
  3966. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3967. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3968. solution.DialysateFormulation = int64(dialysateFormulation)
  3969. }
  3970. }
  3971. return
  3972. }
  3973. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3974. dataBody := make(map[string]interface{}, 0)
  3975. err := json.Unmarshal(data, &dataBody)
  3976. utils.InfoLog(string(data))
  3977. if err != nil {
  3978. utils.ErrorLog(err.Error())
  3979. code = enums.ErrorCodeParamWrong
  3980. return
  3981. }
  3982. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3983. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3984. evaluation.WeightBefore = weightVefore
  3985. }
  3986. // fmt.Println(dataBody["dry_weight"])
  3987. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3988. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3989. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3990. fmt.Println(additionalWeight)
  3991. evaluation.DryWeight = additionalWeight
  3992. }
  3993. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3994. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3995. fmt.Println(additionalWeight)
  3996. evaluation.AdditionalWeight = additionalWeight
  3997. }
  3998. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3999. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  4000. evaluation.Temperature = Temperature
  4001. }
  4002. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  4003. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  4004. evaluation.SystolicBloodPressure = systolicBloodPressure
  4005. }
  4006. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  4007. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  4008. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  4009. }
  4010. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  4011. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  4012. evaluation.PulseFrequency = pulseFrequency
  4013. }
  4014. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  4015. breathingRate := dataBody["breathing_rate"].(string)
  4016. evaluation.BreathingRate = breathingRate
  4017. }
  4018. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  4019. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  4020. evaluation.LastPostDialysis = lastPostDialysis
  4021. }
  4022. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  4023. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  4024. evaluation.DialysisInterphase = dialysisInterphase
  4025. }
  4026. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  4027. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  4028. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  4029. }
  4030. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  4031. catheter, _ := dataBody["catheter"].(string)
  4032. evaluation.Catheter = catheter
  4033. }
  4034. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  4035. catheter_bend := int(dataBody["catheter_bend"].(float64))
  4036. evaluation.CatheterBend = catheter_bend
  4037. }
  4038. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  4039. Complication, _ := dataBody["complication"].(string)
  4040. evaluation.Complication = Complication
  4041. }
  4042. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4043. remark := dataBody["remark"].(string)
  4044. evaluation.Remark = remark
  4045. }
  4046. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  4047. machine_type := dataBody["machine_type"].(string)
  4048. evaluation.MachineType = machine_type
  4049. }
  4050. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4051. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4052. evaluation.BloodAccessPartId = blood_access_part_id
  4053. }
  4054. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  4055. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  4056. // evaluation.BloodAccessPartId = blood_access_part_id
  4057. //}
  4058. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  4059. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  4060. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  4061. }
  4062. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  4063. internal_fistula, _ := dataBody["internal_fistula"].(string)
  4064. evaluation.InternalFistula = internal_fistula
  4065. }
  4066. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  4067. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  4068. evaluation.InternalFistulaSkin = internal_fistula_skin
  4069. }
  4070. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  4071. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  4072. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  4073. evaluation.IsHemorrhage = is_hemorrhage
  4074. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  4075. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  4076. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  4077. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  4078. is_hemorrhage = 0
  4079. }
  4080. evaluation.IsHemorrhage = is_hemorrhage
  4081. if is_hemorrhage == 1 {
  4082. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  4083. hemorrhage, _ := dataBody["hemorrhage"].(string)
  4084. evaluation.Hemorrhage = hemorrhage
  4085. }
  4086. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  4087. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  4088. evaluation.HemorrhageOther = hemorrhage_other
  4089. }
  4090. }
  4091. } else {
  4092. evaluation.IsHemorrhage = 0
  4093. }
  4094. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  4095. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  4096. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  4097. }
  4098. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  4099. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  4100. evaluation.InternalFistulaOther = internal_fistula_other
  4101. }
  4102. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  4103. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  4104. evaluation.BloodAccessNoise = blood_access_noise
  4105. }
  4106. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  4107. //puncture_way := int64(dataBody["puncture_way"].(float64))
  4108. puncture_way := dataBody["puncture_way"].(string)
  4109. evaluation.PunctureWay = puncture_way
  4110. }
  4111. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  4112. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  4113. evaluation.VenousCatheterization = venous_catheterization
  4114. }
  4115. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  4116. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  4117. evaluation.VenousCatheterizationPart = venous_catheterization_part
  4118. }
  4119. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  4120. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  4121. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  4122. }
  4123. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  4124. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  4125. evaluation.DuctusArantii = ductus_arantii
  4126. }
  4127. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  4128. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  4129. evaluation.EmergencyTreatment = emergency_treatment
  4130. }
  4131. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  4132. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  4133. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  4134. }
  4135. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  4136. dialysis_count, _ := dataBody["dialysis_count"].(string)
  4137. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  4138. evaluation.DialysisCount = dialysis_count
  4139. }
  4140. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  4141. is_infect, _ := dataBody["is_infect"].(string)
  4142. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  4143. evaluation.IsInfect = infect
  4144. }
  4145. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  4146. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  4147. evaluation.Exposed = exposed
  4148. }
  4149. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  4150. skin, _ := dataBody["skin"].(string)
  4151. //skins, _ := strconv.ParseInt(skin, 10, 64)
  4152. evaluation.Skin = skin
  4153. }
  4154. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  4155. skin_other, _ := dataBody["skin_other"].(string)
  4156. evaluation.SkinOther = skin_other
  4157. }
  4158. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  4159. infect_other, _ := dataBody["infect_other"].(string)
  4160. evaluation.InfectOther = infect_other
  4161. }
  4162. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  4163. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  4164. evaluation.DuctusArantiiOther = ductus_arantii_other
  4165. }
  4166. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4167. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  4168. evaluation.PunctureNeedle = punctureNeedle
  4169. }
  4170. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  4171. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  4172. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  4173. }
  4174. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  4175. pinholing := dataBody["pinholing"].(string)
  4176. evaluation.Phinholing = pinholing
  4177. }
  4178. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4179. catheter_suture := dataBody["catheter_suture"].(string)
  4180. evaluation.CatheterSuture = catheter_suture
  4181. }
  4182. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4183. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4184. evaluation.CatheterSutureOther = catheter_suture_other
  4185. }
  4186. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4187. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4188. evaluation.UrineVolume = urine_volume
  4189. }
  4190. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4191. edema := dataBody["edema"].(string)
  4192. evaluation.Edema = edema
  4193. }
  4194. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4195. specialTreatment := dataBody["special_treatment"].(string)
  4196. evaluation.SpecialTreatment = specialTreatment
  4197. }
  4198. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4199. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4200. evaluation.CatheterMaintenance = catheter_maintenance
  4201. }
  4202. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4203. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4204. evaluation.ThromubusType = thromubusType
  4205. }
  4206. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4207. thrombus_av := dataBody["thrombus_av"].(string)
  4208. evaluation.ThrombusAv = thrombus_av
  4209. }
  4210. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4211. thromubus_a := dataBody["thromubus_a"].(string)
  4212. evaluation.ThromubusA = thromubus_a
  4213. }
  4214. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4215. thromubus_v := dataBody["thromubus_v"].(string)
  4216. evaluation.ThromubusV = thromubus_v
  4217. }
  4218. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4219. dehydration := dataBody["dehydration"].(string)
  4220. evaluation.Dehydration = dehydration
  4221. }
  4222. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4223. period := int64(dataBody["period"].(float64))
  4224. evaluation.Period = period
  4225. }
  4226. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4227. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4228. evaluation.EstimatedFoodIntake = estimated_food_intake
  4229. }
  4230. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4231. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4232. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4233. }
  4234. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4235. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4236. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4237. }
  4238. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4239. urea_befor := dataBody["urea_befor"].(string)
  4240. evaluation.UreaBefor = urea_befor
  4241. }
  4242. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4243. suction := dataBody["suction"].(string)
  4244. evaluation.Suction = suction
  4245. }
  4246. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4247. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4248. evaluation.WeightBeforRemake = weight_befor_remake
  4249. }
  4250. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4251. height := dataBody["height"].(string)
  4252. evaluation.Height = height
  4253. }
  4254. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4255. age := dataBody["age"].(string)
  4256. evaluation.Age = age
  4257. }
  4258. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4259. his_department := dataBody["his_department"].(string)
  4260. evaluation.HisDepartment = his_department
  4261. }
  4262. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4263. his_bed := dataBody["his_bed"].(string)
  4264. evaluation.HisBed = his_bed
  4265. }
  4266. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4267. point_puncture := dataBody["point_puncture"].(string)
  4268. evaluation.PointPuncture = point_puncture
  4269. }
  4270. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4271. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4272. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4273. }
  4274. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4275. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4276. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4277. }
  4278. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4279. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4280. evaluation.WhetherUnobstructed = whether_unobstructed
  4281. }
  4282. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4283. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4284. evaluation.LienNecessary = lien_necessary
  4285. }
  4286. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4287. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4288. timeLayout := "2006-01-02"
  4289. loc, _ := time.LoadLocation("Local")
  4290. var startTime int64
  4291. if len(pathway_formation_time) > 0 {
  4292. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4293. startTime = theTime.Unix()
  4294. }
  4295. evaluation.PathwayFormationTime = startTime
  4296. }
  4297. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4298. befor_symptoms := dataBody["befor_symptoms"].(string)
  4299. evaluation.BeforSymptoms = befor_symptoms
  4300. }
  4301. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4302. washing_time, _ := dataBody["washing_time"].(string)
  4303. evaluation.WashingTime = washing_time
  4304. }
  4305. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4306. warsh_count, _ := dataBody["warsh_count"].(string)
  4307. evaluation.WarshCount = warsh_count
  4308. }
  4309. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4310. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4311. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4312. }
  4313. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4314. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4315. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4316. }
  4317. return
  4318. }
  4319. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4320. dataBody := make(map[string]interface{}, 0)
  4321. err := json.Unmarshal(data, &dataBody)
  4322. if err != nil {
  4323. utils.ErrorLog(err.Error())
  4324. code = enums.ErrorCodeParamWrong
  4325. return
  4326. }
  4327. timeLayout := "2006-01-02"
  4328. loc, _ := time.LoadLocation("Local")
  4329. isChild := false
  4330. if action == "create" {
  4331. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4332. utils.ErrorLog("advice_type")
  4333. code = enums.ErrorCodeParamWrong
  4334. return
  4335. }
  4336. adviceType := int64(dataBody["advice_type"].(float64))
  4337. if adviceType != 1 && adviceType != 2 {
  4338. utils.ErrorLog("advice_type != 1&&2")
  4339. code = enums.ErrorCodeParamWrong
  4340. return
  4341. }
  4342. advice.AdviceType = adviceType
  4343. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4344. utils.ErrorLog("advice_date")
  4345. code = enums.ErrorCodeParamWrong
  4346. return
  4347. }
  4348. adviceDate, _ := dataBody["advice_date"].(string)
  4349. if len(adviceDate) == 0 {
  4350. utils.ErrorLog("len(adviceDate) == 0")
  4351. code = enums.ErrorCodeParamWrong
  4352. return
  4353. }
  4354. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4355. if err != nil {
  4356. utils.ErrorLog(err.Error())
  4357. code = enums.ErrorCodeParamWrong
  4358. return
  4359. }
  4360. advice.AdviceDate = theTime.Unix()
  4361. advice.RecordDate = theTime.Unix()
  4362. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4363. parentId := int64(dataBody["parent_id"].(float64))
  4364. advice.ParentId = parentId
  4365. if parentId > 0 {
  4366. isChild = true
  4367. }
  4368. }
  4369. } else {
  4370. isChild = advice.ParentId > 0
  4371. }
  4372. if !isChild {
  4373. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4374. utils.ErrorLog("start_time")
  4375. code = enums.ErrorCodeParamWrong
  4376. return
  4377. }
  4378. startTime, _ := dataBody["start_time"].(string)
  4379. if len(startTime) == 0 {
  4380. utils.ErrorLog("len(start_time) == 0")
  4381. code = enums.ErrorCodeParamWrong
  4382. return
  4383. }
  4384. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4385. if err != nil {
  4386. utils.ErrorLog(err.Error())
  4387. code = enums.ErrorCodeParamWrong
  4388. return
  4389. }
  4390. advice.StartTime = theTime.Unix()
  4391. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4392. deliveryWay, _ := dataBody["delivery_way"].(string)
  4393. advice.DeliveryWay = deliveryWay
  4394. }
  4395. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4396. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4397. advice.ExecutionFrequency = executionFrequency
  4398. }
  4399. }
  4400. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4401. deliveryWay, _ := dataBody["delivery_way"].(string)
  4402. advice.DeliveryWay = deliveryWay
  4403. }
  4404. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4405. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4406. advice.ExecutionFrequency = executionFrequency
  4407. }
  4408. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4409. utils.ErrorLog("advice_name")
  4410. code = enums.ErrorCodeParamWrong
  4411. return
  4412. }
  4413. adviceName, _ := dataBody["advice_name"].(string)
  4414. if len(adviceName) == 0 {
  4415. utils.ErrorLog("len(advice_name) == 0")
  4416. code = enums.ErrorCodeParamWrong
  4417. return
  4418. }
  4419. advice.AdviceName = adviceName
  4420. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4421. adviceDsc, _ := dataBody["advice_desc"].(string)
  4422. advice.AdviceDesc = adviceDsc
  4423. }
  4424. if dataBody["way"] == nil {
  4425. advice.Way = 0
  4426. } else {
  4427. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4428. way := int64(dataBody["way"].(float64))
  4429. advice.Way = way
  4430. }
  4431. }
  4432. if dataBody["drug_id"] == nil {
  4433. advice.DrugId = 0
  4434. } else {
  4435. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4436. drug_id := int64(dataBody["drug_id"].(float64))
  4437. advice.DrugId = drug_id
  4438. }
  4439. }
  4440. if dataBody["drug_name_id"] == nil {
  4441. advice.DrugNameId = 0
  4442. } else {
  4443. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4444. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4445. advice.DrugNameId = drug_name_id
  4446. }
  4447. }
  4448. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4449. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4450. advice.SingleDose = singleDose
  4451. }
  4452. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4453. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4454. advice.SingleDoseUnit = singleDoseUnit
  4455. }
  4456. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4457. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4458. advice.DrugSpec = drugSpec
  4459. }
  4460. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4461. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4462. advice.DrugSpecUnit = drugSpecUnit
  4463. }
  4464. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4465. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4466. advice.PrescribingNumber = prescribingNumber
  4467. }
  4468. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4469. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4470. advice.PrescribingNumberUnit = prescribingNumberUnit
  4471. }
  4472. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4473. remark, _ := dataBody["remark"].(string)
  4474. advice.Remark = remark
  4475. }
  4476. return
  4477. }
  4478. func (c *PatientApiController) GetPatientEducation() {
  4479. patientID, _ := c.GetInt64("patient_id", 0)
  4480. page, _ := c.GetInt64("page", 0)
  4481. limit, _ := c.GetInt64("limit", 0)
  4482. startTime := c.GetString("start_time", "")
  4483. endTime := c.GetString("end_time", "")
  4484. if page <= 0 {
  4485. page = 1
  4486. }
  4487. if limit <= 0 {
  4488. limit = 10
  4489. }
  4490. if patientID <= 0 {
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4492. return
  4493. }
  4494. timeLayout := "2006-01-02"
  4495. loc, _ := time.LoadLocation("Local")
  4496. var theStartTIme int64
  4497. if len(startTime) > 0 {
  4498. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4499. if err != nil {
  4500. theStartTIme = 0
  4501. }
  4502. theStartTIme = theTime.Unix()
  4503. }
  4504. var theEndtTIme int64
  4505. if len(endTime) > 0 {
  4506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4507. if err != nil {
  4508. theEndtTIme = 0
  4509. }
  4510. theEndtTIme = theTime.Unix()
  4511. }
  4512. adminUserInfo := c.GetMobileAdminUserInfo()
  4513. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4514. c.ServeSuccessJSON(map[string]interface{}{
  4515. "total": total,
  4516. "edus": edus,
  4517. })
  4518. return
  4519. }
  4520. func (c *PatientApiController) GetPatientSchedulesList() {
  4521. patientID, _ := c.GetInt64("patient_id", 0)
  4522. page, _ := c.GetInt64("page", 0)
  4523. limit, _ := c.GetInt64("limit", 0)
  4524. if patientID <= 0 {
  4525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4526. return
  4527. }
  4528. adminUserInfo := c.GetMobileAdminUserInfo()
  4529. todayTime := time.Now().Format("2006-01-02")
  4530. timeLayout := "2006-01-02 15:04:05"
  4531. loc, _ := time.LoadLocation("Local")
  4532. var theStartTime int64
  4533. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4534. theStartTime = theTime.Unix()
  4535. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4536. if len(schedules) > 0 {
  4537. for index, item := range schedules {
  4538. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4539. schedules[index].Week = int64(week)
  4540. }
  4541. }
  4542. c.ServeSuccessJSON(map[string]interface{}{
  4543. "schedules": schedules,
  4544. })
  4545. return
  4546. }
  4547. func (c *PatientApiController) GetRecords() {
  4548. patientID, _ := c.GetInt64("patient_id", 0)
  4549. page, _ := c.GetInt64("page", 0)
  4550. limit, _ := c.GetInt64("limit", 0)
  4551. startTime := c.GetString("start_time", "")
  4552. endTime := c.GetString("end_time", "")
  4553. mode_id, _ := c.GetInt64("mode_id", 0)
  4554. if page <= 0 {
  4555. page = 1
  4556. }
  4557. if limit <= 0 {
  4558. limit = 10
  4559. }
  4560. if patientID <= 0 {
  4561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4562. return
  4563. }
  4564. timeLayout := "2006-01-02"
  4565. loc, _ := time.LoadLocation("Local")
  4566. var theStartTIme int64
  4567. if len(startTime) > 0 {
  4568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4569. if err != nil {
  4570. theStartTIme = 0
  4571. }
  4572. theStartTIme = theTime.Unix()
  4573. }
  4574. var theEndtTIme int64
  4575. if len(endTime) > 0 {
  4576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4577. if err != nil {
  4578. theEndtTIme = 0
  4579. }
  4580. theEndtTIme = theTime.Unix()
  4581. }
  4582. adminUserInfo := c.GetMobileAdminUserInfo()
  4583. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4584. c.ServeSuccessJSON(map[string]interface{}{
  4585. "total": total,
  4586. "records": records,
  4587. })
  4588. return
  4589. }
  4590. func (c *PatientApiController) GetPatientMonitor() {
  4591. partition, _ := c.GetInt64("partition")
  4592. monitorDate := c.GetString("date")
  4593. patient_id, _ := c.GetInt64("patient_id")
  4594. timeLayout := "2006-01-02"
  4595. loc, _ := time.LoadLocation("Local")
  4596. var theStartTime int64
  4597. if len(monitorDate) > 0 {
  4598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4599. if err != nil {
  4600. theStartTime = 0
  4601. }
  4602. theStartTime = theTime.Unix()
  4603. }
  4604. adminInfo := c.GetMobileAdminUserInfo()
  4605. orgID := adminInfo.Org.Id
  4606. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4607. if err != nil {
  4608. c.ErrorLog("获取排班信息失败:%v", err)
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4610. } else {
  4611. if len(monitor) > 0 {
  4612. //获取所有床位
  4613. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4614. //获取所有分区
  4615. zoneList, _ := service.GetAllZoneByList(orgID)
  4616. //获取透析处方
  4617. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4618. //获取透前评估
  4619. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4620. //获取上机
  4621. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4622. //获取透后
  4623. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4624. //获取透后监测
  4625. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4626. //获取所有的患者
  4627. patients, _ := service.GetAllPatientListByListOne(orgID)
  4628. for _, it := range patients {
  4629. if orgID == 10445 {
  4630. if theStartTime <= 1703952000 {
  4631. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4632. it.TotalDialysis = listOne.Count
  4633. }
  4634. if theStartTime >= 1704038400 {
  4635. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4636. it.TotalDialysis = listOrder.Count
  4637. }
  4638. }
  4639. }
  4640. //获取所有透析模式
  4641. treatments, _ := service.GetAllTreatModeByList(orgID)
  4642. for key, item := range monitor {
  4643. // 获取床位信息
  4644. for _, it := range numberList {
  4645. if item.BedId == it.ID {
  4646. monitor[key].DeviceNumber = it
  4647. break
  4648. }
  4649. }
  4650. //获取分区信息
  4651. for _, it := range zoneList {
  4652. if item.PartitionId == it.ID {
  4653. monitor[key].DeviceZone = it
  4654. }
  4655. }
  4656. for _, prescription := range prescriptions {
  4657. if item.PatientId == prescription.PatientId {
  4658. monitor[key].Prescription = prescription
  4659. break
  4660. }
  4661. }
  4662. // 透前评估
  4663. for _, assessmentBefore := range assessmentBefores {
  4664. if item.PatientId == assessmentBefore.PatientId {
  4665. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4666. break
  4667. }
  4668. }
  4669. // 透析上下机
  4670. for _, dialysisOrder := range dialysisOrders {
  4671. if item.PatientId == dialysisOrder.PatientId {
  4672. monitor[key].DialysisOrder = dialysisOrder
  4673. break
  4674. }
  4675. }
  4676. // 治疗小节
  4677. for _, afterDislysis := range AssessmentAfterDislysis {
  4678. if item.PatientId == afterDislysis.PatientId {
  4679. monitor[key].AssessmentAfterDislysis = afterDislysis
  4680. break
  4681. }
  4682. }
  4683. for _, it := range monitorlist {
  4684. if item.PatientId == it.PatientId {
  4685. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4686. }
  4687. }
  4688. for _, patient := range patients {
  4689. if item.PatientId == patient.ID {
  4690. monitor[key].MonitorPatients = patient
  4691. break
  4692. }
  4693. }
  4694. for _, treatment := range treatments {
  4695. if item.ModeId == treatment.ID {
  4696. monitor[key].TreatmentMode = treatment
  4697. break
  4698. }
  4699. }
  4700. }
  4701. }
  4702. }
  4703. //获取患者的透析次数
  4704. //count, err := service.GetDialysisCount(orgID, partition)
  4705. patients, err := service.GetAllpatientFourty(orgID)
  4706. if err == nil {
  4707. c.ServeSuccessJSON(map[string]interface{}{
  4708. "monitor": monitor,
  4709. //"patientCount": count,
  4710. "patients": patients,
  4711. })
  4712. } else {
  4713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4714. }
  4715. }
  4716. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4717. // @param keyword:string 病人姓名或透析号
  4718. // @param page:int
  4719. func (this *PatientApiController) SearchMonitorPatient() {
  4720. keyword := this.GetString("keyword")
  4721. page, _ := this.GetInt("page")
  4722. if page <= 0 {
  4723. page = 1
  4724. }
  4725. if len(keyword) == 0 {
  4726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4727. return
  4728. }
  4729. adminUserInfo := this.GetMobileAdminUserInfo()
  4730. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4731. if getMonitorErr != nil {
  4732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4733. return
  4734. } else {
  4735. this.ServeSuccessJSON(map[string]interface{}{
  4736. "monitor": monitors,
  4737. })
  4738. }
  4739. }
  4740. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4741. id, _ := c.GetInt64("id", 0)
  4742. page, _ := c.GetInt64("page", 0)
  4743. limit, _ := c.GetInt64("limit", 0)
  4744. if id <= 0 {
  4745. c.ServeSuccessJSON(map[string]interface{}{
  4746. "solutions": nil,
  4747. })
  4748. return
  4749. }
  4750. if page <= 0 {
  4751. page = 1
  4752. }
  4753. if limit <= 0 {
  4754. limit = 10
  4755. }
  4756. adminInfo := c.GetMobileAdminUserInfo()
  4757. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4758. c.ServeSuccessJSON(map[string]interface{}{
  4759. "solutions": solutions,
  4760. "total": total,
  4761. })
  4762. return
  4763. }
  4764. // GetDoctorAdvices 医嘱列表
  4765. func (c *PatientApiController) GetDoctorAdvices() {
  4766. id, _ := c.GetInt64("id", 0)
  4767. adviceType, _ := c.GetInt64("advice_type", 0)
  4768. stopType, _ := c.GetInt64("stop_state", 0)
  4769. startTime := c.GetString("start_time", "")
  4770. endTime := c.GetString("end_time", "")
  4771. keywords := c.GetString("keywords", "")
  4772. need, _ := c.GetInt64("need_doctor", 0)
  4773. adminUserInfo := c.GetMobileAdminUserInfo()
  4774. timeLayout := "2006-01-02"
  4775. loc, _ := time.LoadLocation("Local")
  4776. var theStartTIme int64
  4777. if len(startTime) > 0 {
  4778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4779. if err != nil {
  4780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4781. return
  4782. }
  4783. theStartTIme = theTime.Unix()
  4784. }
  4785. var theEndtTIme int64
  4786. if len(endTime) > 0 {
  4787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4788. if err != nil {
  4789. utils.ErrorLog(err.Error())
  4790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4791. return
  4792. }
  4793. theEndtTIme = theTime.Unix()
  4794. }
  4795. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4796. if need == 1 {
  4797. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4798. c.ServeSuccessJSON(map[string]interface{}{
  4799. "advices": advices,
  4800. "total": total,
  4801. "users": users,
  4802. })
  4803. } else {
  4804. c.ServeSuccessJSON(map[string]interface{}{
  4805. "advices": advices,
  4806. "total": total,
  4807. "users": []string{},
  4808. })
  4809. }
  4810. return
  4811. }
  4812. func (c *PatientApiController) GetPrintDialysisOrder() {
  4813. xtno := c.GetString("xtno")
  4814. xtdate := c.GetString("xtdate")
  4815. timeLayout := "2006-01-02"
  4816. loc, _ := time.LoadLocation("Local")
  4817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4818. if err != nil {
  4819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4820. return
  4821. }
  4822. xttime := theTime.Unix()
  4823. //获取当前日期月份的第一天
  4824. firstmonth := service.GetFirstDateOfMonth(theTime)
  4825. firstMonthDate := firstmonth.Unix()
  4826. operatorIDs := make([]int64, 0)
  4827. adminUserInfo := c.GetMobileAdminUserInfo()
  4828. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4829. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4830. //透析单
  4831. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4832. if dialysisOrder != nil {
  4833. if dialysisOrder.FinishNurse > 0 {
  4834. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4835. }
  4836. if dialysisOrder.StartNurse > 0 {
  4837. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4838. }
  4839. }
  4840. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4841. //透前评估
  4842. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4843. //透后评估
  4844. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4845. if AssessmentAfterDislysis.Modifier > 0 {
  4846. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4847. }
  4848. //透析处方
  4849. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4850. if dialysisPrescription.PrescriptionDoctor > 0 {
  4851. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4852. }
  4853. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4854. patientInfo.TotalDialysis = dialysis_count
  4855. //临时医嘱
  4856. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4857. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4858. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4859. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4860. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4861. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4862. if adminUserInfo.Org.Id != 10489 {
  4863. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4864. for _, item := range projects {
  4865. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4866. var advice models.HisDoctorAdviceInfo
  4867. advice.ID = item.ID
  4868. advice.Checker = item.Checker
  4869. advice.CheckTime = item.CheckTime
  4870. advice.CheckState = item.CheckState
  4871. advice.ExecutionState = item.ExecutionState
  4872. advice.ExecutionStaff = item.ExecutionStaff
  4873. //advice.PrescribingNumber = float64(item.Count)
  4874. advice.PrescribingNumber = cnt
  4875. advice.PrescribingNumberUnit = item.Unit
  4876. advice.AdviceDoctor = item.Doctor
  4877. if item.Type == 3 {
  4878. advice.AdviceName = item.GoodInfo.GoodName
  4879. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4880. } else if item.Type == 2 {
  4881. advice.AdviceName = item.HisProject.ProjectName
  4882. }
  4883. advice.StartTime = item.StartTime
  4884. hisAdvice = append(hisAdvice, &advice)
  4885. }
  4886. }
  4887. }
  4888. if len(DoctorAdvice) > 0 {
  4889. for _, item := range DoctorAdvice {
  4890. if item.AdviceDoctor > 0 {
  4891. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4892. }
  4893. if item.ExecutionStaff > 0 {
  4894. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4895. }
  4896. if item.Checker > 0 {
  4897. operatorIDs = append(operatorIDs, item.Checker)
  4898. }
  4899. }
  4900. }
  4901. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4902. //透析监测
  4903. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4904. //透析小结
  4905. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4906. //接诊评估
  4907. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4908. //相关操作对应的操作人
  4909. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4910. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4911. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4912. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4913. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4914. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4915. if config.IsOpen == 1 {
  4916. c.ServeSuccessJSON(map[string]interface{}{
  4917. "users": adminUser,
  4918. "patientInfo": patientInfo,
  4919. "PredialysisEvaluation": PredialysisEvaluation,
  4920. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4921. "dialysisPrescription": dialysisPrescription,
  4922. "advices": hisAdvice,
  4923. "monitors": Record,
  4924. "summary": TreatmentSummary,
  4925. "receiverTreatmentAccess": receiverTreatmentAccess,
  4926. "dialysisOrder": dialysisOrder,
  4927. "operators": operators,
  4928. "org_template_info": templateInfo,
  4929. "check": check,
  4930. "dialysiscount": dialysiscount,
  4931. "last_order": last_order,
  4932. "projects": projects,
  4933. "project_config": project_config,
  4934. "lastWeight": lastWeight,
  4935. "lastSchedule": lastSchedule,
  4936. "DoctorAdvice": DoctorAdvice,
  4937. "hisAdvice": hisAdvice,
  4938. })
  4939. }
  4940. if config.IsOpen == 0 || config.IsOpen == 2 {
  4941. c.ServeSuccessJSON(map[string]interface{}{
  4942. "users": adminUser,
  4943. "patientInfo": patientInfo,
  4944. "PredialysisEvaluation": PredialysisEvaluation,
  4945. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4946. "dialysisPrescription": dialysisPrescription,
  4947. "advices": DoctorAdvice,
  4948. "monitors": Record,
  4949. "summary": TreatmentSummary,
  4950. "receiverTreatmentAccess": receiverTreatmentAccess,
  4951. "dialysisOrder": dialysisOrder,
  4952. "operators": operators,
  4953. "org_template_info": templateInfo,
  4954. "check": check,
  4955. "dialysiscount": dialysiscount,
  4956. "last_order": last_order,
  4957. "projects": projects,
  4958. "project_config": project_config,
  4959. "lastWeight": lastWeight,
  4960. "lastSchedule": lastSchedule,
  4961. "DoctorAdvice": DoctorAdvice,
  4962. "hisAdvice": hisAdvice,
  4963. })
  4964. }
  4965. }
  4966. func (c *PatientApiController) CreateGroupAdvice() {
  4967. is_child, _ := c.GetInt64("is_child", 0)
  4968. if is_child == 1 {
  4969. patient, _ := c.GetInt64("id", 0)
  4970. if patient <= 0 {
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. adminUserInfo := c.GetMobileAdminUserInfo()
  4975. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4976. if patientInfo.ID == 0 {
  4977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4978. return
  4979. }
  4980. group_no, _ := c.GetInt64("group_no")
  4981. if group_no <= 0 {
  4982. group_no = 0
  4983. }
  4984. dataBody := make(map[string]interface{}, 0)
  4985. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4986. if err != nil {
  4987. utils.ErrorLog(err.Error())
  4988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4989. return
  4990. }
  4991. timeLayout := "2006-01-02"
  4992. loc, _ := time.LoadLocation("Local")
  4993. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4994. utils.ErrorLog("advice_type")
  4995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4996. return
  4997. }
  4998. adviceType := int64(dataBody["advice_type"].(float64))
  4999. if adviceType != 1 && adviceType != 2 {
  5000. utils.ErrorLog("advice_type != 1&&2")
  5001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5002. return
  5003. }
  5004. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5005. utils.ErrorLog("start_time")
  5006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5007. return
  5008. }
  5009. startTime2, _ := dataBody["start_time"].(string)
  5010. time_arr := strings.Split(startTime2, " ")
  5011. if len(time_arr) > 0 {
  5012. startTime2 = time_arr[0]
  5013. }
  5014. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5015. utils.ErrorLog("advice_date")
  5016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5017. return
  5018. }
  5019. advice_date, _ := dataBody["advice_date"].(string)
  5020. var advicedateunix int64
  5021. if len(advice_date) > 0 {
  5022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  5023. if err != nil {
  5024. fmt.Println(err)
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5026. return
  5027. }
  5028. advicedateunix = theTime.Unix()
  5029. }
  5030. adviceDate := startTime2
  5031. if len(adviceDate) == 0 {
  5032. utils.ErrorLog("len(adviceDate) == 0")
  5033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5034. return
  5035. }
  5036. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  5037. if err != nil {
  5038. utils.ErrorLog(err.Error())
  5039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5040. return
  5041. }
  5042. AdviceDate := advicedateunix
  5043. RecordDate := advicedateunix
  5044. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5045. utils.ErrorLog("start_time")
  5046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5047. return
  5048. }
  5049. startTime, _ := dataBody["start_time"].(string)
  5050. if len(startTime) == 0 {
  5051. utils.ErrorLog("len(start_time) == 0")
  5052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5053. return
  5054. }
  5055. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  5056. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  5057. if err != nil {
  5058. utils.ErrorLog(err.Error())
  5059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5060. return
  5061. }
  5062. StartTime := theTime.Unix()
  5063. Remark := ""
  5064. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5065. remark, _ := dataBody["remark"].(string)
  5066. Remark = remark
  5067. }
  5068. Startdate := int64(dataBody["record_date"].(float64))
  5069. var advices []*models.GroupAdvice
  5070. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  5071. utils.ErrorLog("adviceNames")
  5072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5073. return
  5074. }
  5075. adviceNames := dataBody["adviceNames"].([]interface{})
  5076. for _, adviceNameMap := range adviceNames {
  5077. adviceNameM := adviceNameMap.(map[string]interface{})
  5078. var advice models.GroupAdvice
  5079. advice.Remark = Remark
  5080. advice.AdviceType = adviceType
  5081. advice.StartTime = StartTime
  5082. if adminUserInfo.Org.Id == 10340 {
  5083. advice.AdviceDate = AdviceDate
  5084. advice.RecordDate = RecordDate
  5085. }
  5086. if adminUserInfo.Org.Id != 10340 {
  5087. advice.AdviceDate = theTimeOne.Unix()
  5088. advice.RecordDate = theTimeOne.Unix()
  5089. }
  5090. advice.Status = 1
  5091. advice.CreatedTime = time.Now().Unix()
  5092. advice.UpdatedTime = time.Now().Unix()
  5093. advice.StopState = 2
  5094. advice.ExecutionState = 2
  5095. advice.UserOrgId = adminUserInfo.Org.Id
  5096. advice.PatientId = patientInfo.ID
  5097. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5098. advice.IsSettle = 2
  5099. //入口
  5100. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  5101. if errcode > 0 {
  5102. c.ServeFailJSONWithSGJErrorCode(errcode)
  5103. return
  5104. }
  5105. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  5106. subdrugs := adviceNameM["subdrugs"].([]interface{})
  5107. if len(subdrugs) > 0 {
  5108. for _, subdrug := range subdrugs {
  5109. var s models.GroupAdvice
  5110. s.Remark = Remark
  5111. s.AdviceType = adviceType
  5112. s.StartTime = StartTime
  5113. s.AdviceDate = AdviceDate
  5114. s.RecordDate = RecordDate
  5115. s.Status = 1
  5116. s.CreatedTime = time.Now().Unix()
  5117. s.UpdatedTime = time.Now().Unix()
  5118. s.StopState = 2
  5119. s.ExecutionState = 2
  5120. s.UserOrgId = adminUserInfo.Org.Id
  5121. s.PatientId = patientInfo.ID
  5122. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  5123. s.IsSettle = 2
  5124. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  5125. if errcode > 0 {
  5126. c.ServeFailJSONWithSGJErrorCode(errcode)
  5127. return
  5128. }
  5129. advice.Children = append(advice.Children, &s)
  5130. }
  5131. }
  5132. }
  5133. //长沙南雅
  5134. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5135. //查询该患者今日有没有双人核对
  5136. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  5137. if check.ID > 0 {
  5138. advice.Checker = check.Modifier
  5139. advice.CheckState = 1
  5140. advice.CheckTime = time.Now().Unix()
  5141. }
  5142. }
  5143. advices = append(advices, &advice)
  5144. }
  5145. // 查询信息规挡的设置天数
  5146. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5147. if infor.ID > 0 && infor.WeekDay > 0 {
  5148. var cha_time int64
  5149. timeNowStr := time.Now().Format("2006-01-02")
  5150. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5151. //今日的日期减去设置的日期
  5152. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5153. if cha_time >= Startdate {
  5154. //查询审核是否允许
  5155. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  5156. //申请状态不允许的情况 拒绝修改
  5157. if infor.ApplicationStatus != 1 {
  5158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5159. return
  5160. }
  5161. }
  5162. }
  5163. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  5164. for _, item := range advices {
  5165. //记录日志
  5166. byterequest, _ := json.Marshal(item)
  5167. adviceLog := models.XtDoctorAdviceLog{
  5168. UserOrgId: item.UserOrgId,
  5169. PatientId: item.PatientId,
  5170. AdminUserId: adminUserInfo.AdminUser.Id,
  5171. Module: 1,
  5172. ErrLog: string(byterequest),
  5173. Status: 1,
  5174. Ctime: time.Now().Unix(),
  5175. Mtime: 0,
  5176. Source: "手机端新增医嘱",
  5177. RecordDate: item.AdviceDate,
  5178. }
  5179. service.CreateDoctorAdviceLog(adviceLog)
  5180. }
  5181. finish := models.XtDialysisFinish{
  5182. IsFinish: 1,
  5183. UserOrgId: adminUserInfo.Org.Id,
  5184. Status: 1,
  5185. Ctime: time.Now().Unix(),
  5186. Mtime: 0,
  5187. Module: 4,
  5188. RecordDate: advicedateunix,
  5189. Sourse: 1,
  5190. PatientId: patient,
  5191. }
  5192. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5193. if dialysisFinish.ID == 0 {
  5194. service.CreateDialysisFinish(finish)
  5195. }
  5196. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5197. redis := service.RedisClient()
  5198. //清空key 值
  5199. redis.Set(key, "", time.Second)
  5200. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5201. redis.Set(keyOne, "", time.Second)
  5202. defer redis.Close()
  5203. if createErr != nil {
  5204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5205. return
  5206. }
  5207. c.ServeSuccessJSON(map[string]interface{}{
  5208. "msg": "ok",
  5209. "advices": newAdvices,
  5210. })
  5211. return
  5212. } else if is_child == 2 {
  5213. patient, _ := c.GetInt64("id", 0)
  5214. if patient <= 0 {
  5215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5216. return
  5217. }
  5218. adminUserInfo := c.GetMobileAdminUserInfo()
  5219. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5220. if patientInfo.ID == 0 {
  5221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5222. return
  5223. }
  5224. var advice models.DoctorAdvice
  5225. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5226. if code > 0 {
  5227. c.ServeFailJSONWithSGJErrorCode(code)
  5228. return
  5229. }
  5230. if advice.ParentId > 0 {
  5231. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5232. if old.ID == 0 || old.PatientId != patient {
  5233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5234. return
  5235. }
  5236. if old.StopState == 1 || old.ExecutionState == 1 {
  5237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5238. return
  5239. }
  5240. if old.ParentId > 0 {
  5241. advice.ParentId = old.ParentId
  5242. }
  5243. advice.StartTime = old.StartTime
  5244. advice.AdviceDoctor = old.AdviceDoctor
  5245. advice.DeliveryWay = old.DeliveryWay
  5246. advice.ExecutionFrequency = old.ExecutionFrequency
  5247. advice.GroupNo = old.GroupNo
  5248. }
  5249. advice.Status = 1
  5250. advice.CreatedTime = time.Now().Unix()
  5251. advice.UpdatedTime = time.Now().Unix()
  5252. advice.StopState = 2
  5253. advice.ExecutionState = 2
  5254. advice.UserOrgId = adminUserInfo.Org.Id
  5255. advice.PatientId = patient
  5256. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5257. advice.IsSettle = 2
  5258. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5259. if advice.PrescribingNumber == 0 {
  5260. advice.PrescribingNumber = 1
  5261. }
  5262. //查询该患者今日有没有双人核对
  5263. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5264. if check.ID > 0 {
  5265. advice.Checker = check.Modifier
  5266. advice.CheckState = 1
  5267. advice.CheckTime = time.Now().Unix()
  5268. }
  5269. }
  5270. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5271. if infor.ID > 0 {
  5272. var cha_time int64
  5273. timeNowStr := time.Now().Format("2006-01-02")
  5274. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5275. //今日的日期减去设置的日期
  5276. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5277. if cha_time >= advice.RecordDate {
  5278. //查询审核是否允许
  5279. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5280. //申请状态不允许的情况 拒绝修改
  5281. if infor.ApplicationStatus != 1 {
  5282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5283. return
  5284. }
  5285. }
  5286. }
  5287. err := service.CreateDoctorAdvice(&advice)
  5288. //记录日志
  5289. byterequest, _ := json.Marshal(advice)
  5290. adviceLog := models.XtDoctorAdviceLog{
  5291. UserOrgId: advice.UserOrgId,
  5292. PatientId: advice.PatientId,
  5293. AdminUserId: adminUserInfo.Org.Id,
  5294. Module: 1,
  5295. ErrLog: string(byterequest),
  5296. Status: 1,
  5297. Ctime: time.Now().Unix(),
  5298. Mtime: 0,
  5299. Source: "手机端新增医嘱",
  5300. RecordDate: advice.AdviceDate,
  5301. }
  5302. service.CreateDoctorAdviceLog(adviceLog)
  5303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5304. redis := service.RedisClient()
  5305. //清空key 值
  5306. redis.Set(key, "", time.Second)
  5307. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5308. redis.Set(keyOne, "", time.Second)
  5309. defer redis.Close()
  5310. if err != nil {
  5311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5312. return
  5313. }
  5314. c.ServeSuccessJSON(map[string]interface{}{
  5315. "msg": "ok",
  5316. "advice": advice,
  5317. })
  5318. return
  5319. }
  5320. }
  5321. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5322. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5323. utils.ErrorLog("advice_name")
  5324. return enums.ErrorCodeParamWrong
  5325. }
  5326. adviceName, _ := json["advice_name"].(string)
  5327. if len(adviceName) == 0 {
  5328. utils.ErrorLog("len(advice_name) == 0")
  5329. return enums.ErrorCodeParamWrong
  5330. }
  5331. advice.AdviceName = adviceName
  5332. adviceDesc, _ := json["advice_desc"].(string)
  5333. advice.AdviceDesc = adviceDesc
  5334. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5335. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5336. advice.DrugSpec = drugSpec
  5337. }
  5338. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5339. remark, _ := json["remark"].(string)
  5340. advice.Remark = remark
  5341. }
  5342. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5343. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5344. // advice.Way = src_type
  5345. //}
  5346. if json["way"] == nil {
  5347. advice.Way = 0
  5348. } else {
  5349. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5350. way := int64(json["way"].(float64))
  5351. advice.Way = way
  5352. }
  5353. }
  5354. if json["drug_id"] == nil {
  5355. advice.DrugId = 0
  5356. } else {
  5357. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5358. drug_id := int64(json["drug_id"].(float64))
  5359. advice.DrugId = drug_id
  5360. }
  5361. }
  5362. if json["drug_name_id"] == nil {
  5363. advice.DrugNameId = 0
  5364. } else {
  5365. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5366. drug_name_id := int64(json["drug_name_id"].(float64))
  5367. advice.DrugNameId = drug_name_id
  5368. }
  5369. }
  5370. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5371. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5372. advice.DrugSpecUnit = drugSpecUnit
  5373. }
  5374. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5375. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5376. advice.SingleDose = singleDose
  5377. }
  5378. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5379. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5380. advice.SingleDoseUnit = singleDoseUnit
  5381. }
  5382. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5383. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5384. advice.PrescribingNumber = prescribingNumber
  5385. }
  5386. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5387. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5388. advice.PrescribingNumberUnit = prescribingNumberUnit
  5389. }
  5390. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5391. deliveryWay, _ := json["delivery_way"].(string)
  5392. advice.DeliveryWay = deliveryWay
  5393. }
  5394. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5395. executionFrequency, _ := json["execution_frequency"].(string)
  5396. advice.ExecutionFrequency = executionFrequency
  5397. }
  5398. return 0
  5399. }
  5400. func (c *PatientApiController) DelDoctorAdvice() {
  5401. groupno, _ := c.GetInt64("groupno", -1)
  5402. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5403. patient_id, _ := c.GetInt64("patient_id")
  5404. doc_advice_date, _ := c.GetInt64("advice_date")
  5405. redis := service.RedisClient()
  5406. if is_sub == 1 { //是
  5407. advice_id, _ := c.GetInt64("advice_id")
  5408. adminUserInfo := c.GetMobileAdminUserInfo()
  5409. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5410. if advice.ID == 0 {
  5411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5412. return
  5413. }
  5414. advice.Status = 0
  5415. advice.UpdatedTime = time.Now().Unix()
  5416. advice.Modifier = adminUserInfo.AdminUser.Id
  5417. // 查询信息规挡的设置天数
  5418. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5419. if infor.ID > 0 && infor.WeekDay > 0 {
  5420. var cha_time int64
  5421. timeNowStr := time.Now().Format("2006-01-02")
  5422. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5423. //今日的日期减去设置的日期
  5424. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5425. if cha_time >= advice.AdviceDate {
  5426. //查询审核是否允许
  5427. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5428. //申请状态不允许的情况 拒绝修改
  5429. if infor.ApplicationStatus != 1 {
  5430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5431. return
  5432. }
  5433. }
  5434. }
  5435. //自备药
  5436. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5437. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5438. //查询库存是否是自备药
  5439. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5440. if selfBasedrug.IsSelfDrug == 1 {
  5441. creater := adminUserInfo.AdminUser.Id
  5442. //退库
  5443. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5444. }
  5445. }
  5446. err := service.DeleteDoctorAdvice(&advice)
  5447. //记录日志
  5448. byterequest, _ := json.Marshal(advice)
  5449. adviceLog := models.XtDoctorAdviceLog{
  5450. UserOrgId: advice.UserOrgId,
  5451. PatientId: advice.PatientId,
  5452. AdminUserId: adminUserInfo.AdminUser.Id,
  5453. Module: 4,
  5454. ErrLog: string(byterequest),
  5455. Status: 1,
  5456. Ctime: time.Now().Unix(),
  5457. Mtime: 0,
  5458. Source: "手机端删除医嘱",
  5459. RecordDate: advice.RecordDate,
  5460. }
  5461. service.CreateDoctorAdviceLog(adviceLog)
  5462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5463. redis.Set(key, "", time.Second)
  5464. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5465. redis.Set(keyTwo, "", time.Second)
  5466. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5467. redis.Set(keyThree, "", time.Second)
  5468. redis.Close()
  5469. if err != nil {
  5470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5471. return
  5472. }
  5473. c.ServeSuccessJSON(map[string]interface{}{
  5474. "msg": "ok",
  5475. })
  5476. return
  5477. } else { //
  5478. var ids []string
  5479. if groupno == 0 {
  5480. advice_id := c.GetString("advice_id")
  5481. ids = strings.Split(advice_id, ",")
  5482. if len(ids) <= 0 {
  5483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5484. return
  5485. }
  5486. }
  5487. if groupno < 0 {
  5488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5489. return
  5490. }
  5491. adminUserInfo := c.GetMobileAdminUserInfo()
  5492. var advice models.DoctorAdvice
  5493. if groupno > 0 {
  5494. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5495. if advice.ID == 0 {
  5496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5497. return
  5498. }
  5499. } else {
  5500. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5501. for _, item := range advices {
  5502. if item.ID == 0 {
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5504. return
  5505. }
  5506. }
  5507. }
  5508. advice.UpdatedTime = time.Now().Unix()
  5509. advice.Status = 0
  5510. advice.GroupNo = groupno
  5511. advice.Modifier = adminUserInfo.AdminUser.Id
  5512. var err error
  5513. if groupno > 0 {
  5514. // 查询信息规挡的设置天数
  5515. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5516. if infor.ID > 0 {
  5517. var cha_time int64
  5518. timeNowStr := time.Now().Format("2006-01-02")
  5519. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5520. //今日的日期减去设置的日期
  5521. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5522. if cha_time >= advice.AdviceDate {
  5523. //查询审核是否允许
  5524. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5525. //申请状态不允许的情况 拒绝修改
  5526. if infor.ApplicationStatus != 1 {
  5527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5528. return
  5529. }
  5530. }
  5531. }
  5532. //自备药
  5533. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5534. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5535. //查询库存是否是自备药
  5536. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5537. if selfBasedrug.IsSelfDrug == 1 {
  5538. creater := adminUserInfo.AdminUser.Id
  5539. //退库
  5540. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5541. }
  5542. }
  5543. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5544. //记录日志
  5545. byterequest, _ := json.Marshal(advice)
  5546. adviceLog := models.XtDoctorAdviceLog{
  5547. UserOrgId: advice.UserOrgId,
  5548. PatientId: advice.PatientId,
  5549. AdminUserId: adminUserInfo.AdminUser.Id,
  5550. Module: 4,
  5551. ErrLog: string(byterequest),
  5552. Status: 1,
  5553. Ctime: time.Now().Unix(),
  5554. Mtime: 0,
  5555. Source: "手机端删除医嘱",
  5556. RecordDate: advice.RecordDate,
  5557. }
  5558. service.CreateDoctorAdviceLog(adviceLog)
  5559. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5560. redis.Set(key, "", time.Second)
  5561. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5562. redis.Set(keyTwo, "", time.Second)
  5563. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5564. redis.Set(keyThree, "", time.Second)
  5565. } else {
  5566. // 查询信息规挡的设置天数
  5567. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5568. if infor.ID > 0 {
  5569. var cha_time int64
  5570. timeNowStr := time.Now().Format("2006-01-02")
  5571. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5572. //今日的日期减去设置的日期
  5573. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5574. if cha_time >= advice.AdviceDate {
  5575. //查询审核是否允许
  5576. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5577. //申请状态不允许的情况 拒绝修改
  5578. if infor.ApplicationStatus != 1 {
  5579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5580. return
  5581. }
  5582. }
  5583. }
  5584. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5585. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5586. for _, item := range advicelist {
  5587. //自备药
  5588. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5589. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5590. //查询库存是否是自备药
  5591. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5592. if selfBasedrug.IsSelfDrug == 1 {
  5593. creater := adminUserInfo.AdminUser.Id
  5594. //退库
  5595. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5596. }
  5597. }
  5598. //记录日志
  5599. byterequest, _ := json.Marshal(item)
  5600. adviceLog := models.XtDoctorAdviceLog{
  5601. UserOrgId: item.UserOrgId,
  5602. PatientId: item.PatientId,
  5603. AdminUserId: adminUserInfo.AdminUser.Id,
  5604. Module: 4,
  5605. ErrLog: string(byterequest),
  5606. Status: 1,
  5607. Ctime: time.Now().Unix(),
  5608. Mtime: 0,
  5609. Source: "手机端批量删除医嘱",
  5610. RecordDate: item.RecordDate,
  5611. }
  5612. service.CreateDoctorAdviceLog(adviceLog)
  5613. }
  5614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5615. redis.Set(key, "", time.Second)
  5616. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5617. redis.Set(keyTwo, "", time.Second)
  5618. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5619. redis.Set(keyThree, "", time.Second)
  5620. redis.Close()
  5621. }
  5622. if err != nil {
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5624. return
  5625. }
  5626. c.ServeSuccessJSON(map[string]interface{}{
  5627. "msg": "ok",
  5628. })
  5629. return
  5630. }
  5631. }
  5632. // /m/api/advice/group/modify_starttime [post]
  5633. // @param group_no:int
  5634. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5635. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5636. group_no, _ := this.GetInt64("group_no")
  5637. start_time_str := this.GetString("start_time")
  5638. if group_no <= 0 || len(start_time_str) == 0 {
  5639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5640. return
  5641. }
  5642. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5643. if parseTimeErr != nil {
  5644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5645. return
  5646. }
  5647. adminUserInfo := this.GetMobileAdminUserInfo()
  5648. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5649. if updateStartTimeErr != nil {
  5650. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5652. return
  5653. }
  5654. this.ServeSuccessJSON(map[string]interface{}{
  5655. "start_time": startTime.Unix(),
  5656. })
  5657. }
  5658. func (this *PatientApiController) DelSubDoctorAdvice() {
  5659. advice_id, _ := this.GetInt64("advice_id")
  5660. adminUserInfo := this.GetMobileAdminUserInfo()
  5661. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5662. if advice.ID == 0 {
  5663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5664. return
  5665. }
  5666. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5667. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5668. // return
  5669. //}
  5670. advice.Status = 0
  5671. advice.UpdatedTime = time.Now().Unix()
  5672. advice.Modifier = adminUserInfo.AdminUser.Id
  5673. err := service.DeleteDoctorAdvice(&advice)
  5674. if err != nil {
  5675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5676. return
  5677. }
  5678. this.ServeSuccessJSON(map[string]interface{}{
  5679. "msg": "ok",
  5680. })
  5681. return
  5682. }
  5683. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5684. //adminUserInfo := this.GetMobileAdminUserInfo()
  5685. //service.FindUnReadDoctorAdviceMessage()
  5686. }
  5687. func (this *PatientApiController) GetPatientsByKeyWord() {
  5688. keyWord := this.GetString("keyword")
  5689. adminUserInfo := this.GetMobileAdminUserInfo()
  5690. today := utils.ZeroHourTimeOfDay(time.Now())
  5691. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5692. if err != nil {
  5693. utils.ErrorLog(err.Error())
  5694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5695. return
  5696. }
  5697. this.ServeSuccessJSON(map[string]interface{}{
  5698. "patient": patient,
  5699. })
  5700. }
  5701. func (this *PatientApiController) GetSearchPatient() {
  5702. keyWord := this.GetString("keyword")
  5703. adminUserInfo := this.GetMobileAdminUserInfo()
  5704. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5705. if err != nil {
  5706. utils.ErrorLog(err.Error())
  5707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5708. return
  5709. }
  5710. this.ServeSuccessJSON(map[string]interface{}{
  5711. "patient": patient,
  5712. })
  5713. }
  5714. func (c *PatientApiController) ExecProject() {
  5715. execution_time := c.GetString("execution_time")
  5716. project_id, _ := c.GetInt64("project_id")
  5717. team_id, _ := c.GetInt64("team_id")
  5718. is_check_team, _ := c.GetInt64("is_check_team")
  5719. if len(execution_time) <= 0 {
  5720. utils.ErrorLog("execution_time")
  5721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5722. return
  5723. }
  5724. timeLayout2 := "2006-01-02 15:04:05"
  5725. loc, _ := time.LoadLocation("Local")
  5726. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5727. if errs != nil {
  5728. utils.ErrorLog(errs.Error())
  5729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5730. return
  5731. }
  5732. adminInfo := c.GetMobileAdminUserInfo()
  5733. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5734. //针对舒和
  5735. if adminInfo.Org.Id == 10644 {
  5736. if project.StartTime > theTime.Unix() {
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  5738. return
  5739. }
  5740. }
  5741. if project.Type == 3 {
  5742. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5743. if good.IsUser != 1 {
  5744. //查询开关是否开启
  5745. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5746. //开关已经开启
  5747. if stockSetting.IsType == 1 {
  5748. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5749. scheduleDateStart := theTime.Format("2006-01-02")
  5750. timeLayout3 := "2006-01-02"
  5751. loc, _ := time.LoadLocation("Local")
  5752. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5753. //查询该耗材是否已经出库
  5754. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5755. if auto.ID == 0 {
  5756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5757. return
  5758. }
  5759. }
  5760. }
  5761. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5762. //查询开关是否开启
  5763. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5764. //开关已经开启
  5765. if stockSetting.IsType == 1 {
  5766. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5767. scheduleDateStart := theTime.Format("2006-01-02")
  5768. timeLayout3 := "2006-01-02"
  5769. loc, _ := time.LoadLocation("Local")
  5770. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5771. //查询该耗材是否已经出库
  5772. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5773. if auto.ID == 0 {
  5774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5775. return
  5776. }
  5777. }
  5778. }
  5779. }
  5780. if project.ExecutionState == 1 {
  5781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5782. return
  5783. }
  5784. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5786. return
  5787. }
  5788. project.ExecutionState = 1
  5789. project.ExecutionStaff = adminInfo.AdminUser.Id
  5790. project.ExecutionTime = theTime.Unix()
  5791. if team_id == 0 {
  5792. // 查询信息规挡的设置天数
  5793. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5794. if infor.ID > 0 {
  5795. var cha_time int64
  5796. timeNowStr := time.Now().Format("2006-01-02")
  5797. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5798. //今日的日期减去设置的日期
  5799. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5800. if cha_time >= project.RecordDate {
  5801. //查询审核是否允许
  5802. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5803. //申请状态不允许的情况 拒绝修改
  5804. if infor.ApplicationStatus != 1 {
  5805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5806. return
  5807. }
  5808. }
  5809. }
  5810. err := service.SaveHisProject(&project)
  5811. if err == nil {
  5812. c.ServeSuccessJSON(map[string]interface{}{
  5813. "project": project,
  5814. })
  5815. } else {
  5816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5817. return
  5818. }
  5819. } else {
  5820. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5821. // 查询信息规挡的设置天数
  5822. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5823. if infor.ID > 0 {
  5824. var cha_time int64
  5825. timeNowStr := time.Now().Format("2006-01-02")
  5826. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5827. //今日的日期减去设置的日期
  5828. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5829. if cha_time >= project.RecordDate {
  5830. //查询审核是否允许
  5831. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5832. //申请状态不允许的情况 拒绝修改
  5833. if infor.ApplicationStatus != 1 {
  5834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5835. return
  5836. }
  5837. }
  5838. }
  5839. err := service.SaveHisProject(&project)
  5840. if err == nil {
  5841. c.ServeSuccessJSON(map[string]interface{}{
  5842. "project": project,
  5843. })
  5844. } else {
  5845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5846. return
  5847. }
  5848. } else {
  5849. // 查询信息规挡的设置天数
  5850. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5851. if infor.ID > 0 {
  5852. var cha_time int64
  5853. timeNowStr := time.Now().Format("2006-01-02")
  5854. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5855. //今日的日期减去设置的日期
  5856. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5857. if cha_time >= project.RecordDate {
  5858. //查询审核是否允许
  5859. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5860. //申请状态不允许的情况 拒绝修改
  5861. if infor.ApplicationStatus != 1 {
  5862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5863. return
  5864. }
  5865. }
  5866. }
  5867. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5868. var ids []int64
  5869. for _, items := range ps {
  5870. ids = append(ids, items.ID)
  5871. }
  5872. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5873. if err == nil {
  5874. c.ServeSuccessJSON(map[string]interface{}{
  5875. "project": project,
  5876. })
  5877. } else {
  5878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5879. return
  5880. }
  5881. }
  5882. }
  5883. }
  5884. func (c *PatientApiController) CheckProject() {
  5885. adminInfo := c.GetMobileAdminUserInfo()
  5886. project_id, _ := c.GetInt64("project_id")
  5887. team_id, _ := c.GetInt64("team_id")
  5888. is_check_team, _ := c.GetInt64("is_check_team")
  5889. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5890. if project.CheckState == 1 {
  5891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5892. return
  5893. }
  5894. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5896. return
  5897. }
  5898. project.Checker = adminInfo.AdminUser.Id
  5899. project.CheckTime = time.Now().Unix()
  5900. project.CheckState = 1
  5901. if team_id == 0 {
  5902. // 查询信息规挡的设置天数
  5903. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5904. if infor.ID > 0 {
  5905. var cha_time int64
  5906. timeNowStr := time.Now().Format("2006-01-02")
  5907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5908. //今日的日期减去设置的日期
  5909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5910. if cha_time >= project.RecordDate {
  5911. //查询审核是否允许
  5912. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5913. //申请状态不允许的情况 拒绝修改
  5914. if infor.ApplicationStatus != 1 {
  5915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5916. return
  5917. }
  5918. }
  5919. }
  5920. err := service.SaveHisProject(&project)
  5921. if err == nil {
  5922. c.ServeSuccessJSON(map[string]interface{}{
  5923. "msg": "ok",
  5924. "project": project,
  5925. })
  5926. } else {
  5927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5928. return
  5929. }
  5930. } else {
  5931. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5932. // 查询信息规挡的设置天数
  5933. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5934. if infor.ID > 0 {
  5935. var cha_time int64
  5936. timeNowStr := time.Now().Format("2006-01-02")
  5937. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5938. //今日的日期减去设置的日期
  5939. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5940. if cha_time >= project.RecordDate {
  5941. //查询审核是否允许
  5942. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5943. //申请状态不允许的情况 拒绝修改
  5944. if infor.ApplicationStatus != 1 {
  5945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5946. return
  5947. }
  5948. }
  5949. }
  5950. err := service.SaveHisProject(&project)
  5951. if err == nil {
  5952. c.ServeSuccessJSON(map[string]interface{}{
  5953. "msg": "ok",
  5954. "project": project,
  5955. })
  5956. } else {
  5957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5958. return
  5959. }
  5960. } else {
  5961. // 查询信息规挡的设置天数
  5962. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5963. if infor.ID > 0 {
  5964. var cha_time int64
  5965. timeNowStr := time.Now().Format("2006-01-02")
  5966. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5967. //今日的日期减去设置的日期
  5968. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5969. if cha_time >= project.RecordDate {
  5970. //查询审核是否允许
  5971. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5972. //申请状态不允许的情况 拒绝修改
  5973. if infor.ApplicationStatus != 1 {
  5974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5975. return
  5976. }
  5977. }
  5978. }
  5979. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5980. var ids []int64
  5981. for _, items := range ps {
  5982. ids = append(ids, items.ID)
  5983. }
  5984. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5985. if err == nil {
  5986. c.ServeSuccessJSON(map[string]interface{}{
  5987. "project": project,
  5988. })
  5989. } else {
  5990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5991. return
  5992. }
  5993. }
  5994. }
  5995. }