patient_api_controller.go 238KB

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