patient_api_controller.go 232KB

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