patient_api_controller.go 265KB

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