patient_api_controller.go 248KB

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