patient_api_controller.go 249KB

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