patient_api_controller.go 270KB

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