patient_api_controller.go 271KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608
  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 && advice.UserOrgId != 10610 {
  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 && advice.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 && item.UserOrgId != 10610 {
  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 || adminUserInfo.Org.Id == 10768 {
  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 || adminUserInfo.Org.Id == 10768 {
  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 || adminUserInfo.Org.Id == 10768 {
  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 || adminUserInfo.Org.Id == 10768 {
  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. if adminUserInfo.Org.Id == 10768 {
  4069. dewater_amount = dewater_amount * 1000
  4070. }
  4071. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  4072. }
  4073. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  4074. redis := service.RedisClient()
  4075. //清空key 值
  4076. redis.Set(keyThree, "", time.Second)
  4077. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  4078. //清空key 值
  4079. redis.Set(keyFour, "", time.Second)
  4080. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":schedual_detail"
  4081. redis.Set(keyFive, "", time.Second)
  4082. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  4083. redis.Set(keySix, "", time.Second)
  4084. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  4085. redis.Set(keySeven, "", time.Second)
  4086. keyNight := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4087. redis.Set(keyNight, "", time.Second)
  4088. var recordDateStr = time.Now().Format("2006-01-02")
  4089. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4090. //清空key 值
  4091. redis.Set(keyOne, "", time.Second)
  4092. }
  4093. }
  4094. err = service.UpadatePredialysisEvaluation(&evaluation)
  4095. //记录日志
  4096. byterequest, _ := json.Marshal(evaluation)
  4097. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  4098. UserOrgId: evaluation.UserOrgId,
  4099. AdminUserId: adminUserInfo.AdminUser.Id,
  4100. ErrLog: string(byterequest),
  4101. PatientId: evaluation.PatientId,
  4102. RecordDate: evaluation.AssessmentDate,
  4103. Ctime: time.Now().Unix(),
  4104. Mtime: 0,
  4105. Status: 1,
  4106. Source: "手机端保存透前评估",
  4107. }
  4108. service.CreateBeforLog(beforeDislysisLog)
  4109. finish := models.XtDialysisFinish{
  4110. IsFinish: 1,
  4111. UserOrgId: adminUserInfo.Org.Id,
  4112. Status: 1,
  4113. Ctime: time.Now().Unix(),
  4114. Mtime: 0,
  4115. Module: 3,
  4116. RecordDate: evaluation.AssessmentDate,
  4117. Sourse: 1,
  4118. PatientId: id,
  4119. }
  4120. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  4121. if dialysisFinish.ID == 0 {
  4122. service.CreateDialysisFinish(finish)
  4123. }
  4124. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  4125. redis := service.RedisClient()
  4126. defer redis.Close()
  4127. //清空key 值
  4128. redis.Set(key, "", time.Second)
  4129. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  4130. redis.Set(keyOne, "", time.Second)
  4131. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4132. redis.Set(keyTwo, "", time.Second)
  4133. if err != nil {
  4134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  4135. return
  4136. }
  4137. c.ServeSuccessJSON(map[string]interface{}{
  4138. "msg": "ok",
  4139. "evaluation": evaluation,
  4140. })
  4141. return
  4142. }
  4143. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4144. dataBody := make(map[string]interface{}, 0)
  4145. err := json.Unmarshal(data, &dataBody)
  4146. utils.InfoLog(string(data))
  4147. if err != nil {
  4148. utils.ErrorLog(err.Error())
  4149. code = enums.ErrorCodeParamWrong
  4150. return
  4151. }
  4152. // if method == "create" {
  4153. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  4154. utils.ErrorLog("mode")
  4155. code = enums.ErrorCodeParamWrong
  4156. return
  4157. }
  4158. mode := int64(dataBody["mode"].(float64))
  4159. if mode <= 0 {
  4160. utils.ErrorLog("mode <= 0")
  4161. code = enums.ErrorCodeParamWrong
  4162. return
  4163. }
  4164. solution.ModeId = mode
  4165. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  4166. utils.ErrorLog("mode_name")
  4167. code = enums.ErrorCodeParamWrong
  4168. return
  4169. }
  4170. modeName, _ := dataBody["mode_name"].(string)
  4171. if len(modeName) == 0 {
  4172. utils.ErrorLog("len(mode_name) == 0")
  4173. code = enums.ErrorCodeParamWrong
  4174. return
  4175. }
  4176. solution.ModeName = modeName
  4177. solution.Name = modeName
  4178. // }
  4179. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4180. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4181. solution.DialysisDuration = dialysisDuration
  4182. }
  4183. if dataBody["dialysis_duration"] != nil {
  4184. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4185. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4186. solution.DialysisDuration = dialysisDuration
  4187. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  4188. dialysisDuration := dataBody["dialysis_duration"].(float64)
  4189. solution.DialysisDuration = dialysisDuration
  4190. }
  4191. }
  4192. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  4193. dialyzer := int64(dataBody["dialyzer"].(float64))
  4194. solution.Dialyzer = dialyzer
  4195. }
  4196. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4197. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4198. solution.PerfusionApparatus = perfusionApparatus
  4199. }
  4200. if dataBody["blood_flow_volume"] != nil {
  4201. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4202. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4203. solution.BloodFlowVolume = bloodFlowVolume
  4204. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  4205. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  4206. solution.BloodFlowVolume = bloodFlowVolume
  4207. }
  4208. }
  4209. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4210. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4211. solution.HemodialysisMachine = hemodialysisMachine
  4212. }
  4213. if dataBody["dewater"] != nil {
  4214. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  4215. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  4216. solution.Dewater = dewater
  4217. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  4218. dewater := dataBody["dewater"].(float64)
  4219. solution.Dewater = dewater
  4220. }
  4221. }
  4222. if dataBody["replacement_total"] != nil {
  4223. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  4224. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  4225. solution.ReplacementTotal = replacementTotal
  4226. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  4227. replacementTotal := dataBody["replacement_total"].(float64)
  4228. solution.ReplacementTotal = replacementTotal
  4229. }
  4230. }
  4231. if dataBody["displace_liqui"] != nil {
  4232. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  4233. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  4234. solution.DisplaceLiqui = displaceLiqui
  4235. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  4236. displaceLiqui := dataBody["displace_liqui"].(float64)
  4237. solution.DisplaceLiqui = displaceLiqui
  4238. }
  4239. }
  4240. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4241. replacementWay := int64(dataBody["replacement_way"].(float64))
  4242. solution.ReplacementWay = replacementWay
  4243. }
  4244. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4245. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4246. solution.Anticoagulant = anticoagulant
  4247. }
  4248. if dataBody["anticoagulant_shouji"] != nil {
  4249. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4250. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4251. solution.AnticoagulantShouji = anticoagulantShouji
  4252. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  4253. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  4254. solution.AnticoagulantShouji = anticoagulantShouji
  4255. }
  4256. }
  4257. if dataBody["anticoagulant_weichi"] != nil {
  4258. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4259. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4260. solution.AnticoagulantWeichi = anticoagulantWeichi
  4261. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  4262. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  4263. solution.AnticoagulantWeichi = anticoagulantWeichi
  4264. }
  4265. }
  4266. if dataBody["anticoagulant_zongliang"] != nil {
  4267. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4268. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4269. solution.AnticoagulantZongliang = anticoagulantZongliang
  4270. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  4271. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  4272. solution.AnticoagulantZongliang = anticoagulantZongliang
  4273. }
  4274. }
  4275. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4276. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4277. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4278. }
  4279. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4280. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4281. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4282. }
  4283. if dataBody["kalium"] != nil {
  4284. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4285. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4286. solution.Kalium = kalium
  4287. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  4288. kalium := dataBody["kalium"].(float64)
  4289. solution.Kalium = kalium
  4290. }
  4291. }
  4292. if dataBody["sodium"] != nil {
  4293. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4294. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4295. solution.Sodium = sodium
  4296. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  4297. sodium := dataBody["sodium"].(float64)
  4298. solution.Sodium = sodium
  4299. }
  4300. }
  4301. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4302. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4303. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4304. solution.Calcium = calcium
  4305. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  4306. calcium := dataBody["calcium"].(float64)
  4307. solution.Calcium = calcium
  4308. }
  4309. }
  4310. if dataBody["bicarbonate"] != nil {
  4311. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4312. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4313. solution.Bicarbonate = bicarbonate
  4314. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  4315. bicarbonate := dataBody["bicarbonate"].(float64)
  4316. solution.Bicarbonate = bicarbonate
  4317. }
  4318. }
  4319. if dataBody["glucose"] != nil {
  4320. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4321. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4322. solution.Glucose = glucose
  4323. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  4324. glucose := dataBody["glucose"].(float64)
  4325. solution.Glucose = glucose
  4326. }
  4327. }
  4328. // if dataBody["dry_weight"] != nil {
  4329. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4330. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4331. // solution.DryWeight = dryWeight
  4332. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  4333. // dryWeight := dataBody["dry_weight"].(float64)
  4334. // solution.DryWeight = dryWeight
  4335. // }
  4336. // }
  4337. if dataBody["dialysate_flow"] != nil {
  4338. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4339. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4340. solution.DialysateFlow = dialysateFlow
  4341. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  4342. dialysateFlow := dataBody["dialysate_flow"].(float64)
  4343. solution.DialysateFlow = dialysateFlow
  4344. }
  4345. }
  4346. if dataBody["dialysate_temperature"] != nil {
  4347. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4348. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4349. solution.DialysateTemperature = dialysateTemperature
  4350. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  4351. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  4352. solution.DialysateTemperature = dialysateTemperature
  4353. }
  4354. }
  4355. if dataBody["conductivity"] != nil {
  4356. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4357. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4358. solution.Conductivity = conductivity
  4359. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  4360. conductivity := dataBody["conductivity"].(float64)
  4361. solution.Conductivity = conductivity
  4362. }
  4363. }
  4364. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4365. remark := dataBody["remark"].(string)
  4366. solution.Remark = remark
  4367. }
  4368. if dataBody["dialysis_duration_hour"] != nil {
  4369. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4370. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  4371. solution.DialysisDurationHour = dialysisDurationHour
  4372. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  4373. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  4374. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4375. }
  4376. }
  4377. if dataBody["dialysis_duration_minute"] != nil {
  4378. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4379. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  4380. solution.DialysisDurationMinute = dialysisDurationMinute
  4381. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  4382. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  4383. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4384. }
  4385. }
  4386. if dataBody["target_ultrafiltration"] != nil {
  4387. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4388. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4389. solution.TargetUltrafiltration = targetUltrafiltration
  4390. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  4391. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  4392. solution.TargetUltrafiltration = targetUltrafiltration
  4393. }
  4394. }
  4395. if dataBody["dialysate_formulation"] != nil {
  4396. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  4397. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  4398. solution.DialysateFormulation = dialysateFormulation
  4399. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4400. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  4401. solution.DialysateFormulation = int64(dialysateFormulation)
  4402. }
  4403. }
  4404. return
  4405. }
  4406. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  4407. dataBody := make(map[string]interface{}, 0)
  4408. err := json.Unmarshal(data, &dataBody)
  4409. utils.InfoLog(string(data))
  4410. if err != nil {
  4411. utils.ErrorLog(err.Error())
  4412. code = enums.ErrorCodeParamWrong
  4413. return
  4414. }
  4415. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  4416. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  4417. evaluation.WeightBefore = weightVefore
  4418. }
  4419. // fmt.Println(dataBody["dry_weight"])
  4420. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  4421. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4422. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4423. fmt.Println(additionalWeight)
  4424. evaluation.DryWeight = additionalWeight
  4425. }
  4426. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  4427. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  4428. fmt.Println(additionalWeight)
  4429. evaluation.AdditionalWeight = additionalWeight
  4430. }
  4431. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  4432. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  4433. evaluation.Temperature = Temperature
  4434. }
  4435. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  4436. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  4437. evaluation.SystolicBloodPressure = systolicBloodPressure
  4438. }
  4439. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  4440. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  4441. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  4442. }
  4443. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  4444. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  4445. evaluation.PulseFrequency = pulseFrequency
  4446. }
  4447. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  4448. breathingRate := dataBody["breathing_rate"].(string)
  4449. evaluation.BreathingRate = breathingRate
  4450. }
  4451. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  4452. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  4453. evaluation.LastPostDialysis = lastPostDialysis
  4454. }
  4455. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  4456. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  4457. evaluation.DialysisInterphase = dialysisInterphase
  4458. }
  4459. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  4460. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  4461. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  4462. }
  4463. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  4464. catheter, _ := dataBody["catheter"].(string)
  4465. evaluation.Catheter = catheter
  4466. }
  4467. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  4468. catheter_bend := int(dataBody["catheter_bend"].(float64))
  4469. evaluation.CatheterBend = catheter_bend
  4470. }
  4471. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  4472. Complication, _ := dataBody["complication"].(string)
  4473. evaluation.Complication = Complication
  4474. }
  4475. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4476. remark := dataBody["remark"].(string)
  4477. evaluation.Remark = remark
  4478. }
  4479. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  4480. machine_type := dataBody["machine_type"].(string)
  4481. evaluation.MachineType = machine_type
  4482. }
  4483. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4484. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4485. evaluation.BloodAccessPartId = blood_access_part_id
  4486. }
  4487. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  4488. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  4489. // evaluation.BloodAccessPartId = blood_access_part_id
  4490. //}
  4491. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  4492. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  4493. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  4494. }
  4495. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  4496. internal_fistula, _ := dataBody["internal_fistula"].(string)
  4497. evaluation.InternalFistula = internal_fistula
  4498. }
  4499. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  4500. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  4501. evaluation.InternalFistulaSkin = internal_fistula_skin
  4502. }
  4503. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  4504. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  4505. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  4506. evaluation.IsHemorrhage = is_hemorrhage
  4507. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  4508. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  4509. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  4510. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  4511. is_hemorrhage = 0
  4512. }
  4513. evaluation.IsHemorrhage = is_hemorrhage
  4514. if is_hemorrhage == 1 {
  4515. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  4516. hemorrhage, _ := dataBody["hemorrhage"].(string)
  4517. evaluation.Hemorrhage = hemorrhage
  4518. }
  4519. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  4520. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  4521. evaluation.HemorrhageOther = hemorrhage_other
  4522. }
  4523. }
  4524. } else {
  4525. evaluation.IsHemorrhage = 0
  4526. }
  4527. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  4528. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  4529. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  4530. }
  4531. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  4532. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  4533. evaluation.InternalFistulaOther = internal_fistula_other
  4534. }
  4535. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  4536. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  4537. evaluation.BloodAccessNoise = blood_access_noise
  4538. }
  4539. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  4540. //puncture_way := int64(dataBody["puncture_way"].(float64))
  4541. puncture_way := dataBody["puncture_way"].(string)
  4542. evaluation.PunctureWay = puncture_way
  4543. }
  4544. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  4545. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  4546. evaluation.VenousCatheterization = venous_catheterization
  4547. }
  4548. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  4549. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  4550. evaluation.VenousCatheterizationPart = venous_catheterization_part
  4551. }
  4552. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  4553. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  4554. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  4555. }
  4556. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  4557. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  4558. evaluation.DuctusArantii = ductus_arantii
  4559. }
  4560. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  4561. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  4562. evaluation.EmergencyTreatment = emergency_treatment
  4563. }
  4564. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  4565. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  4566. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  4567. }
  4568. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  4569. dialysis_count, _ := dataBody["dialysis_count"].(string)
  4570. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  4571. evaluation.DialysisCount = dialysis_count
  4572. }
  4573. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  4574. is_infect, _ := dataBody["is_infect"].(string)
  4575. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  4576. evaluation.IsInfect = infect
  4577. }
  4578. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  4579. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  4580. evaluation.Exposed = exposed
  4581. }
  4582. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  4583. skin, _ := dataBody["skin"].(string)
  4584. //skins, _ := strconv.ParseInt(skin, 10, 64)
  4585. evaluation.Skin = skin
  4586. }
  4587. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  4588. skin_other, _ := dataBody["skin_other"].(string)
  4589. evaluation.SkinOther = skin_other
  4590. }
  4591. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  4592. infect_other, _ := dataBody["infect_other"].(string)
  4593. evaluation.InfectOther = infect_other
  4594. }
  4595. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  4596. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  4597. evaluation.DuctusArantiiOther = ductus_arantii_other
  4598. }
  4599. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4600. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  4601. evaluation.PunctureNeedle = punctureNeedle
  4602. }
  4603. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  4604. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  4605. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  4606. }
  4607. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  4608. pinholing := dataBody["pinholing"].(string)
  4609. evaluation.Phinholing = pinholing
  4610. }
  4611. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4612. catheter_suture := dataBody["catheter_suture"].(string)
  4613. evaluation.CatheterSuture = catheter_suture
  4614. }
  4615. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4616. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4617. evaluation.CatheterSutureOther = catheter_suture_other
  4618. }
  4619. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4620. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4621. evaluation.UrineVolume = urine_volume
  4622. }
  4623. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4624. edema := dataBody["edema"].(string)
  4625. evaluation.Edema = edema
  4626. }
  4627. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4628. specialTreatment := dataBody["special_treatment"].(string)
  4629. evaluation.SpecialTreatment = specialTreatment
  4630. }
  4631. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4632. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4633. evaluation.CatheterMaintenance = catheter_maintenance
  4634. }
  4635. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4636. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4637. evaluation.ThromubusType = thromubusType
  4638. }
  4639. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4640. thrombus_av := dataBody["thrombus_av"].(string)
  4641. evaluation.ThrombusAv = thrombus_av
  4642. }
  4643. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4644. thromubus_a := dataBody["thromubus_a"].(string)
  4645. evaluation.ThromubusA = thromubus_a
  4646. }
  4647. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4648. thromubus_v := dataBody["thromubus_v"].(string)
  4649. evaluation.ThromubusV = thromubus_v
  4650. }
  4651. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4652. dehydration := dataBody["dehydration"].(string)
  4653. evaluation.Dehydration = dehydration
  4654. }
  4655. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4656. period := int64(dataBody["period"].(float64))
  4657. evaluation.Period = period
  4658. }
  4659. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4660. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4661. evaluation.EstimatedFoodIntake = estimated_food_intake
  4662. }
  4663. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4664. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4665. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4666. }
  4667. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4668. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4669. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4670. }
  4671. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4672. urea_befor := dataBody["urea_befor"].(string)
  4673. evaluation.UreaBefor = urea_befor
  4674. }
  4675. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4676. suction := dataBody["suction"].(string)
  4677. evaluation.Suction = suction
  4678. }
  4679. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4680. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4681. evaluation.WeightBeforRemake = weight_befor_remake
  4682. }
  4683. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4684. height := dataBody["height"].(string)
  4685. evaluation.Height = height
  4686. }
  4687. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4688. age := dataBody["age"].(string)
  4689. evaluation.Age = age
  4690. }
  4691. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4692. his_department := dataBody["his_department"].(string)
  4693. evaluation.HisDepartment = his_department
  4694. }
  4695. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4696. his_bed := dataBody["his_bed"].(string)
  4697. evaluation.HisBed = his_bed
  4698. }
  4699. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4700. point_puncture := dataBody["point_puncture"].(string)
  4701. evaluation.PointPuncture = point_puncture
  4702. }
  4703. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4704. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4705. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4706. }
  4707. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4708. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4709. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4710. }
  4711. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4712. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4713. evaluation.WhetherUnobstructed = whether_unobstructed
  4714. }
  4715. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4716. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4717. evaluation.LienNecessary = lien_necessary
  4718. }
  4719. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4720. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4721. timeLayout := "2006-01-02"
  4722. loc, _ := time.LoadLocation("Local")
  4723. var startTime int64
  4724. if len(pathway_formation_time) > 0 {
  4725. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4726. startTime = theTime.Unix()
  4727. }
  4728. evaluation.PathwayFormationTime = startTime
  4729. }
  4730. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4731. befor_symptoms := dataBody["befor_symptoms"].(string)
  4732. evaluation.BeforSymptoms = befor_symptoms
  4733. }
  4734. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4735. washing_time, _ := dataBody["washing_time"].(string)
  4736. evaluation.WashingTime = washing_time
  4737. }
  4738. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4739. warsh_count, _ := dataBody["warsh_count"].(string)
  4740. evaluation.WarshCount = warsh_count
  4741. }
  4742. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4743. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4744. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4745. }
  4746. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4747. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4748. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4749. }
  4750. return
  4751. }
  4752. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4753. dataBody := make(map[string]interface{}, 0)
  4754. err := json.Unmarshal(data, &dataBody)
  4755. if err != nil {
  4756. utils.ErrorLog(err.Error())
  4757. code = enums.ErrorCodeParamWrong
  4758. return
  4759. }
  4760. timeLayout := "2006-01-02"
  4761. loc, _ := time.LoadLocation("Local")
  4762. isChild := false
  4763. if action == "create" {
  4764. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4765. utils.ErrorLog("advice_type")
  4766. code = enums.ErrorCodeParamWrong
  4767. return
  4768. }
  4769. adviceType := int64(dataBody["advice_type"].(float64))
  4770. if adviceType != 1 && adviceType != 2 {
  4771. utils.ErrorLog("advice_type != 1&&2")
  4772. code = enums.ErrorCodeParamWrong
  4773. return
  4774. }
  4775. advice.AdviceType = adviceType
  4776. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4777. utils.ErrorLog("advice_date")
  4778. code = enums.ErrorCodeParamWrong
  4779. return
  4780. }
  4781. adviceDate, _ := dataBody["advice_date"].(string)
  4782. if len(adviceDate) == 0 {
  4783. utils.ErrorLog("len(adviceDate) == 0")
  4784. code = enums.ErrorCodeParamWrong
  4785. return
  4786. }
  4787. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4788. if err != nil {
  4789. utils.ErrorLog(err.Error())
  4790. code = enums.ErrorCodeParamWrong
  4791. return
  4792. }
  4793. advice.AdviceDate = theTime.Unix()
  4794. advice.RecordDate = theTime.Unix()
  4795. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4796. parentId := int64(dataBody["parent_id"].(float64))
  4797. advice.ParentId = parentId
  4798. if parentId > 0 {
  4799. isChild = true
  4800. }
  4801. }
  4802. } else {
  4803. isChild = advice.ParentId > 0
  4804. }
  4805. if !isChild {
  4806. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4807. utils.ErrorLog("start_time")
  4808. code = enums.ErrorCodeParamWrong
  4809. return
  4810. }
  4811. startTime, _ := dataBody["start_time"].(string)
  4812. if len(startTime) == 0 {
  4813. utils.ErrorLog("len(start_time) == 0")
  4814. code = enums.ErrorCodeParamWrong
  4815. return
  4816. }
  4817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4818. if err != nil {
  4819. utils.ErrorLog(err.Error())
  4820. code = enums.ErrorCodeParamWrong
  4821. return
  4822. }
  4823. advice.StartTime = theTime.Unix()
  4824. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4825. deliveryWay, _ := dataBody["delivery_way"].(string)
  4826. advice.DeliveryWay = deliveryWay
  4827. }
  4828. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4829. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4830. advice.ExecutionFrequency = executionFrequency
  4831. }
  4832. }
  4833. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4834. deliveryWay, _ := dataBody["delivery_way"].(string)
  4835. advice.DeliveryWay = deliveryWay
  4836. }
  4837. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4838. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4839. advice.ExecutionFrequency = executionFrequency
  4840. }
  4841. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4842. utils.ErrorLog("advice_name")
  4843. code = enums.ErrorCodeParamWrong
  4844. return
  4845. }
  4846. adviceName, _ := dataBody["advice_name"].(string)
  4847. if len(adviceName) == 0 {
  4848. utils.ErrorLog("len(advice_name) == 0")
  4849. code = enums.ErrorCodeParamWrong
  4850. return
  4851. }
  4852. advice.AdviceName = adviceName
  4853. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4854. adviceDsc, _ := dataBody["advice_desc"].(string)
  4855. advice.AdviceDesc = adviceDsc
  4856. }
  4857. if dataBody["way"] == nil {
  4858. advice.Way = 0
  4859. } else {
  4860. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4861. way := int64(dataBody["way"].(float64))
  4862. advice.Way = way
  4863. }
  4864. }
  4865. if dataBody["drug_id"] == nil {
  4866. advice.DrugId = 0
  4867. } else {
  4868. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4869. drug_id := int64(dataBody["drug_id"].(float64))
  4870. advice.DrugId = drug_id
  4871. }
  4872. }
  4873. if dataBody["drug_name_id"] == nil {
  4874. advice.DrugNameId = 0
  4875. } else {
  4876. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4877. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4878. advice.DrugNameId = drug_name_id
  4879. }
  4880. }
  4881. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4882. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4883. advice.SingleDose = singleDose
  4884. }
  4885. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4886. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4887. advice.SingleDoseUnit = singleDoseUnit
  4888. }
  4889. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4890. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4891. advice.DrugSpec = drugSpec
  4892. }
  4893. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4894. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4895. advice.DrugSpecUnit = drugSpecUnit
  4896. }
  4897. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4898. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4899. advice.PrescribingNumber = prescribingNumber
  4900. }
  4901. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4902. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4903. advice.PrescribingNumberUnit = prescribingNumberUnit
  4904. }
  4905. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4906. remark, _ := dataBody["remark"].(string)
  4907. advice.Remark = remark
  4908. }
  4909. return
  4910. }
  4911. func (c *PatientApiController) GetPatientEducation() {
  4912. patientID, _ := c.GetInt64("patient_id", 0)
  4913. page, _ := c.GetInt64("page", 0)
  4914. limit, _ := c.GetInt64("limit", 0)
  4915. startTime := c.GetString("start_time", "")
  4916. endTime := c.GetString("end_time", "")
  4917. if page <= 0 {
  4918. page = 1
  4919. }
  4920. if limit <= 0 {
  4921. limit = 10
  4922. }
  4923. if patientID <= 0 {
  4924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4925. return
  4926. }
  4927. timeLayout := "2006-01-02"
  4928. loc, _ := time.LoadLocation("Local")
  4929. var theStartTIme int64
  4930. if len(startTime) > 0 {
  4931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4932. if err != nil {
  4933. theStartTIme = 0
  4934. }
  4935. theStartTIme = theTime.Unix()
  4936. }
  4937. var theEndtTIme int64
  4938. if len(endTime) > 0 {
  4939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4940. if err != nil {
  4941. theEndtTIme = 0
  4942. }
  4943. theEndtTIme = theTime.Unix()
  4944. }
  4945. adminUserInfo := c.GetMobileAdminUserInfo()
  4946. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4947. c.ServeSuccessJSON(map[string]interface{}{
  4948. "total": total,
  4949. "edus": edus,
  4950. })
  4951. return
  4952. }
  4953. func (c *PatientApiController) GetPatientSchedulesList() {
  4954. patientID, _ := c.GetInt64("patient_id", 0)
  4955. page, _ := c.GetInt64("page", 0)
  4956. limit, _ := c.GetInt64("limit", 0)
  4957. if patientID <= 0 {
  4958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4959. return
  4960. }
  4961. adminUserInfo := c.GetMobileAdminUserInfo()
  4962. todayTime := time.Now().Format("2006-01-02")
  4963. timeLayout := "2006-01-02 15:04:05"
  4964. loc, _ := time.LoadLocation("Local")
  4965. var theStartTime int64
  4966. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4967. theStartTime = theTime.Unix()
  4968. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4969. if len(schedules) > 0 {
  4970. for index, item := range schedules {
  4971. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4972. schedules[index].Week = int64(week)
  4973. }
  4974. }
  4975. c.ServeSuccessJSON(map[string]interface{}{
  4976. "schedules": schedules,
  4977. })
  4978. return
  4979. }
  4980. func (c *PatientApiController) GetRecords() {
  4981. patientID, _ := c.GetInt64("patient_id", 0)
  4982. page, _ := c.GetInt64("page", 0)
  4983. limit, _ := c.GetInt64("limit", 0)
  4984. startTime := c.GetString("start_time", "")
  4985. endTime := c.GetString("end_time", "")
  4986. mode_id, _ := c.GetInt64("mode_id", 0)
  4987. if page <= 0 {
  4988. page = 1
  4989. }
  4990. if limit <= 0 {
  4991. limit = 10
  4992. }
  4993. if patientID <= 0 {
  4994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4995. return
  4996. }
  4997. timeLayout := "2006-01-02"
  4998. loc, _ := time.LoadLocation("Local")
  4999. var theStartTIme int64
  5000. if len(startTime) > 0 {
  5001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5002. if err != nil {
  5003. theStartTIme = 0
  5004. }
  5005. theStartTIme = theTime.Unix()
  5006. }
  5007. var theEndtTIme int64
  5008. if len(endTime) > 0 {
  5009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  5010. if err != nil {
  5011. theEndtTIme = 0
  5012. }
  5013. theEndtTIme = theTime.Unix()
  5014. }
  5015. adminUserInfo := c.GetMobileAdminUserInfo()
  5016. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  5017. c.ServeSuccessJSON(map[string]interface{}{
  5018. "total": total,
  5019. "records": records,
  5020. })
  5021. return
  5022. }
  5023. func (c *PatientApiController) GetPatientMonitor() {
  5024. partition, _ := c.GetInt64("partition")
  5025. monitorDate := c.GetString("date")
  5026. patient_id, _ := c.GetInt64("patient_id")
  5027. timeLayout := "2006-01-02"
  5028. loc, _ := time.LoadLocation("Local")
  5029. var theStartTime int64
  5030. if len(monitorDate) > 0 {
  5031. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  5032. if err != nil {
  5033. theStartTime = 0
  5034. }
  5035. theStartTime = theTime.Unix()
  5036. }
  5037. adminInfo := c.GetMobileAdminUserInfo()
  5038. orgID := adminInfo.Org.Id
  5039. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  5040. if err != nil {
  5041. c.ErrorLog("获取排班信息失败:%v", err)
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5043. } else {
  5044. if len(monitor) > 0 {
  5045. //获取所有床位
  5046. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  5047. //获取所有分区
  5048. zoneList, _ := service.GetAllZoneByList(orgID)
  5049. //获取透析处方
  5050. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  5051. //获取透前评估
  5052. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  5053. //获取上机
  5054. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  5055. //获取透后
  5056. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  5057. //获取透后监测
  5058. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  5059. //获取所有的患者
  5060. patients, _ := service.GetAllPatientListByListOne(orgID)
  5061. for _, it := range patients {
  5062. if orgID == 10445 {
  5063. if theStartTime <= 1703952000 {
  5064. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  5065. it.TotalDialysis = listOne.Count
  5066. }
  5067. if theStartTime >= 1704038400 {
  5068. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  5069. it.TotalDialysis = listOrder.Count
  5070. }
  5071. }
  5072. }
  5073. //获取所有透析模式
  5074. treatments, _ := service.GetAllTreatModeByList(orgID)
  5075. for key, item := range monitor {
  5076. // 获取床位信息
  5077. for _, it := range numberList {
  5078. if item.BedId == it.ID {
  5079. monitor[key].DeviceNumber = it
  5080. break
  5081. }
  5082. }
  5083. //获取分区信息
  5084. for _, it := range zoneList {
  5085. if item.PartitionId == it.ID {
  5086. monitor[key].DeviceZone = it
  5087. }
  5088. }
  5089. for _, prescription := range prescriptions {
  5090. if item.PatientId == prescription.PatientId {
  5091. monitor[key].Prescription = prescription
  5092. break
  5093. }
  5094. }
  5095. // 透前评估
  5096. for _, assessmentBefore := range assessmentBefores {
  5097. if item.PatientId == assessmentBefore.PatientId {
  5098. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  5099. break
  5100. }
  5101. }
  5102. // 透析上下机
  5103. for _, dialysisOrder := range dialysisOrders {
  5104. if item.PatientId == dialysisOrder.PatientId {
  5105. monitor[key].DialysisOrder = dialysisOrder
  5106. break
  5107. }
  5108. }
  5109. // 治疗小节
  5110. for _, afterDislysis := range AssessmentAfterDislysis {
  5111. if item.PatientId == afterDislysis.PatientId {
  5112. monitor[key].AssessmentAfterDislysis = afterDislysis
  5113. break
  5114. }
  5115. }
  5116. for _, it := range monitorlist {
  5117. if item.PatientId == it.PatientId {
  5118. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  5119. }
  5120. }
  5121. for _, patient := range patients {
  5122. if item.PatientId == patient.ID {
  5123. monitor[key].MonitorPatients = patient
  5124. break
  5125. }
  5126. }
  5127. for _, treatment := range treatments {
  5128. if item.ModeId == treatment.ID {
  5129. monitor[key].TreatmentMode = treatment
  5130. break
  5131. }
  5132. }
  5133. }
  5134. }
  5135. }
  5136. //获取患者的透析次数
  5137. //count, err := service.GetDialysisCount(orgID, partition)
  5138. patients, err := service.GetAllpatientFourty(orgID)
  5139. if err == nil {
  5140. c.ServeSuccessJSON(map[string]interface{}{
  5141. "monitor": monitor,
  5142. //"patientCount": count,
  5143. "patients": patients,
  5144. })
  5145. } else {
  5146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5147. }
  5148. }
  5149. // /m/api/monitor/patient [get] 搜索病人的测量记录
  5150. // @param keyword:string 病人姓名或透析号
  5151. // @param page:int
  5152. func (this *PatientApiController) SearchMonitorPatient() {
  5153. keyword := this.GetString("keyword")
  5154. page, _ := this.GetInt("page")
  5155. if page <= 0 {
  5156. page = 1
  5157. }
  5158. if len(keyword) == 0 {
  5159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5160. return
  5161. }
  5162. adminUserInfo := this.GetMobileAdminUserInfo()
  5163. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  5164. if getMonitorErr != nil {
  5165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5166. return
  5167. } else {
  5168. this.ServeSuccessJSON(map[string]interface{}{
  5169. "monitor": monitors,
  5170. })
  5171. }
  5172. }
  5173. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  5174. id, _ := c.GetInt64("id", 0)
  5175. page, _ := c.GetInt64("page", 0)
  5176. limit, _ := c.GetInt64("limit", 0)
  5177. if id <= 0 {
  5178. c.ServeSuccessJSON(map[string]interface{}{
  5179. "solutions": nil,
  5180. })
  5181. return
  5182. }
  5183. if page <= 0 {
  5184. page = 1
  5185. }
  5186. if limit <= 0 {
  5187. limit = 10
  5188. }
  5189. adminInfo := c.GetMobileAdminUserInfo()
  5190. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  5191. c.ServeSuccessJSON(map[string]interface{}{
  5192. "solutions": solutions,
  5193. "total": total,
  5194. })
  5195. return
  5196. }
  5197. // GetDoctorAdvices 医嘱列表
  5198. func (c *PatientApiController) GetDoctorAdvices() {
  5199. id, _ := c.GetInt64("id", 0)
  5200. adviceType, _ := c.GetInt64("advice_type", 0)
  5201. stopType, _ := c.GetInt64("stop_state", 0)
  5202. startTime := c.GetString("start_time", "")
  5203. endTime := c.GetString("end_time", "")
  5204. keywords := c.GetString("keywords", "")
  5205. need, _ := c.GetInt64("need_doctor", 0)
  5206. adminUserInfo := c.GetMobileAdminUserInfo()
  5207. timeLayout := "2006-01-02"
  5208. loc, _ := time.LoadLocation("Local")
  5209. var theStartTIme int64
  5210. if len(startTime) > 0 {
  5211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5212. if err != nil {
  5213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5214. return
  5215. }
  5216. theStartTIme = theTime.Unix()
  5217. }
  5218. var theEndtTIme int64
  5219. if len(endTime) > 0 {
  5220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  5221. if err != nil {
  5222. utils.ErrorLog(err.Error())
  5223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5224. return
  5225. }
  5226. theEndtTIme = theTime.Unix()
  5227. }
  5228. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  5229. if need == 1 {
  5230. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  5231. c.ServeSuccessJSON(map[string]interface{}{
  5232. "advices": advices,
  5233. "total": total,
  5234. "users": users,
  5235. })
  5236. } else {
  5237. c.ServeSuccessJSON(map[string]interface{}{
  5238. "advices": advices,
  5239. "total": total,
  5240. "users": []string{},
  5241. })
  5242. }
  5243. return
  5244. }
  5245. func (c *PatientApiController) GetPrintDialysisOrder() {
  5246. xtno := c.GetString("xtno")
  5247. xtdate := c.GetString("xtdate")
  5248. timeLayout := "2006-01-02"
  5249. loc, _ := time.LoadLocation("Local")
  5250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  5251. if err != nil {
  5252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5253. return
  5254. }
  5255. xttime := theTime.Unix()
  5256. //获取当前日期月份的第一天
  5257. firstmonth := service.GetFirstDateOfMonth(theTime)
  5258. firstMonthDate := firstmonth.Unix()
  5259. operatorIDs := make([]int64, 0)
  5260. adminUserInfo := c.GetMobileAdminUserInfo()
  5261. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  5262. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  5263. //透析单
  5264. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5265. if dialysisOrder != nil {
  5266. if dialysisOrder.FinishNurse > 0 {
  5267. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  5268. }
  5269. if dialysisOrder.StartNurse > 0 {
  5270. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  5271. }
  5272. }
  5273. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5274. //透前评估
  5275. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5276. //透后评估
  5277. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5278. if AssessmentAfterDislysis.Modifier > 0 {
  5279. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  5280. }
  5281. //透析处方
  5282. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5283. if dialysisPrescription.PrescriptionDoctor > 0 {
  5284. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  5285. }
  5286. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5287. patientInfo.TotalDialysis = dialysis_count
  5288. //临时医嘱
  5289. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5290. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5291. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  5292. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  5293. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5294. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5295. if adminUserInfo.Org.Id != 10489 {
  5296. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  5297. for _, item := range projects {
  5298. cnt, _ := strconv.ParseFloat(item.Count, 64)
  5299. var advice models.HisDoctorAdviceInfo
  5300. advice.ID = item.ID
  5301. advice.Checker = item.Checker
  5302. advice.CheckTime = item.CheckTime
  5303. advice.CheckState = item.CheckState
  5304. advice.ExecutionState = item.ExecutionState
  5305. advice.ExecutionStaff = item.ExecutionStaff
  5306. //advice.PrescribingNumber = float64(item.Count)
  5307. advice.PrescribingNumber = cnt
  5308. advice.PrescribingNumberUnit = item.Unit
  5309. advice.AdviceDoctor = item.Doctor
  5310. advice.Remark = item.Remark
  5311. if item.Type == 3 {
  5312. advice.AdviceName = item.GoodInfo.GoodName
  5313. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  5314. } else if item.Type == 2 {
  5315. advice.AdviceName = item.HisProject.ProjectName
  5316. }
  5317. advice.StartTime = item.StartTime
  5318. hisAdvice = append(hisAdvice, &advice)
  5319. }
  5320. }
  5321. }
  5322. if len(DoctorAdvice) > 0 {
  5323. for _, item := range DoctorAdvice {
  5324. if item.AdviceDoctor > 0 {
  5325. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  5326. }
  5327. if item.ExecutionStaff > 0 {
  5328. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  5329. }
  5330. if item.Checker > 0 {
  5331. operatorIDs = append(operatorIDs, item.Checker)
  5332. }
  5333. }
  5334. }
  5335. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5336. //透析监测
  5337. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5338. //透析小结
  5339. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5340. //接诊评估
  5341. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5342. if receiverTreatmentAccess.Condition == 1 {
  5343. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  5344. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, patientInfo.ID)
  5345. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  5346. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  5347. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  5348. }
  5349. }
  5350. //相关操作对应的操作人
  5351. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  5352. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  5353. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  5354. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5355. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  5356. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5357. numberList, _ := service.GetAllBedNumberList(adminUserInfo.Org.Id)
  5358. now := time.Now()
  5359. // 计算当前是周几,周一为第1天,周日为第0天
  5360. weekday := now.Weekday()
  5361. // 计算当前日期是周几,并计算出周一的日期
  5362. // 通过减去当前是周几的偏移量再加1来实现(因为Weekday()返回的是从周日开始的索引,而我们想要从周一开始)
  5363. mondayone := now.AddDate(0, 0, -(int(weekday)+6)%7) // 或者使用 monday := now.Add(-time.Hour * 24 * (int(weekday)+6)%7)
  5364. // 设置开始时间为周一的00:00:00
  5365. startOfTheWeek := time.Date(mondayone.Year(), mondayone.Month(), mondayone.Day(), 0, 0, 0, 0, mondayone.Location())
  5366. // 设置结束时间为周日的23:59:59(周一的日期基础上加6天)
  5367. endOfTheWeek := startOfTheWeek.AddDate(0, 0, 6).Add(24*time.Hour - time.Second) // 或者使用 endOfTheWeek := monday.AddDate(0, 0, 7).Add(-time.Second)
  5368. var start_time = startOfTheWeek.Format("2006-01-02")
  5369. var end_time = endOfTheWeek.Format("2006-01-02")
  5370. var startTime int64
  5371. if len(start_time) > 0 {
  5372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5373. if err != nil {
  5374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5375. return
  5376. }
  5377. startTime = theTime.Unix()
  5378. }
  5379. var endTime int64
  5380. if len(end_time) > 0 {
  5381. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5382. if err != nil {
  5383. utils.ErrorLog(err.Error())
  5384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5385. return
  5386. }
  5387. endTime = theTime.Unix()
  5388. }
  5389. if xttime < 1740931200 {
  5390. startTime = 1740326400
  5391. endTime = 1740844800
  5392. }
  5393. scheduleDialyCount, _ := service.GetPatientScheduleDialyCount(patientInfo.ID, startTime, endTime, adminUserInfo.Org.Id)
  5394. dialysis_count_one := len(scheduleDialyCount)
  5395. var dialysis_count_str = "一周" + strconv.Itoa(dialysis_count_one) + "次"
  5396. PredialysisEvaluation.DialysisCount = dialysis_count_str
  5397. if config.IsOpen == 1 {
  5398. c.ServeSuccessJSON(map[string]interface{}{
  5399. "users": adminUser,
  5400. "patientInfo": patientInfo,
  5401. "PredialysisEvaluation": PredialysisEvaluation,
  5402. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5403. "dialysisPrescription": dialysisPrescription,
  5404. "advices": hisAdvice,
  5405. "monitors": Record,
  5406. "summary": TreatmentSummary,
  5407. "receiverTreatmentAccess": receiverTreatmentAccess,
  5408. "dialysisOrder": dialysisOrder,
  5409. "operators": operators,
  5410. "org_template_info": templateInfo,
  5411. "check": check,
  5412. "dialysiscount": dialysiscount,
  5413. "last_order": last_order,
  5414. "projects": projects,
  5415. "project_config": project_config,
  5416. "lastWeight": lastWeight,
  5417. "lastSchedule": lastSchedule,
  5418. "DoctorAdvice": DoctorAdvice,
  5419. "hisAdvice": hisAdvice,
  5420. "numberList": numberList,
  5421. })
  5422. }
  5423. if config.IsOpen == 0 || config.IsOpen == 2 {
  5424. c.ServeSuccessJSON(map[string]interface{}{
  5425. "users": adminUser,
  5426. "patientInfo": patientInfo,
  5427. "PredialysisEvaluation": PredialysisEvaluation,
  5428. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5429. "dialysisPrescription": dialysisPrescription,
  5430. "advices": DoctorAdvice,
  5431. "monitors": Record,
  5432. "summary": TreatmentSummary,
  5433. "receiverTreatmentAccess": receiverTreatmentAccess,
  5434. "dialysisOrder": dialysisOrder,
  5435. "operators": operators,
  5436. "org_template_info": templateInfo,
  5437. "check": check,
  5438. "dialysiscount": dialysiscount,
  5439. "last_order": last_order,
  5440. "projects": projects,
  5441. "project_config": project_config,
  5442. "lastWeight": lastWeight,
  5443. "lastSchedule": lastSchedule,
  5444. "DoctorAdvice": DoctorAdvice,
  5445. "hisAdvice": hisAdvice,
  5446. "numberList": numberList,
  5447. })
  5448. }
  5449. }
  5450. func (c *PatientApiController) CreateGroupAdvice() {
  5451. is_child, _ := c.GetInt64("is_child", 0)
  5452. fmt.Println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", is_child)
  5453. if is_child == 1 {
  5454. patient, _ := c.GetInt64("id", 0)
  5455. if patient <= 0 {
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5457. return
  5458. }
  5459. adminUserInfo := c.GetMobileAdminUserInfo()
  5460. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5461. if patientInfo.ID == 0 {
  5462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5463. return
  5464. }
  5465. group_no, _ := c.GetInt64("group_no")
  5466. if group_no <= 0 {
  5467. group_no = 0
  5468. }
  5469. dataBody := make(map[string]interface{}, 0)
  5470. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5471. if err != nil {
  5472. utils.ErrorLog(err.Error())
  5473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5474. return
  5475. }
  5476. timeLayout := "2006-01-02"
  5477. loc, _ := time.LoadLocation("Local")
  5478. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5479. utils.ErrorLog("advice_type")
  5480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5481. return
  5482. }
  5483. adviceType := int64(dataBody["advice_type"].(float64))
  5484. if adviceType != 1 && adviceType != 2 {
  5485. utils.ErrorLog("advice_type != 1&&2")
  5486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5487. return
  5488. }
  5489. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5490. utils.ErrorLog("start_time")
  5491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5492. return
  5493. }
  5494. startTime2, _ := dataBody["start_time"].(string)
  5495. time_arr := strings.Split(startTime2, " ")
  5496. if len(time_arr) > 0 {
  5497. startTime2 = time_arr[0]
  5498. }
  5499. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5500. utils.ErrorLog("advice_date")
  5501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5502. return
  5503. }
  5504. advice_date, _ := dataBody["advice_date"].(string)
  5505. var advicedateunix int64
  5506. if len(advice_date) > 0 {
  5507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  5508. if err != nil {
  5509. fmt.Println(err)
  5510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5511. return
  5512. }
  5513. advicedateunix = theTime.Unix()
  5514. }
  5515. adviceDate := startTime2
  5516. if len(adviceDate) == 0 {
  5517. utils.ErrorLog("len(adviceDate) == 0")
  5518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5519. return
  5520. }
  5521. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  5522. if err != nil {
  5523. utils.ErrorLog(err.Error())
  5524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5525. return
  5526. }
  5527. AdviceDate := advicedateunix
  5528. RecordDate := advicedateunix
  5529. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5530. utils.ErrorLog("start_time")
  5531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5532. return
  5533. }
  5534. startTime, _ := dataBody["start_time"].(string)
  5535. if len(startTime) == 0 {
  5536. utils.ErrorLog("len(start_time) == 0")
  5537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5538. return
  5539. }
  5540. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  5541. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  5542. if err != nil {
  5543. utils.ErrorLog(err.Error())
  5544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. return
  5546. }
  5547. StartTime := theTime.Unix()
  5548. Remark := ""
  5549. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5550. remark, _ := dataBody["remark"].(string)
  5551. Remark = remark
  5552. }
  5553. Startdate := int64(dataBody["record_date"].(float64))
  5554. var advices []*models.GroupAdvice
  5555. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  5556. utils.ErrorLog("adviceNames")
  5557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5558. return
  5559. }
  5560. adviceNames := dataBody["adviceNames"].([]interface{})
  5561. for _, adviceNameMap := range adviceNames {
  5562. adviceNameM := adviceNameMap.(map[string]interface{})
  5563. var advice models.GroupAdvice
  5564. advice.Remark = Remark
  5565. advice.AdviceType = adviceType
  5566. advice.StartTime = StartTime
  5567. if adminUserInfo.Org.Id == 10340 {
  5568. advice.AdviceDate = AdviceDate
  5569. advice.RecordDate = RecordDate
  5570. }
  5571. if adminUserInfo.Org.Id != 10340 {
  5572. advice.AdviceDate = theTimeOne.Unix()
  5573. advice.RecordDate = theTimeOne.Unix()
  5574. }
  5575. advice.Status = 1
  5576. advice.CreatedTime = time.Now().Unix()
  5577. advice.UpdatedTime = time.Now().Unix()
  5578. advice.StopState = 2
  5579. advice.ExecutionState = 2
  5580. advice.UserOrgId = adminUserInfo.Org.Id
  5581. advice.PatientId = patientInfo.ID
  5582. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5583. advice.IsSettle = 2
  5584. //入口
  5585. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  5586. if errcode > 0 {
  5587. c.ServeFailJSONWithSGJErrorCode(errcode)
  5588. return
  5589. }
  5590. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  5591. subdrugs := adviceNameM["subdrugs"].([]interface{})
  5592. if len(subdrugs) > 0 {
  5593. for _, subdrug := range subdrugs {
  5594. var s models.GroupAdvice
  5595. s.Remark = Remark
  5596. s.AdviceType = adviceType
  5597. s.StartTime = StartTime
  5598. s.AdviceDate = AdviceDate
  5599. s.RecordDate = RecordDate
  5600. s.Status = 1
  5601. s.CreatedTime = time.Now().Unix()
  5602. s.UpdatedTime = time.Now().Unix()
  5603. s.StopState = 2
  5604. s.ExecutionState = 2
  5605. s.UserOrgId = adminUserInfo.Org.Id
  5606. s.PatientId = patientInfo.ID
  5607. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  5608. s.IsSettle = 2
  5609. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  5610. if errcode > 0 {
  5611. c.ServeFailJSONWithSGJErrorCode(errcode)
  5612. return
  5613. }
  5614. advice.Children = append(advice.Children, &s)
  5615. }
  5616. }
  5617. }
  5618. //长沙南雅
  5619. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5620. //查询该患者今日有没有双人核对
  5621. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  5622. if check.ID > 0 {
  5623. advice.Checker = check.Modifier
  5624. advice.CheckState = 1
  5625. advice.CheckTime = time.Now().Unix()
  5626. }
  5627. }
  5628. advices = append(advices, &advice)
  5629. }
  5630. // 查询信息规挡的设置天数
  5631. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5632. if infor.ID > 0 && infor.WeekDay > 0 {
  5633. var cha_time int64
  5634. timeNowStr := time.Now().Format("2006-01-02")
  5635. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5636. //今日的日期减去设置的日期
  5637. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5638. if cha_time >= Startdate {
  5639. //查询审核是否允许
  5640. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  5641. //申请状态不允许的情况 拒绝修改
  5642. if infor.ApplicationStatus != 1 {
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5644. return
  5645. }
  5646. }
  5647. }
  5648. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  5649. for _, item := range advices {
  5650. //记录日志
  5651. byterequest, _ := json.Marshal(item)
  5652. adviceLog := models.XtDoctorAdviceLog{
  5653. UserOrgId: item.UserOrgId,
  5654. PatientId: item.PatientId,
  5655. AdminUserId: adminUserInfo.AdminUser.Id,
  5656. Module: 1,
  5657. ErrLog: string(byterequest),
  5658. Status: 1,
  5659. Ctime: time.Now().Unix(),
  5660. Mtime: 0,
  5661. Source: "手机端新增医嘱",
  5662. RecordDate: item.AdviceDate,
  5663. }
  5664. service.CreateDoctorAdviceLog(adviceLog)
  5665. }
  5666. finish := models.XtDialysisFinish{
  5667. IsFinish: 1,
  5668. UserOrgId: adminUserInfo.Org.Id,
  5669. Status: 1,
  5670. Ctime: time.Now().Unix(),
  5671. Mtime: 0,
  5672. Module: 4,
  5673. RecordDate: advicedateunix,
  5674. Sourse: 1,
  5675. PatientId: patient,
  5676. }
  5677. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5678. if dialysisFinish.ID == 0 {
  5679. service.CreateDialysisFinish(finish)
  5680. }
  5681. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5682. redis := service.RedisClient()
  5683. //清空key 值
  5684. redis.Set(key, "", time.Second)
  5685. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5686. redis.Set(keyOne, "", time.Second)
  5687. defer redis.Close()
  5688. if createErr != nil {
  5689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5690. return
  5691. }
  5692. c.ServeSuccessJSON(map[string]interface{}{
  5693. "msg": "ok",
  5694. "advices": newAdvices,
  5695. })
  5696. return
  5697. } else if is_child == 2 {
  5698. patient, _ := c.GetInt64("id", 0)
  5699. if patient <= 0 {
  5700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5701. return
  5702. }
  5703. adminUserInfo := c.GetMobileAdminUserInfo()
  5704. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5705. if patientInfo.ID == 0 {
  5706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5707. return
  5708. }
  5709. var advice models.DoctorAdvice
  5710. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5711. if code > 0 {
  5712. c.ServeFailJSONWithSGJErrorCode(code)
  5713. return
  5714. }
  5715. if advice.ParentId > 0 {
  5716. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5717. if old.ID == 0 || old.PatientId != patient {
  5718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5719. return
  5720. }
  5721. if old.StopState == 1 || old.ExecutionState == 1 {
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5723. return
  5724. }
  5725. if old.ParentId > 0 {
  5726. advice.ParentId = old.ParentId
  5727. }
  5728. advice.StartTime = old.StartTime
  5729. advice.AdviceDoctor = old.AdviceDoctor
  5730. advice.DeliveryWay = old.DeliveryWay
  5731. advice.ExecutionFrequency = old.ExecutionFrequency
  5732. advice.GroupNo = old.GroupNo
  5733. }
  5734. advice.Status = 1
  5735. advice.CreatedTime = time.Now().Unix()
  5736. advice.UpdatedTime = time.Now().Unix()
  5737. advice.StopState = 2
  5738. advice.ExecutionState = 2
  5739. advice.UserOrgId = adminUserInfo.Org.Id
  5740. advice.PatientId = patient
  5741. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5742. advice.IsSettle = 2
  5743. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5744. if advice.PrescribingNumber == 0 {
  5745. advice.PrescribingNumber = 1
  5746. }
  5747. //查询该患者今日有没有双人核对
  5748. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5749. if check.ID > 0 {
  5750. advice.Checker = check.Modifier
  5751. advice.CheckState = 1
  5752. advice.CheckTime = time.Now().Unix()
  5753. }
  5754. }
  5755. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5756. if infor.ID > 0 {
  5757. var cha_time int64
  5758. timeNowStr := time.Now().Format("2006-01-02")
  5759. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5760. //今日的日期减去设置的日期
  5761. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5762. if cha_time >= advice.RecordDate {
  5763. //查询审核是否允许
  5764. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5765. //申请状态不允许的情况 拒绝修改
  5766. if infor.ApplicationStatus != 1 {
  5767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5768. return
  5769. }
  5770. }
  5771. }
  5772. err := service.CreateDoctorAdvice(&advice)
  5773. //记录日志
  5774. byterequest, _ := json.Marshal(advice)
  5775. adviceLog := models.XtDoctorAdviceLog{
  5776. UserOrgId: advice.UserOrgId,
  5777. PatientId: advice.PatientId,
  5778. AdminUserId: adminUserInfo.Org.Id,
  5779. Module: 1,
  5780. ErrLog: string(byterequest),
  5781. Status: 1,
  5782. Ctime: time.Now().Unix(),
  5783. Mtime: 0,
  5784. Source: "手机端新增医嘱",
  5785. RecordDate: advice.AdviceDate,
  5786. }
  5787. service.CreateDoctorAdviceLog(adviceLog)
  5788. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5789. redis := service.RedisClient()
  5790. //清空key 值
  5791. redis.Set(key, "", time.Second)
  5792. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5793. redis.Set(keyOne, "", time.Second)
  5794. defer redis.Close()
  5795. if err != nil {
  5796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5797. return
  5798. }
  5799. c.ServeSuccessJSON(map[string]interface{}{
  5800. "msg": "ok",
  5801. "advice": advice,
  5802. })
  5803. return
  5804. }
  5805. }
  5806. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5807. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5808. utils.ErrorLog("advice_name")
  5809. return enums.ErrorCodeParamWrong
  5810. }
  5811. adviceName, _ := json["advice_name"].(string)
  5812. if len(adviceName) == 0 {
  5813. utils.ErrorLog("len(advice_name) == 0")
  5814. return enums.ErrorCodeParamWrong
  5815. }
  5816. advice.AdviceName = adviceName
  5817. adviceDesc, _ := json["advice_desc"].(string)
  5818. advice.AdviceDesc = adviceDesc
  5819. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5820. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5821. advice.DrugSpec = drugSpec
  5822. }
  5823. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5824. remark, _ := json["remark"].(string)
  5825. advice.Remark = remark
  5826. }
  5827. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5828. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5829. // advice.Way = src_type
  5830. //}
  5831. if json["way"] == nil {
  5832. advice.Way = 0
  5833. } else {
  5834. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5835. way := int64(json["way"].(float64))
  5836. advice.Way = way
  5837. }
  5838. }
  5839. if json["drug_id"] == nil {
  5840. advice.DrugId = 0
  5841. } else {
  5842. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5843. drug_id := int64(json["drug_id"].(float64))
  5844. advice.DrugId = drug_id
  5845. }
  5846. }
  5847. if json["drug_name_id"] == nil {
  5848. advice.DrugNameId = 0
  5849. } else {
  5850. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5851. drug_name_id := int64(json["drug_name_id"].(float64))
  5852. advice.DrugNameId = drug_name_id
  5853. }
  5854. }
  5855. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5856. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5857. advice.DrugSpecUnit = drugSpecUnit
  5858. }
  5859. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5860. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5861. advice.SingleDose = singleDose
  5862. }
  5863. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5864. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5865. advice.SingleDoseUnit = singleDoseUnit
  5866. }
  5867. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5868. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5869. advice.PrescribingNumber = prescribingNumber
  5870. }
  5871. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5872. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5873. advice.PrescribingNumberUnit = prescribingNumberUnit
  5874. }
  5875. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5876. deliveryWay, _ := json["delivery_way"].(string)
  5877. advice.DeliveryWay = deliveryWay
  5878. }
  5879. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5880. executionFrequency, _ := json["execution_frequency"].(string)
  5881. advice.ExecutionFrequency = executionFrequency
  5882. }
  5883. return 0
  5884. }
  5885. func (c *PatientApiController) DelDoctorAdvice() {
  5886. groupno, _ := c.GetInt64("groupno", -1)
  5887. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5888. patient_id, _ := c.GetInt64("patient_id")
  5889. doc_advice_date, _ := c.GetInt64("advice_date")
  5890. redis := service.RedisClient()
  5891. if is_sub == 1 { //是
  5892. advice_id, _ := c.GetInt64("advice_id")
  5893. adminUserInfo := c.GetMobileAdminUserInfo()
  5894. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5895. if advice.ID == 0 {
  5896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5897. return
  5898. }
  5899. advice.Status = 0
  5900. advice.UpdatedTime = time.Now().Unix()
  5901. advice.Modifier = adminUserInfo.AdminUser.Id
  5902. // 查询信息规挡的设置天数
  5903. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5904. if infor.ID > 0 && infor.WeekDay > 0 {
  5905. var cha_time int64
  5906. timeNowStr := time.Now().Format("2006-01-02")
  5907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5908. //今日的日期减去设置的日期
  5909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5910. if cha_time >= advice.AdviceDate {
  5911. //查询审核是否允许
  5912. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5913. //申请状态不允许的情况 拒绝修改
  5914. if infor.ApplicationStatus != 1 {
  5915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5916. return
  5917. }
  5918. }
  5919. }
  5920. //自备药
  5921. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5922. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5923. //查询库存是否是自备药
  5924. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5925. if selfBasedrug.IsSelfDrug == 1 {
  5926. creater := adminUserInfo.AdminUser.Id
  5927. //退库
  5928. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5929. }
  5930. }
  5931. err := service.DeleteDoctorAdvice(&advice)
  5932. //记录日志
  5933. byterequest, _ := json.Marshal(advice)
  5934. adviceLog := models.XtDoctorAdviceLog{
  5935. UserOrgId: advice.UserOrgId,
  5936. PatientId: advice.PatientId,
  5937. AdminUserId: adminUserInfo.AdminUser.Id,
  5938. Module: 4,
  5939. ErrLog: string(byterequest),
  5940. Status: 1,
  5941. Ctime: time.Now().Unix(),
  5942. Mtime: 0,
  5943. Source: "手机端删除医嘱",
  5944. RecordDate: advice.RecordDate,
  5945. }
  5946. service.CreateDoctorAdviceLog(adviceLog)
  5947. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5948. redis.Set(key, "", time.Second)
  5949. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5950. redis.Set(keyTwo, "", time.Second)
  5951. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5952. redis.Set(keyThree, "", time.Second)
  5953. redis.Close()
  5954. if err != nil {
  5955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5956. return
  5957. }
  5958. c.ServeSuccessJSON(map[string]interface{}{
  5959. "msg": "ok",
  5960. })
  5961. return
  5962. } else { //
  5963. var ids []string
  5964. if groupno == 0 {
  5965. advice_id := c.GetString("advice_id")
  5966. ids = strings.Split(advice_id, ",")
  5967. if len(ids) <= 0 {
  5968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5969. return
  5970. }
  5971. }
  5972. if groupno < 0 {
  5973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5974. return
  5975. }
  5976. adminUserInfo := c.GetMobileAdminUserInfo()
  5977. var advice models.DoctorAdvice
  5978. if groupno > 0 {
  5979. advice, _ = service.FindDoctorAdviceByGoroupNoOne(adminUserInfo.Org.Id, groupno, patient_id, doc_advice_date)
  5980. if advice.ID == 0 {
  5981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5982. return
  5983. }
  5984. } else {
  5985. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5986. for _, item := range advices {
  5987. if item.ID == 0 {
  5988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5989. return
  5990. }
  5991. }
  5992. }
  5993. advice.UpdatedTime = time.Now().Unix()
  5994. advice.Status = 0
  5995. advice.GroupNo = groupno
  5996. advice.Modifier = adminUserInfo.AdminUser.Id
  5997. var err error
  5998. if groupno > 0 {
  5999. // 查询信息规挡的设置天数
  6000. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  6001. if infor.ID > 0 {
  6002. var cha_time int64
  6003. timeNowStr := time.Now().Format("2006-01-02")
  6004. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6005. //今日的日期减去设置的日期
  6006. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6007. if cha_time >= advice.AdviceDate {
  6008. //查询审核是否允许
  6009. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  6010. //申请状态不允许的情况 拒绝修改
  6011. if infor.ApplicationStatus != 1 {
  6012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6013. return
  6014. }
  6015. }
  6016. }
  6017. //自备药
  6018. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  6019. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  6020. //查询库存是否是自备药
  6021. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  6022. if selfBasedrug.IsSelfDrug == 1 {
  6023. creater := adminUserInfo.AdminUser.Id
  6024. //退库
  6025. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  6026. }
  6027. }
  6028. err = service.DeleteDoctorAdviceByGroupNoOne(&advice)
  6029. //记录日志
  6030. byterequest, _ := json.Marshal(advice)
  6031. adviceLog := models.XtDoctorAdviceLog{
  6032. UserOrgId: advice.UserOrgId,
  6033. PatientId: advice.PatientId,
  6034. AdminUserId: adminUserInfo.AdminUser.Id,
  6035. Module: 4,
  6036. ErrLog: string(byterequest),
  6037. Status: 1,
  6038. Ctime: time.Now().Unix(),
  6039. Mtime: 0,
  6040. Source: "手机端删除医嘱",
  6041. RecordDate: advice.RecordDate,
  6042. }
  6043. service.CreateDoctorAdviceLog(adviceLog)
  6044. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  6045. redis.Set(key, "", time.Second)
  6046. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  6047. redis.Set(keyTwo, "", time.Second)
  6048. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  6049. redis.Set(keyThree, "", time.Second)
  6050. } else {
  6051. // 查询信息规挡的设置天数
  6052. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  6053. if infor.ID > 0 {
  6054. var cha_time int64
  6055. timeNowStr := time.Now().Format("2006-01-02")
  6056. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6057. //今日的日期减去设置的日期
  6058. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6059. if cha_time >= advice.AdviceDate {
  6060. //查询审核是否允许
  6061. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  6062. //申请状态不允许的情况 拒绝修改
  6063. if infor.ApplicationStatus != 1 {
  6064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6065. return
  6066. }
  6067. }
  6068. }
  6069. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  6070. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  6071. for _, item := range advicelist {
  6072. //自备药
  6073. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  6074. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  6075. //查询库存是否是自备药
  6076. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  6077. if selfBasedrug.IsSelfDrug == 1 {
  6078. creater := adminUserInfo.AdminUser.Id
  6079. //退库
  6080. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  6081. }
  6082. }
  6083. //记录日志
  6084. byterequest, _ := json.Marshal(item)
  6085. adviceLog := models.XtDoctorAdviceLog{
  6086. UserOrgId: item.UserOrgId,
  6087. PatientId: item.PatientId,
  6088. AdminUserId: adminUserInfo.AdminUser.Id,
  6089. Module: 4,
  6090. ErrLog: string(byterequest),
  6091. Status: 1,
  6092. Ctime: time.Now().Unix(),
  6093. Mtime: 0,
  6094. Source: "手机端批量删除医嘱",
  6095. RecordDate: item.RecordDate,
  6096. }
  6097. service.CreateDoctorAdviceLog(adviceLog)
  6098. }
  6099. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  6100. redis.Set(key, "", time.Second)
  6101. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  6102. redis.Set(keyTwo, "", time.Second)
  6103. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  6104. redis.Set(keyThree, "", time.Second)
  6105. redis.Close()
  6106. }
  6107. if err != nil {
  6108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  6109. return
  6110. }
  6111. c.ServeSuccessJSON(map[string]interface{}{
  6112. "msg": "ok",
  6113. })
  6114. return
  6115. }
  6116. }
  6117. // /m/api/advice/group/modify_starttime [post]
  6118. // @param group_no:int
  6119. // @param start_time:string yyyy-MM-dd hh:mm:ss
  6120. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  6121. group_no, _ := this.GetInt64("group_no")
  6122. start_time_str := this.GetString("start_time")
  6123. if group_no <= 0 || len(start_time_str) == 0 {
  6124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6125. return
  6126. }
  6127. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  6128. if parseTimeErr != nil {
  6129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  6130. return
  6131. }
  6132. adminUserInfo := this.GetMobileAdminUserInfo()
  6133. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  6134. if updateStartTimeErr != nil {
  6135. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  6136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6137. return
  6138. }
  6139. this.ServeSuccessJSON(map[string]interface{}{
  6140. "start_time": startTime.Unix(),
  6141. })
  6142. }
  6143. func (this *PatientApiController) DelSubDoctorAdvice() {
  6144. advice_id, _ := this.GetInt64("advice_id")
  6145. adminUserInfo := this.GetMobileAdminUserInfo()
  6146. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  6147. if advice.ID == 0 {
  6148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  6149. return
  6150. }
  6151. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  6152. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  6153. // return
  6154. //}
  6155. advice.Status = 0
  6156. advice.UpdatedTime = time.Now().Unix()
  6157. advice.Modifier = adminUserInfo.AdminUser.Id
  6158. err := service.DeleteDoctorAdvice(&advice)
  6159. if err != nil {
  6160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  6161. return
  6162. }
  6163. this.ServeSuccessJSON(map[string]interface{}{
  6164. "msg": "ok",
  6165. })
  6166. return
  6167. }
  6168. func (this *PatientApiController) GetAdviceUnReadMessage() {
  6169. //adminUserInfo := this.GetMobileAdminUserInfo()
  6170. //service.FindUnReadDoctorAdviceMessage()
  6171. }
  6172. func (this *PatientApiController) GetPatientsByKeyWord() {
  6173. keyWord := this.GetString("keyword")
  6174. adminUserInfo := this.GetMobileAdminUserInfo()
  6175. today := utils.ZeroHourTimeOfDay(time.Now())
  6176. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  6177. if err != nil {
  6178. utils.ErrorLog(err.Error())
  6179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6180. return
  6181. }
  6182. this.ServeSuccessJSON(map[string]interface{}{
  6183. "patient": patient,
  6184. })
  6185. }
  6186. func (this *PatientApiController) GetSearchPatient() {
  6187. keyWord := this.GetString("keyword")
  6188. adminUserInfo := this.GetMobileAdminUserInfo()
  6189. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  6190. if err != nil {
  6191. utils.ErrorLog(err.Error())
  6192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6193. return
  6194. }
  6195. this.ServeSuccessJSON(map[string]interface{}{
  6196. "patient": patient,
  6197. })
  6198. }
  6199. func (c *PatientApiController) ExecProject() {
  6200. execution_time := c.GetString("execution_time")
  6201. project_id, _ := c.GetInt64("project_id")
  6202. team_id, _ := c.GetInt64("team_id")
  6203. is_check_team, _ := c.GetInt64("is_check_team")
  6204. record_date, _ := c.GetInt64("record_date")
  6205. patient_id, _ := c.GetInt64("patient_id")
  6206. if len(execution_time) <= 0 {
  6207. utils.ErrorLog("execution_time")
  6208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6209. return
  6210. }
  6211. timeLayout2 := "2006-01-02 15:04:05"
  6212. loc, _ := time.LoadLocation("Local")
  6213. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  6214. if errs != nil {
  6215. utils.ErrorLog(errs.Error())
  6216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6217. return
  6218. }
  6219. adminInfo := c.GetMobileAdminUserInfo()
  6220. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  6221. //针对舒和
  6222. if adminInfo.Org.Id == 10644 {
  6223. if project.StartTime > theTime.Unix() {
  6224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  6225. return
  6226. }
  6227. }
  6228. if project.Type == 3 {
  6229. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  6230. if good.IsUser != 1 {
  6231. //查询开关是否开启
  6232. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  6233. //开关已经开启
  6234. if stockSetting.IsType == 1 {
  6235. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  6236. scheduleDateStart := theTime.Format("2006-01-02")
  6237. timeLayout3 := "2006-01-02"
  6238. loc, _ := time.LoadLocation("Local")
  6239. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  6240. //查询该耗材是否已经出库
  6241. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  6242. if auto.ID == 0 {
  6243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  6244. return
  6245. }
  6246. }
  6247. }
  6248. if good.IsUser == 1 && good.IsWarehouse == 1 {
  6249. //查询开关是否开启
  6250. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  6251. //开关已经开启
  6252. if stockSetting.IsType == 1 {
  6253. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  6254. scheduleDateStart := theTime.Format("2006-01-02")
  6255. timeLayout3 := "2006-01-02"
  6256. loc, _ := time.LoadLocation("Local")
  6257. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  6258. //查询该耗材是否已经出库
  6259. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  6260. if auto.ID == 0 {
  6261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  6262. return
  6263. }
  6264. }
  6265. }
  6266. }
  6267. if project.ExecutionState == 1 {
  6268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  6269. return
  6270. }
  6271. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  6272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  6273. return
  6274. }
  6275. project.ExecutionState = 1
  6276. project.ExecutionStaff = adminInfo.AdminUser.Id
  6277. project.ExecutionTime = theTime.Unix()
  6278. if team_id == 0 {
  6279. // 查询信息规挡的设置天数
  6280. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6281. if infor.ID > 0 {
  6282. var cha_time int64
  6283. timeNowStr := time.Now().Format("2006-01-02")
  6284. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6285. //今日的日期减去设置的日期
  6286. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6287. if cha_time >= project.RecordDate {
  6288. //查询审核是否允许
  6289. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6290. //申请状态不允许的情况 拒绝修改
  6291. if infor.ApplicationStatus != 1 {
  6292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6293. return
  6294. }
  6295. }
  6296. }
  6297. err := service.SaveHisProject(&project)
  6298. if err == nil {
  6299. c.ServeSuccessJSON(map[string]interface{}{
  6300. "project": project,
  6301. })
  6302. } else {
  6303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6304. return
  6305. }
  6306. } else {
  6307. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  6308. // 查询信息规挡的设置天数
  6309. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6310. if infor.ID > 0 {
  6311. var cha_time int64
  6312. timeNowStr := time.Now().Format("2006-01-02")
  6313. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6314. //今日的日期减去设置的日期
  6315. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6316. if cha_time >= project.RecordDate {
  6317. //查询审核是否允许
  6318. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6319. //申请状态不允许的情况 拒绝修改
  6320. if infor.ApplicationStatus != 1 {
  6321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6322. return
  6323. }
  6324. }
  6325. }
  6326. err := service.SaveHisProject(&project)
  6327. if err == nil {
  6328. c.ServeSuccessJSON(map[string]interface{}{
  6329. "project": project,
  6330. })
  6331. } else {
  6332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6333. return
  6334. }
  6335. } else {
  6336. // 查询信息规挡的设置天数
  6337. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6338. if infor.ID > 0 {
  6339. var cha_time int64
  6340. timeNowStr := time.Now().Format("2006-01-02")
  6341. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6342. //今日的日期减去设置的日期
  6343. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6344. if cha_time >= project.RecordDate {
  6345. //查询审核是否允许
  6346. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6347. //申请状态不允许的情况 拒绝修改
  6348. if infor.ApplicationStatus != 1 {
  6349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6350. return
  6351. }
  6352. }
  6353. }
  6354. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  6355. var ids []int64
  6356. for _, items := range ps {
  6357. ids = append(ids, items.ID)
  6358. }
  6359. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  6360. if err == nil {
  6361. c.ServeSuccessJSON(map[string]interface{}{
  6362. "project": project,
  6363. })
  6364. } else {
  6365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6366. return
  6367. }
  6368. }
  6369. }
  6370. }
  6371. func (c *PatientApiController) CheckProject() {
  6372. adminInfo := c.GetMobileAdminUserInfo()
  6373. project_id, _ := c.GetInt64("project_id")
  6374. team_id, _ := c.GetInt64("team_id")
  6375. is_check_team, _ := c.GetInt64("is_check_team")
  6376. record_date, _ := c.GetInt64("record_date")
  6377. patient_id, _ := c.GetInt64("patient_id")
  6378. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  6379. if project.CheckState == 1 {
  6380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  6381. return
  6382. }
  6383. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  6384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  6385. return
  6386. }
  6387. project.Checker = adminInfo.AdminUser.Id
  6388. project.CheckTime = time.Now().Unix()
  6389. project.CheckState = 1
  6390. if team_id == 0 {
  6391. // 查询信息规挡的设置天数
  6392. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6393. if infor.ID > 0 {
  6394. var cha_time int64
  6395. timeNowStr := time.Now().Format("2006-01-02")
  6396. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6397. //今日的日期减去设置的日期
  6398. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6399. if cha_time >= project.RecordDate {
  6400. //查询审核是否允许
  6401. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6402. //申请状态不允许的情况 拒绝修改
  6403. if infor.ApplicationStatus != 1 {
  6404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6405. return
  6406. }
  6407. }
  6408. }
  6409. err := service.SaveHisProject(&project)
  6410. if err == nil {
  6411. c.ServeSuccessJSON(map[string]interface{}{
  6412. "msg": "ok",
  6413. "project": project,
  6414. })
  6415. } else {
  6416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6417. return
  6418. }
  6419. } else {
  6420. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  6421. // 查询信息规挡的设置天数
  6422. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6423. if infor.ID > 0 {
  6424. var cha_time int64
  6425. timeNowStr := time.Now().Format("2006-01-02")
  6426. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6427. //今日的日期减去设置的日期
  6428. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6429. if cha_time >= project.RecordDate {
  6430. //查询审核是否允许
  6431. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6432. //申请状态不允许的情况 拒绝修改
  6433. if infor.ApplicationStatus != 1 {
  6434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6435. return
  6436. }
  6437. }
  6438. }
  6439. err := service.SaveHisProject(&project)
  6440. if err == nil {
  6441. c.ServeSuccessJSON(map[string]interface{}{
  6442. "msg": "ok",
  6443. "project": project,
  6444. })
  6445. } else {
  6446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6447. return
  6448. }
  6449. } else {
  6450. // 查询信息规挡的设置天数
  6451. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6452. if infor.ID > 0 {
  6453. var cha_time int64
  6454. timeNowStr := time.Now().Format("2006-01-02")
  6455. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6456. //今日的日期减去设置的日期
  6457. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6458. if cha_time >= project.RecordDate {
  6459. //查询审核是否允许
  6460. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6461. //申请状态不允许的情况 拒绝修改
  6462. if infor.ApplicationStatus != 1 {
  6463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6464. return
  6465. }
  6466. }
  6467. }
  6468. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  6469. var ids []int64
  6470. for _, items := range ps {
  6471. ids = append(ids, items.ID)
  6472. }
  6473. err := service.UpdateTeamProjectCheckStatus(ids, patient_id, record_date, adminInfo.Org.Id, adminInfo.AdminUser.Id, time.Now().Unix())
  6474. if err == nil {
  6475. c.ServeSuccessJSON(map[string]interface{}{
  6476. "project": project,
  6477. })
  6478. } else {
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6480. return
  6481. }
  6482. }
  6483. }
  6484. }