patient_api_controller.go 271KB

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