patient_api_controller.go 251KB

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