123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529 |
- package controllers
-
- import (
- "encoding/json"
- "math"
- "math/rand"
- "reflect"
- "regexp"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/jinzhu/gorm"
- "github.com/mozillazg/go-pinyin"
-
- "fmt"
-
- "github.com/astaxie/beego"
- )
-
- type PatientApiController struct {
- BaseAuthAPIController
- }
-
- func PatientApiRegistRouters() {
- beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
- beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
- beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
- beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
- beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
- beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
- beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
- beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
- beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
- beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
- beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
- // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
-
- beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
- beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
-
- beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
- beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
- beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
- beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
- beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
- beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
- beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
- beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
- beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
- beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
- beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
- beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
-
- beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
- beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
- beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
- beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
-
- beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
-
- beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
-
- beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
-
- beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
- beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
-
- beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
-
- beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
-
- beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
-
- beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
-
- //长期医嘱新接口
- beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
- beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
-
- beego.Router("/api/patient/getexportlist", &PatientApiController{}, "Get:GetExportList")
-
- beego.Router("/api/patient/savefalloutbedprint", &PatientApiController{}, "Post:SaveFallOutBedPrint")
-
- beego.Router("/api/patient/getfalloutbedprintlist", &PatientApiController{}, "Get:GetFallOutBedPrintList")
-
- beego.Router("/api/patient/savefilterinformed", &PatientApiController{}, "Post:SaveFilterInformed")
-
- beego.Router("/api/patient/getfilterinformed", &PatientApiController{}, "Get:GetFilterInformed")
-
- beego.Router("/api/patient/saveprofundainformed", &PatientApiController{}, "Post:SaveProfundaInformed")
-
- beego.Router("/api/patient/getprofundainformed", &PatientApiController{}, "Get:GetProfundaInformed")
-
- beego.Router("/api/patient/arterovenous", &PatientApiController{}, "Post:SaveArterOvenous")
-
- beego.Router("/api/patient/getarterovernous", &PatientApiController{}, "Get:GetArterOverNous")
-
- beego.Router("/api/patient/savehighrikinformed", &PatientApiController{}, "Post:SaveHighRikInformed")
-
- beego.Router("/api/patient/gethighriskinformed", &PatientApiController{}, "Get:GetHighRiskInformed")
-
- beego.Router("/api/patient/saveanticoagulation", &PatientApiController{}, "Post:SaveAnticoagulation")
-
- beego.Router("/api/patient/getanticoagulationInformed", &PatientApiController{}, "Get:GetAnticoagulationInformed")
-
- beego.Router("/api/patient/savecriticalinfomed", &PatientApiController{}, "Post:SaveCriticalInfomed")
-
- beego.Router("/api/patient/getcriticalinformed", &PatientApiController{}, "Get:GetCriticalInformed")
-
- beego.Router("/api/patient/savehemoperfusioninformed", &PatientApiController{}, "Post:SaveHemoperfusionInformed")
-
- beego.Router("/api/patient/gethemoperfusioninformed", &PatientApiController{}, "Get:GetHemoperfusionInformed")
-
- beego.Router("/api/patient/savebringinformed", &PatientApiController{}, "Post:SaveBringInformed")
-
- beego.Router("/api/patient/getinformedcontsent", &PatientApiController{}, "Get:GetInformedContsent")
-
- beego.Router("/api/patient/savecatheterization", &PatientApiController{}, "Post:SaveCatheterization")
-
- beego.Router("/api/patient/getcatheterization", &PatientApiController{}, "Get:GetCatheterization")
-
- beego.Router("/api/patient/savedialyzerInformed", &PatientApiController{}, "Post:SaveDialyzerInformed")
-
- beego.Router("/api/patient/getdialyzerinformed", &PatientApiController{}, "Get:GetDialyzerInformed")
-
- beego.Router("/api/patient/savetheapyinformed", &PatientApiController{}, "Post:SaveTheapyInformed")
-
- beego.Router("/api/patient/savetreamentplan", &PatientApiController{}, "Post:SaveTreatmentPlan")
-
- beego.Router("api/patient/gettherapyinformed", &PatientApiController{}, "Get:GetTherapyInformed")
-
- beego.Router("/api/patient/savemedicalhistory", &PatientApiController{}, "Post:SaveMedicalHistory")
-
- beego.Router("/api/patient/savepatientcritaicalinformed", &PatientApiController{}, "Post:SavePatientCritaicalInformed")
-
- beego.Router("/api/patient/getPatientCriticalList", &PatientApiController{}, "Get:GetPatientCriticalList")
-
- beego.Router("/api/patient/savepatientcriticalcalinformedone", &PatientApiController{}, "Post:SavePatientCriticalInformedOne")
-
- beego.Router("/api/patient/getpatientcriticalonelist", &PatientApiController{}, "Get:GetPatientCriticalOneList")
-
- beego.Router("/api/patient/deletesolution", &PatientApiController{}, "Get:DeleteSolution")
-
- beego.Router("/api/patient/gettreamentplan", &PatientApiController{}, "Get:GetTreatMentPlanList")
-
- beego.Router("/api/patient/getpatientbypatientid", &PatientApiController{}, "Get:GetPatientByPatientId")
-
- beego.Router("/api/patient/savepatientlapse", &PatientApiController{}, "Post:SavePatientLapse")
-
- beego.Router("/api/patient/getpatientlapsorecord", &PatientApiController{}, "Get:GetPatientLapsorecord")
-
- beego.Router("/api/patient/getpatientlapserecord", &DialysisApiController{}, "Get:GetPatientLapseRecord")
-
- beego.Router("/api/patient/updatepatientlapserecord", &DialysisApiController{}, "Post:UpdatePatientLapseRecord")
-
- beego.Router("/api/patient/deletepatientlapsorecord", &DialysisApiController{}, "Get:DeletePatientLapseRecord")
-
- beego.Router("/api/patient/getpatientlapeso", &DialysisApiController{}, "Get:GetPatientLapseList")
-
- beego.Router("/api/patient/adddeathsummary", &DialysisApiController{}, "Post:AddDeathSummary")
-
- beego.Router("/api/patient/getpatientdeathsummary", &DialysisApiController{}, "Get:GetPatientDeathSummary")
-
- beego.Router("/api/patient/deletepatientdeathsummary", &DialysisApiController{}, "Get:DeletePatientDeathSummary")
-
- beego.Router("/api/patient/createnewsickhistoryrecord", &PatientApiController{}, "Post:CreateNewSickHistoryRecord")
-
- beego.Router("/api/patient/getnewsickhistory", &PatientApiController{}, "Get:GetNewSickHistory")
-
- beego.Router("/api/patient/deletenewsickhistory", &PatientApiController{}, "Get:DeleteNewSickHistory")
-
- beego.Router("/api/patient/savesickhistorytemplate", &PatientApiController{}, "Post:SaveSickHistoryTemplate")
-
- beego.Router("/api/patient/getsickhistorytemplate", &PatientApiController{}, "Get:GetSickHistoryTemplate")
-
- beego.Router("/api/patient/modifysickhistorytemplate", &PatientApiController{}, "Post:ModifySickHistoryTemplate")
-
- beego.Router("/api/patient/deletesickhistorytemplate", &PatientApiController{}, "Get:DeleteSickHistoryTemplate")
-
- beego.Router("/api/patient/createnewcourseofdiseaserecord", &PatientApiController{}, "Post:CreateNewCourseOfDiaseaseRecord")
-
- beego.Router("/api/patient/getpatientcourseofdiseaseslist", &PatientApiController{}, "Get:GetPatientCoureseOfDiseasesList")
-
- beego.Router("/api/patient/deletenewcourseofdisease", &PatientApiController{}, "Get:DeleteNewCourseOfDisease")
-
- beego.Router("/api/patient/createnewcouresetemplate", &PatientApiController{}, "Post:CreateNewCourseTemplate")
-
- beego.Router("/api/patient/savepatientdeathrecord", &PatientApiController{}, "Post:SavePatientDeathRecord")
-
- beego.Router("/api/patient/getpatientdeathrecord", &PatientApiController{}, "Get:GetPatientDeathRecordOne")
-
- beego.Router("/api/patient/savecouresetemplatetitle", &PatientApiController{}, "Post:SaveCoureseTemplateTitle")
-
- beego.Router("/api/patient/getpatientcourseoftemplate", &PatientApiController{}, "Get:GetPatientCourseOfTemplate")
-
- beego.Router("/api/patient/savecourseofnewtemplate", &PatientApiController{}, "Post:SaveCourseOfNewTemplate")
-
- beego.Router("/api/patient/deletecourestempalte", &PatientApiController{}, "Get:DeleteCouseTemplate")
-
- }
- func (c *PatientApiController) GetExportList() {
- startTime := c.GetString("start_time")
- endTime := c.GetString("end_time")
- schedulType, _ := c.GetInt64("schedul_type", 0)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- adminUserInfo := c.GetAdminUserInfo()
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- theStartTIme = theTime.Unix()
- }
-
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- theEndtTIme = theTime.Unix()
- }
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
- schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
- fmt.Println("schedule23333333333333333", schedule)
- patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- "patientsList": patientsList,
- })
- return
- }
-
- // GetPatientsList 取患者列表
- func (c *PatientApiController) GetPatientsList() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- bindingState, _ := c.GetInt64("binding_state", 0)
- lapseto, _ := c.GetInt64("lapseto", 0)
- source, _ := c.GetInt64("source", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
- contagion, _ := c.GetInt64("contagion", 0)
- reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
- isscheduling, _ := c.GetInt64("isscheduling", 0)
- isprescription, _ := c.GetInt64("isprescription", 0)
- patientSoureType, _ := c.GetInt64("patientSoureType")
- patient_type, _ := c.GetInt64("patient_type")
- nurse, _ := c.GetInt64("nurse")
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var isStartTime bool
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- isStartTime = true
- theStartTIme = theTime.Unix()
- }
- var isEndTime bool
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- isEndTime = true
- theEndtTIme = theTime.Unix()
- }
-
- var patients []*models.Patients
- var total int64
- patients, total, err = service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime, patientSoureType, nurse, patient_type)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- })
- return
-
- }
-
- // GetPatientTotal
- func (c *PatientApiController) GetPatientTotal() {
- adminUserInfo := c.GetAdminUserInfo()
-
- total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientsAllList() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- if adminUserInfo.CurrentOrgId != 10702 {
- patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "patientsOne": patients,
- "total": total,
- })
- return
- } else {
- patients, total, _ := service.GetAllPatientListOne(adminUserInfo.CurrentOrgId)
- patientsOne, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "patientsOne": patientsOne,
- "total": total,
- })
- return
- }
-
- }
-
- // GenerateDialysisNo 生成透析号
- func (c *PatientApiController) GenerateDialysisNo() {
- adminUserInfo := c.GetAdminUserInfo()
-
- dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
- if dialysisNo == 0 {
- dialysisNo = 1
- } else {
- dialysisNo++
- }
- no := strconv.FormatInt(dialysisNo, 10)
-
- rep := 3 - len(no)
-
- if rep > 0 {
- no = strings.Repeat("0", rep) + no
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "no": no,
- })
- return
- }
-
- // CreatePatient 创建患者
- func (c *PatientApiController) CreatePatient() {
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- adminUserInfo := c.GetAdminUserInfo()
- //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
-
- //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //}
-
- var patient models.Patients
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
-
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
- return
- }
-
- patient.RemindCycle = remind_cycle
- patient.IsInfectious = is_infectious
- patient.RegistrarsId = adminUserInfo.AdminUser.Id
- patient.Status = 1
- patient.CreatedTime = time.Now().Unix()
- patient.UserOrgId = adminUserInfo.CurrentOrgId
- patient.UpdatedTime = time.Now().Unix()
- patient.BindingState = 2
- // patient.Lapseto = 1
-
- hans := patient.Name // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- patient.FirstLetter = firstLetter
-
- err := service.CreatePatient(&patient, contagions, diseases)
-
- fmt.Println("创建病人失败err")
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
- return
- }
-
- //获取老表的最后一条数据
- patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
- creater := adminUserInfo.AdminUser.Id
- record := models.XtPatientLaspseRecord{
- PatientId: patients.ID,
- RecordDate: time.Now().Unix(),
- LapseDate: time.Now().Unix(),
- LapseType: 1,
- LapseClass: 0,
- LapseReason: "",
- AdminUserId: creater,
- Remark: "",
- UserOrgId: adminUserInfo.CurrentOrgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: "转入",
- HisType: 0,
- HisZone: "",
- HisBed: "",
- }
- service.CreatePatientRecord(record)
-
- patientsNew := models.XtPatientsNew{
- UserOrgId: adminUserInfo.CurrentOrgId,
- UserId: 0,
- Avatar: patients.Avatar,
- PatientType: patients.PatientType,
- DialysisNo: patients.DialysisNo,
- AdmissionNumber: patients.AdmissionNumber,
- Source: patients.Source,
- Lapseto: patients.Lapseto,
- PartitionId: patients.PartitionId,
- BedId: patients.BedId,
- Name: patients.Name,
- Alias: patients.Alias,
- Gender: patients.Gender,
- MaritalStatus: patients.MaritalStatus,
- IdCardNo: patients.IdCardNo,
- Birthday: patients.Birthday,
- ReimbursementWayId: patients.ReimbursementWayId,
- HealthCareType: patients.HealthCareType,
- HealthCareNo: patients.HealthCareNo,
- HealthCareDueDate: patients.HealthCareDueDate,
- Height: patients.Height,
- BloodType: patients.BloodType,
- Rh: patients.Rh,
- HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
- EducationLevel: patients.EducationLevel,
- Profession: patients.Profession,
- Phone: patients.Phone,
- HomeTelephone: patients.HomeTelephone,
- RelativePhone: patients.RelativePhone,
- RelativeRelations: patients.RelativeRelations,
- HomeAddress: patients.HomeAddress,
- WorkUnit: patients.WorkUnit,
- UnitAddress: patients.UnitAddress,
- Children: patients.Children,
- ReceivingDate: patients.ReceivingDate,
- IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
- FirstDialysisDate: patients.FirstDialysisDate,
- FirstDialysisHospital: patients.FirstDialysisHospital,
- PredialysisCondition: patients.PredialysisCondition,
- PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
- PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
- InductionPeriod: patients.InductionPeriod,
- InitialDialysis: patients.InitialDialysis,
- TotalDialysis: patients.TotalDialysis,
- AttendingDoctorId: patients.AttendingDoctorId,
- HeadNurseId: patients.HeadNurseId,
- Evaluate: patients.Evaluate,
- Diagnose: patients.Diagnose,
- Remark: patients.Remark,
- RegistrarsId: patients.RegistrarsId,
- Registrars: patients.Registrars,
- QrCode: patients.QrCode,
- BindingState: patients.BindingState,
- PatientComplains: patients.PatientComplains,
- PresentHistory: patients.PresentHistory,
- PastHistory: patients.PresentHistory,
- Temperature: patients.Temperature,
- Pulse: patients.Pulse,
- Respiratory: patients.Respiratory,
- Sbp: patients.SBP,
- Dbp: patients.DBP,
- Status: patients.Status,
- CreatedTime: patients.CreatedTime,
- UpdatedTime: patients.UpdatedTime,
- Nation: patients.Nation,
- NativePlace: patients.NativePlace,
- Age: patients.Age,
- InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
- IsInfectious: patients.IsInfectious,
- RemindCycle: patients.RemindCycle,
- ResponseResult: patients.ResponseResult,
- IsOpenRemind: patients.IsOpenRemind,
- FirstTreatmentDate: patients.FirstTreatmentDate,
- DialysisAge: patients.DialysisAge,
- ExpenseKind: patients.ExpenseKind,
- TellPhone: patients.TellPhone,
- ContactName: patients.ContactName,
- BloodPatients: 1,
- SlowPatients: 0,
- MemberPatients: 0,
- EcommerPatients: "",
- BloodId: patients.ID,
- SlowId: 0,
- MemberId: 0,
- MemberFistdate: 0,
- MemberPatienttype: 0,
- MemberTreatement: 0,
- EquitmentId: "",
- UserSysBeforeCount: patient.UserSysBeforeCount,
- TrobleShoot: patient.TrobleShoot,
- TreatmentPlan: patient.TreatmentPlan,
- Doctor: patient.Doctor,
- RecordNumber: patient.RecordNumber,
- PatientSource: patient.PatientSource,
- PatientEndTime: patient.PatientEndTime,
- PatientStartTime: patient.PatientStartTime,
- InfectiousRemark: patient.InfectiousRemark,
- AllergicHistory: patient.AllergicHistory,
- PatientAddress: patient.PatientAddress,
- PrintDate: patient.PrintDate,
- FamalityRecord: patient.FamalityRecord,
- }
- patientsNew.FirstLetter = firstLetter
-
- err = service.CreatePatientsNew(&patientsNew)
- fmt.Print("创建失败", err)
-
- allergic := models.XtPatientAllergic{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient.ID,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.PatientSource,
- PatientAddress: patient.PatientAddress,
- Remake: patient.Remark,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
-
- if len(patient.PatientAddress) > 0 {
- service.CreateAllergic(allergic)
- }
-
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
-
- }
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.SAdd("sgj_patient:new_user_set", patient.UserId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // EditPatient 修改
- func (c *PatientApiController) EditPatient() {
- id, _ := c.GetInt64("id", 0)
-
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- patient.UpdatedTime = time.Now().Unix()
- patient.IsInfectious = is_infectious
- patient.RemindCycle = remind_cycle
- err := service.UpdatePatient(&patient, contagions, diseases)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- ////更新转归状态
- //lapseto := models.PatientLapseto{
- // LapsetoType: patient.Lapseto,
- // LapsetoTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- //}
- //err = service.UpdatePatientLapseto(patient.ID, lapseto)
- //fmt.Println("更新转归失败", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- patientsNew := models.XtPatientsNew{
- UserOrgId: patient.UserOrgId,
- UserId: patient.UserId,
- Avatar: patient.Avatar,
- PatientType: patient.PatientType,
- DialysisNo: patient.DialysisNo,
- AdmissionNumber: patient.AdmissionNumber,
- Source: patient.Source,
- PartitionId: patient.PartitionId,
- BedId: patient.BedId,
- Name: patient.Name,
- Alias: patient.Alias,
- Gender: patient.Gender,
- MaritalStatus: patient.MaritalStatus,
- IdCardNo: patient.IdCardNo,
- Birthday: patient.Birthday,
- ReimbursementWayId: patient.ReimbursementWayId,
- HealthCareType: patient.HealthCareType,
- HealthCareNo: patient.HealthCareNo,
- HealthCareDueDate: patient.HealthCareDueDate,
- Height: patient.Height,
- BloodType: patient.BloodType,
- Rh: patient.Rh,
- HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
- EducationLevel: patient.EducationLevel,
- Profession: patient.Profession,
- Phone: patient.Phone,
- HomeTelephone: patient.HomeTelephone,
- RelativePhone: patient.RelativePhone,
- RelativeRelations: patient.RelativeRelations,
- HomeAddress: patient.HomeAddress,
- WorkUnit: patient.WorkUnit,
- UnitAddress: patient.UnitAddress,
- Children: patient.Children,
- ReceivingDate: patient.ReceivingDate,
- IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
- FirstDialysisDate: patient.FirstDialysisDate,
- FirstDialysisHospital: patient.FirstDialysisHospital,
- PredialysisCondition: patient.PredialysisCondition,
- PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
- InductionPeriod: patient.InductionPeriod,
- InitialDialysis: patient.InitialDialysis,
- TotalDialysis: patient.TotalDialysis,
- AttendingDoctorId: patient.AttendingDoctorId,
- HeadNurseId: patient.HeadNurseId,
- Evaluate: patient.Evaluate,
- Diagnose: patient.Diagnose,
- Remark: patient.Remark,
- RegistrarsId: patient.RegistrarsId,
- Registrars: patient.Registrars,
- QrCode: patient.QrCode,
- BindingState: patient.BindingState,
- PatientComplains: patient.PatientComplains,
- PresentHistory: patient.PresentHistory,
- PastHistory: patient.PastHistory,
- Temperature: patient.Temperature,
- Pulse: patient.Pulse,
- Respiratory: patient.Respiratory,
- Sbp: patient.SBP,
- Dbp: patient.DBP,
- Nation: patient.Nation,
- NativePlace: patient.NativePlace,
- Age: patient.Age,
- InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
- IsInfectious: patient.IsInfectious,
- RemindCycle: patient.RemindCycle,
- ResponseResult: patient.ResponseResult,
- IsOpenRemind: patient.IsOpenRemind,
- FirstTreatmentDate: patient.FirstTreatmentDate,
- DialysisAge: patient.DialysisAge,
- ExpenseKind: patient.ExpenseKind,
- TellPhone: patient.TellPhone,
- ContactName: patient.ContactName,
- UpdatedTime: time.Now().Unix(),
- BloodPatients: 1,
- Lapseto: patient.Lapseto,
- TrobleShoot: patient.TrobleShoot,
- SchRemark: patient.SchRemark,
- TreatmentPlan: patient.TreatmentPlan,
- RecordNumber: patient.RecordNumber,
- PatientSource: patient.PatientSource,
- PatientStartTime: patient.PatientStartTime,
- PatientEndTime: patient.PatientEndTime,
- InfectiousRemark: patient.InfectiousRemark,
- AllergicHistory: patient.AllergicHistory,
- PatientAddress: patient.PatientAddress,
- PrintDate: patient.PrintDate,
- FamalityRecord: patient.FamalityRecord,
- }
- // //更新病人ID获取新表病人ID
- err = service.UpdatepatientTwo(&patientsNew, id)
-
- allergic := models.XtPatientAllergic{
- PatientId: patient.ID,
- UserOrgId: adminUserInfo.CurrentOrgId,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.PatientSource,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Remake: patient.Remark,
- PatientAddress: patient.PatientAddress,
- }
- if len(patient.PatientAddress) > 0 {
- service.CreateAllergic(allergic)
- }
-
- nowTimeUinx := time.Now()
- today := nowTimeUinx.Format("2006-01-02")
-
- redis := service.RedisClient()
- defer redis.Close()
- key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(key, "", time.Second*60*60*18)
-
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
- redis.Set(keyOne, "", time.Second*60*60*18)
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
-
- }
-
- func (c *PatientApiController) EditLapseto() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- start_time := c.GetString("start_time")
-
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- patient_address := c.GetString("patient_address")
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
-
- if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
- utils.ErrorLog("lapseto_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- lapsetoType := int64(patientBody["lapseto_type"].(float64))
-
- lapseto.LapsetoType = lapsetoType
-
- if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
- utils.ErrorLog("lapseto_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
- return
- }
- lapsetoTime, _ := patientBody["lapseto_time"].(string)
-
- //if len(lapsetoTime) == 0 {
- // utils.ErrorLog("len(lapsetoTime) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
-
- out_reason, _ := patientBody["out_reason"].(string)
-
- //if len(out_reason) == 0 {
- // utils.ErrorLog("len(out_reason) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
-
- lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
-
- //if err != nil {
- // utils.ErrorLog("lapsetoTimeUnix")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
- lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
- lapseto.UpdatedTime = time.Now().Unix()
- lapseto.CreatedTime = time.Now().Unix()
- lapseto.Status = 1
- patient.Lapseto = lapseto.LapsetoType
- patient.OutReason = out_reason
- patient.DeathTime = lapsetoTimeUnix.Unix()
-
- patient.PatientStartTime = startTime
- patient.PatientEndTime = endTime
- patient.PatientAddress = patient_address
-
- //if patient.Lapseto == 1 {
- // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
- // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // }
- //}
-
- err = service.EditPatientLapseto(&patient, &lapseto)
-
- if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
- fmt.Println("lapsetoTimeUnix.Unix()", lapsetoTimeUnix.Unix())
- if adminUserInfo.CurrentOrgId == 10340 {
- service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
- service.UpdateScheduleItemByPatientId(id)
- } else {
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- service.UpdateScheduleByDeathTime(id, timenow)
- service.UpdateScheduleItemByPatientId(id)
- }
- }
-
- allergic := models.XtPatientAllergic{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient.ID,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.Lapseto,
- PatientAddress: patient.PatientAddress,
- Remake: patient.Remark,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
- allergic.StartTime = lapseto.LapsetoTime
- allergic.EndTime = lapseto.LapsetoTime
- }
-
- service.CreateAllergic(allergic)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) GetPatient() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
-
- infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
- diseases := service.GetPatientDiseases(patient.ID)
- contagions := service.GetPatientContagions(patient.ID)
- patientVascularAccessOne, _ := service.GetPatientVascularAccessOne(patient.ID)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "diseases": diseases,
- "contagions": contagions,
- "infections": infections,
- "patientVascularAccessOne": patientVascularAccessOne,
- })
- return
- }
-
- func (c *PatientApiController) CreateDialysisSolution() {
-
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var solution models.DialysisSolution
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
- //if thisSolution.ID > 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
- // return
- //}
-
- solution.RegistrarsId = adminUserInfo.AdminUser.Id
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.Status = 1
- solution.PatientId = id
- solution.CreatedTime = time.Now().Unix()
- solution.UserOrgId = adminUserInfo.CurrentOrgId
- solution.UpdatedTime = time.Now().Unix()
- solution.SubName = ""
- solution.ParentId = 0
- solution.SolutionStatus = 1
-
- //records, _ := service.GetAllSchedules()
-
- schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
- for _, sch := range schs {
- var DialysisMachineName string
- if len(solution.DialysisDialyszers) > 0 {
- DialysisMachineName = solution.DialysisDialyszers
- }
- if len(solution.DialyzerPerfusionApparatus) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
- }
-
- if len(solution.DialysisIrrigation) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
- }
-
- if len(solution.DialysisStrainer) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
- }
- sch.DialysisMachineName = DialysisMachineName
- service.UpdateSch(sch)
- }
-
- err := service.CreatePatientDialysisSolution(&solution)
-
- //获取最新1条
- dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
-
- //更新状态
- service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) UpdateDialysisSolution() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
-
- err := service.UpdatePatientDialysisSolution(&solution)
-
- nowTimeUinx := time.Now()
- today := nowTimeUinx.Format("2006-01-02")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- todayTime, err := time.ParseInLocation(timeLayout, today, loc)
-
- if adminUserInfo.CurrentOrgId == 9538 || adminUserInfo.CurrentOrgId == 10164 {
- prescription := models.DialysisPrescription{
- Dialyzer: solution.Dialyzer,
- Anticoagulant: solution.Anticoagulant,
- AnticoagulantShouji: solution.AnticoagulantShouji,
- AnticoagulantWeichi: solution.AnticoagulantWeichi,
- AnticoagulantZongliang: solution.AnticoagulantZongliang,
- ModeId: solution.ModeId,
- DialysisDurationHour: solution.DialysisDurationHour,
- Kalium: solution.Kalium,
- Sodium: solution.Sodium,
- Calcium: solution.Calcium,
- TargetUltrafiltration: solution.TargetUltrafiltration,
- DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
- BloodAccess: solution.BloodAccess,
- DialysateFlow: solution.DialysateFlow,
- DialysateTemperature: solution.DialysateTemperature,
- DialysisIrrigation: solution.DialysisIrrigation,
- DialysisDialyszers: solution.DialysisDialyszers,
- PlasmaSeparator: solution.PlasmaSeparator,
- BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
- OxygenUptake: solution.OxygenUptake,
- OxygenFlow: solution.OxygenFlow,
- OxygenTime: solution.OxygenTime,
- MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
- Amylaceum: solution.Amylaceum,
- DialysisStrainer: solution.DialysisStrainer,
- Chaptalization: solution.Chaptalization,
- BloodAccessPartId: solution.BloodAccessPartId,
- }
- service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
- }
-
- schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
- for _, sch := range schs {
- var DialysisMachineName string
- if len(solution.DialysisDialyszers) > 0 {
- DialysisMachineName = solution.DialysisDialyszers
- }
- if len(solution.DialyzerPerfusionApparatus) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
- }
-
- if len(solution.DialysisIrrigation) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
- }
-
- if len(solution.DialysisStrainer) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
- }
- sch.DialysisMachineName = DialysisMachineName
- service.UpdateSch(sch)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) UpdateDialysisSolutionDetail() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.AffirmState = 1
-
- err := service.UpdatePatientDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientDialysisSolutionList() {
- id, _ := c.GetInt64("id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if id <= 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": nil,
- })
- return
- }
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
- stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solutions,
- "total": total,
- "stockType": stockType,
- })
- return
- }
- func (c *PatientApiController) DeleteDialysisSolution() {
-
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- if solution.UseState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.Status = 0
-
- err := service.DeleteSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // GetDryWeights 取患者干体重调整铺
- func (c *PatientApiController) GetDryWeights() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "weights": weights,
- "total": total,
- })
- return
-
- }
-
- func (c *PatientApiController) CreateDryWeights() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var theWeight models.DryWeightAdjust
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
- theWeight.Weight = weight
-
- // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // doctor := int64(dataBody["doctor"].(float64))
- // theWeight.Doctor = doctor
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- theWeight.Remark = remark
- }
-
- theWeight.CreatedTime = time.Now().Unix()
- theWeight.UpdatedTime = time.Now().Unix()
- theWeight.Status = 1
- theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
- theWeight.UserOrgId = adminUserInfo.CurrentOrgId
- theWeight.PatientId = patient
- theWeight.Doctor = adminUserInfo.AdminUser.Id
-
- old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
- if old.ID > 0 {
- theWeight.AdjustedValue = theWeight.Weight - old.Weight
- }
-
- err = service.CreateDryWeightAdjust(&theWeight)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "weight": theWeight,
- })
- return
- }
-
- func (c *PatientApiController) CreateGroupAdvice() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var patientInfo models.Patients
- patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
- utils.ErrorLog("advice_type != 1&&2")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
-
- time_arr := strings.Split(startTime2, " ")
-
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
-
- Remark = remark
- }
- var advices []*models.GroupAdvice
- if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
- utils.ErrorLog("adviceNames")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["adviceNames"].([]interface{})
- for _, adviceNameMap := range adviceNames {
-
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patientInfo.ID
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
-
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: advice.RecordDate,
- Sourse: 1,
- PatientId: patient,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
-
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
-
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- singleDose := adviceNameM["single_dose"].(float64)
- advice.SingleDose = singleDose
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
- tmp := adviceNameM["single_dose_unit"].(float64)
- singleDoseUnit := service.TypeConversion(tmp)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- prescribingNumber := adviceNameM["prescribing_number"].(float64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
- way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
- advice.Way = int64(way)
- }
- if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
- way := int64(adviceNameM["way"].(float64))
- advice.Way = way
- }
-
- if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
- drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
- advice.DrugId = int64(drug_id)
- }
- if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
- drug_id := int64(adviceNameM["drug_id"].(float64))
- advice.DrugId = drug_id
- }
-
- if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
-
- remark, _ := adviceNameM["remark"].(string)
-
- advice.Remark = remark
-
- if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
- if advice.PrescribingNumber == 0 {
- advice.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
- fmt.Println("chek", check)
- if check.ID > 0 {
- advice.Checker = check.Modifier
- advice.CheckState = 1
- advice.CheckTime = time.Now().Unix()
- }
- }
- if adviceType == 1 {
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
- week_day, _ := adviceNameM["week_days"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
- push_start_time, _ := adviceNameM["push_start_time"].(string)
- var startTime int64
- if len(push_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- advice.PushStartTime = startTime
- }
-
- }
-
- //针对康桥
- if adminUserInfo.CurrentOrgId == 10702 {
- if adviceType == 3 {
- adviceType = 2
- }
-
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
- children := adviceNameM["children"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.CurrentOrgId
- child.PatientId = patientInfo.ID
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
- child.IsSettle = 2
-
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
- childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
- child.SingleDose = childSingleDose
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
- childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
- child.PrescribingNumber = childPrescribingNumber
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
- drug_id := int64(childMap["drug_id"].(float64))
- child.DrugId = drug_id
- }
-
- if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
- way := int64(childMap["way"].(float64))
- child.Way = way
- }
-
- if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(childMap["drug_name_id"].(float64))
- child.DrugNameId = drug_name_id
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
-
- if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
- if child.PrescribingNumber == 0 {
- child.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
-
- if check.ID > 0 {
- child.Checker = check.Modifier
- child.CheckState = 1
- child.CheckTime = time.Now().Unix()
- }
- }
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
-
- for _, item := range advices {
- //记录日志
- byterequest, _ := json.Marshal(item)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电导端批量插入医嘱",
- RecordDate: item.AdviceDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
- }
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- return
- }
-
- func (c *PatientApiController) CreateDoctorAdvice() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- var advice models.DoctorAdvice
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if advice.ParentId > 0 {
-
- old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
- if old.ID == 0 || old.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
-
- if old.StopState == 1 || old.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- if old.ParentId > 0 {
- advice.ParentId = old.ParentId
- }
- advice.StartTime = old.StartTime
- advice.AdviceDoctor = old.AdviceDoctor
- advice.DeliveryWay = old.DeliveryWay
- advice.ExecutionFrequency = old.ExecutionFrequency
- advice.GroupNo = old.GroupNo
-
- }
-
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
- if advice.PrescribingNumber == 0 {
- advice.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
-
- if check.ID > 0 {
- advice.Checker = check.Modifier
- advice.CheckState = 1
- advice.CheckTime = time.Now().Unix()
- }
- }
- err := service.CreateDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑新增医嘱",
- RecordDate: advice.RecordDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
-
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: advice.AdviceDate,
- Sourse: 1,
- PatientId: patient,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- executionTime := c.GetString("execution_time")
-
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
- // checker := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- //查询自动扣减是否开启
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- //查询已经执行的医嘱
- advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
-
- if drugStockConfig.IsOpen == 1 {
- for _, item := range advicelist {
- medical, _ := service.GetBaseDrugMedical(advice.DrugId)
- //查询这个患者这个患者这个药已经出库的所有数量
- advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- var total_count int64
- var drug_count int64
- for _, it := range advicelist {
- if it.PrescribingNumberUnit == medical.MaxUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber * medical.MinNumber
- }
- if it.PrescribingNumberUnit == medical.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber
- }
-
- }
-
- for _, its := range drugoutlist {
- if its.CountUnit == medical.MaxUnit {
- drug_count += its.Count * medical.MinNumber
- }
- if its.CountUnit == medical.MinUnit {
- drug_count += its.Count
- }
- }
- if total_count == drug_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- var total int64
- var prescribing_number_total int64
-
- //查询默认出库仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
-
- //查询该药品在默认仓库是否有库存
- list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
-
- if medical.MinUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
-
- prescribing_number_total = count
-
- }
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
-
- }
- if pharmacyConfig.IsOpen != 1 {
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- }
-
- }
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecDoctorAdvice() {
-
- origin, _ := c.GetInt64("origin", 0)
-
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- executionTime := c.GetString("execution_time")
-
- if origin != 2 {
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
- var prescribing_number_total_one int64
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total_one = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total_one = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total_one = count
- }
-
- //库存不足
- if prescribing_number_total_one > selfDrugStockCount.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- }
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- if advice.ParentId > 0 {
- err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- } else {
- err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
-
- //自备药信息
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- if drugStockConfig.IsOpen == 1 {
- var total int64
- var prescribing_number_total int64
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse != 1 {
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
- advice.ExecutionState = 2
- advice.ExecutionStaff = 0
- advice.ExecutionTime = 0
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
- advice.ExecutionState = 2
- advice.ExecutionStaff = 0
- advice.ExecutionTime = 0
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- if prescribing_number_total <= total {
-
- //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
-
- adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
-
- if adviceSetting.IsAdviceOpen == 1 {
- //查询是否出库按钮开启
- prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if prescriptionConfig.IsOpen == 1 {
-
- if medical.IsUse == 2 {
- //是通过药房发药
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- //执行出库
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
- //执行出库
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
-
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- } else {
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
-
- } else {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- //是通过药房发药
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //更新字典里面的库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
- }
- }
- }
-
- //自备药
- selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpen.IsOpen == 1 {
-
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
-
- if selfBasedrug.IsSelfDrug == 1 {
-
- //查询是否有库存
- info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
-
- if len(info) > 0 {
- var total_count int64
- var prescribing_number_total int64
- for _, item := range info {
- if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if prescribing_number_total > total_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
- //出库
- if prescribing_number_total <= total_count {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: advice.AdviceDate,
- Type: 0,
- PatientId: advice.PatientId,
- IsCheck: 1,
- IsSys: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
-
- //查询今日是否有出库数据
- lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutId: lastWarehouseOutOne.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: advice.DrugId,
- Count: prescribing_number_total,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: advice.AdviceDate,
- Mtime: advice.AdviceDate,
- Remark: "",
- OrgId: advice.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: selfBasedrug.MinUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: advice.AdviceDate,
- PatientId: advice.PatientId,
- AdviceId: advice.ID,
- ClassType: "",
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- for _, it := range warehousingOutInfo {
-
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
- }
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
-
- }
-
- }
-
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
-
- if item.Way == 2 {
- if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
- if item.ExecutionState == 1 {
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- //插入自备药出库单
- outStock := models.XtSelfOutStock{
- DrugName: item.AdviceName,
- DrugNameId: item.DrugId,
- DrugSpec: item.AdviceDesc,
- OutstoreNumber: count,
- AdminUserId: adminUserInfo.AdminUser.Id,
- StorckTime: item.RecordDate,
- UserOrgId: adminUserInfo.CurrentOrgId,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- PatientId: item.PatientId,
- ExitMode: 2,
- MedicId: item.DrugId,
- StockOutNumber: warehousing_out_order,
- }
- service.CreateOutStock(&outStock)
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.HisDoctorAdviceInfo{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- if advice.ParentId > 0 {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行His医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- } else {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行His医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品自动出库开关管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
-
- if drugStockConfig.IsOpen == 1 {
- //查询已经执行的医嘱
- advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- medical, _ := service.GetBaseDrugMedical(advice.DrugId)
-
- var total int64
- var prescribing_number_total int64
- //药品保存处方出库
- config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
- if config.IsOpen != 1 {
- //查询默认出库仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
-
- //查询该药品在默认仓库是否有库存
- list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
-
- if medical.MinUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
-
- prescribing_number_total = count
-
- }
-
- if medical.IsUse == 1 {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端零用药品",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse != 1 {
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端药品库存不足",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
-
- if prescribing_number_total > total {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端出库数量大于总库存",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
-
- if medical.IsUse == 2 {
- if config.IsOpen != 1 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- // 开始主事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- creater := c.GetAdminUserInfo().AdminUser.Id
- outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
- var out_count int64
- if len(outListExport) > 0 {
- for _, item := range outListExport {
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
-
- }
- }
-
- newadviceInfo := &models.HisDoctorAdviceInfo{
- ID: item.ID,
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- HisPatientId: item.HisPatientId,
- AdviceType: item.AdviceType,
- AdviceDate: item.AdviceDate,
- StartTime: item.StartTime,
- AdviceName: item.AdviceName,
- AdviceDesc: item.AdviceDesc,
- ReminderDate: item.ReminderDate,
- SingleDose: item.SingleDose,
- SingleDoseUnit: item.SingleDoseUnit,
- PrescribingNumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- AdviceDoctor: item.AdviceDoctor,
- Status: item.Status,
- CreatedTime: item.CreatedTime,
- UpdatedTime: item.UpdatedTime,
- AdviceAffirm: item.AdviceAffirm,
- Remark: item.Remark,
- StopTime: item.StopTime,
- StopReason: item.StopReason,
- StopDoctor: item.StopDoctor,
- StopState: item.StopState,
- ParentId: item.ParentId,
- ExecutionTime: item.ExecutionTime,
- ExecutionStaff: item.ExecutionStaff,
- ExecutionState: item.ExecutionState,
- Checker: item.Checker,
- RecordDate: item.RecordDate,
- DialysisOrderId: item.DialysisOrderId,
- CheckTime: item.CheckTime,
- CheckState: item.CheckState,
- DrugSpec: item.DrugSpec,
- DrugSpecUnit: item.DrugSpecUnit,
- Groupno: item.Groupno,
- RemindType: item.RemindType,
- FrequencyType: item.FrequencyType,
- DayCount: item.DayCount,
- WeekDay: item.WeekDay,
- TemplateId: item.TemplateId,
- Modifier: item.Modifier,
- DrugId: item.DrugId,
- Price: item.Price,
- PrescriptionId: item.PrescriptionId,
- MedListCodg: item.MedListCodg,
- FeedetlSn: item.FeedetlSn,
- Day: item.DayCount,
- ChildDoctorAdvice: nil,
- Drug: models.Drug{},
- Diagnosis: item.Diagnosis,
- Way: item.Way,
- HospApprFlag: item.HospApprFlag,
- LmtUsedFlag: item.LmtUsedFlag,
- HisOrderInfo: models.HisOrderInfo{},
- IsMedicine: item.IsMedicine,
- ExecutionFrequencyId: item.ExecutionFrequencyId,
- Child: nil,
- IsSettle: item.IsSettle,
- IsMobile: item.IsMobile,
- IsSelfDrug: item.IsSelfDrug,
- DrugWayCount: item.DrugWayCount,
- }
-
- //如果当前医嘱数量大于历史出库数据则需要出库
- if prescribing_number_total > out_count {
-
- //按最小单位出库
- var cha_count = prescribing_number_total - out_count
-
- item.PrescribingNumber = float64(cha_count)
- item.PrescribingNumberUnit = medical.MinUnit
-
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
-
- }
-
- //如果当前医嘱数量小于历史出库数据则需要退库
- if prescribing_number_total < out_count {
- var cha_count = out_count - prescribing_number_total
- drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
- service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
- service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
-
- }
-
- if prescribing_number_total == out_count {
- if out_count == 0 {
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
- }
-
- }
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
-
- if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(item.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "6",
- "advice": advice,
- })
- return
- }
- }
-
- tx.Commit()
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- // 开始主事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- creater := c.GetAdminUserInfo().AdminUser.Id
- outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
- var out_count int64
- if len(outListExport) > 0 {
- for _, item := range outListExport {
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
-
- }
- }
-
- newadviceInfo := &models.HisDoctorAdviceInfo{
- ID: item.ID,
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- HisPatientId: item.HisPatientId,
- AdviceType: item.AdviceType,
- AdviceDate: item.AdviceDate,
- StartTime: item.StartTime,
- AdviceName: item.AdviceName,
- AdviceDesc: item.AdviceDesc,
- ReminderDate: item.ReminderDate,
- SingleDose: item.SingleDose,
- SingleDoseUnit: item.SingleDoseUnit,
- PrescribingNumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- AdviceDoctor: item.AdviceDoctor,
- Status: item.Status,
- CreatedTime: item.CreatedTime,
- UpdatedTime: item.UpdatedTime,
- AdviceAffirm: item.AdviceAffirm,
- Remark: item.Remark,
- StopTime: item.StopTime,
- StopReason: item.StopReason,
- StopDoctor: item.StopDoctor,
- StopState: item.StopState,
- ParentId: item.ParentId,
- ExecutionTime: item.ExecutionTime,
- ExecutionStaff: item.ExecutionStaff,
- ExecutionState: item.ExecutionState,
- Checker: item.Checker,
- RecordDate: item.RecordDate,
- DialysisOrderId: item.DialysisOrderId,
- CheckTime: item.CheckTime,
- CheckState: item.CheckState,
- DrugSpec: item.DrugSpec,
- DrugSpecUnit: item.DrugSpecUnit,
- Groupno: item.Groupno,
- RemindType: item.RemindType,
- FrequencyType: item.FrequencyType,
- DayCount: item.DayCount,
- WeekDay: item.WeekDay,
- TemplateId: item.TemplateId,
- Modifier: item.Modifier,
- DrugId: item.DrugId,
- Price: item.Price,
- PrescriptionId: item.PrescriptionId,
- MedListCodg: item.MedListCodg,
- FeedetlSn: item.FeedetlSn,
- Day: item.DayCount,
- ChildDoctorAdvice: nil,
- Drug: models.Drug{},
- Diagnosis: item.Diagnosis,
- Way: item.Way,
- HospApprFlag: item.HospApprFlag,
- LmtUsedFlag: item.LmtUsedFlag,
- HisOrderInfo: models.HisOrderInfo{},
- IsMedicine: item.IsMedicine,
- ExecutionFrequencyId: item.ExecutionFrequencyId,
- Child: nil,
- IsSettle: item.IsSettle,
- IsMobile: item.IsMobile,
- IsSelfDrug: item.IsSelfDrug,
- DrugWayCount: item.DrugWayCount,
- }
-
- //如果当前医嘱数量大于历史出库数据则需要出库
- if prescribing_number_total > out_count {
-
- //按最小单位出库
- var cha_count = prescribing_number_total - out_count
-
- newadviceInfo.PrescribingNumber = float64(cha_count)
- newadviceInfo.PrescribingNumberUnit = medical.MinUnit
-
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
-
- }
-
- //如果当前医嘱数量小于历史出库数据则需要退库
- if prescribing_number_total < out_count {
- var cha_count = out_count - prescribing_number_total
- drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
- service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
- service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
-
- }
-
- if prescribing_number_total == out_count {
- if out_count == 0 {
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
- }
-
- }
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
-
- tx.Commit()
- if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(item.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "6",
- "advice": advice,
- })
- return
- }
- }
- }
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
-
- //出库数量累加
- //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- }
- }
- }
-
- }
-
- //自备药
-
- selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpen.IsOpen == 1 {
-
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
-
- if selfBasedrug.IsSelfDrug == 1 {
-
- //查询是否有库存
- info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
-
- if len(info) > 0 {
- var total_count int64
- var prescribing_number_total int64
- for _, item := range info {
- if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if prescribing_number_total > total_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
- //出库
- if prescribing_number_total <= total_count {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: advice.AdviceDate,
- Type: 0,
- PatientId: advice.PatientId,
- IsCheck: 1,
- IsSys: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
- //查询今日是否有出库数据
- lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutId: lastWarehouseOutOne.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: advice.DrugId,
- Count: prescribing_number_total,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: advice.AdviceDate,
- Mtime: advice.AdviceDate,
- Remark: "",
- OrgId: advice.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: selfBasedrug.MinUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: advice.AdviceDate,
- PatientId: advice.PatientId,
- AdviceId: advice.ID,
- ClassType: "",
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- for _, it := range warehousingOutInfo {
-
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
- }
-
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- }
-
- }
-
- func (c *PatientApiController) CheckGroupAdvice() {
- groupno, _ := c.GetInt64("groupno", 0)
-
- if groupno <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- checker := adminUserInfo.AdminUser.Id
-
- theTime := time.Now()
-
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) CheckDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- origin, _ := c.GetInt64("origin", 0)
-
- if origin != 2 {
- // executionTime := c.GetString("execution_time")
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- // executionStaff := adminUserInfo.AdminUser.Id
- checker := adminUserInfo.AdminUser.Id
-
- // timeLayout := "2006-01-02 15:04:05"
- // loc, _ := time.LoadLocation("Local")
-
- // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
-
- theTime := time.Now()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- if advice.ParentId > 0 {
- err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 3,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "核对医嘱",
- RecordDate: exceAdvice.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- } else {
- err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 3,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "核对医嘱",
- RecordDate: exceAdvice.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
- checker := adminUserInfo.AdminUser.Id
- theTime := time.Now()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.HisDoctorAdviceInfo{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if advice.ParentId > 0 {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- } else {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
- }
-
- func (c *PatientApiController) UpdateDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if advice.AdviceType == 1 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
- // return
- //}
-
- //if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
- // if advice.StopState == 1 || advice.ExecutionState == 1 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- // return
- // }
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
- // return
- //}
-
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- err := service.UpdateDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端修改医嘱",
- RecordDate: advice.AdviceDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
-
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) StopGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
- utils.ErrorLog("stop_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopTime, _ := dataBody["stop_time"].(string)
- if len(stopTime) == 0 {
- utils.ErrorLog("len(stop_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopTime = theTime.Unix()
-
- if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) StopDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
- utils.ErrorLog("stop_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopTime, _ := dataBody["stop_time"].(string)
- if len(stopTime) == 0 {
- utils.ErrorLog("len(stop_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopTime = theTime.Unix()
-
- if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- err = service.StopDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) DeleteDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Status = 0
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否是自备药
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- creater := adminUserInfo.AdminUser.Id
- //退库
- service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
- }
- }
-
- err := service.DeleteDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 4,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端删除医嘱",
- RecordDate: advice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
-
- redis.Set(keyOne, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(key, "", time.Second)
- redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) DeleteGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否是自备药
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- creater := adminUserInfo.AdminUser.Id
- //退库
- service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
- }
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
-
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 4,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端批量删除医嘱",
- RecordDate: advice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
-
- key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // GetDoctorAdvices 医嘱列表
- func (c *PatientApiController) GetDoctorAdvices() {
- id, _ := c.GetInt64("id", 0)
- adviceType, _ := c.GetInt64("advice_type", 0)
- stopType, _ := c.GetInt64("stop_state", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- adminUserInfo := c.GetAdminUserInfo()
-
- delivery_way_one := c.GetString("delivery_way_one", "")
- operatorIDs := make([]int64, 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theEndtTIme = theTime.Unix()
- }
-
- hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
-
- if hisconfig.IsOpen == 1 {
- advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
- advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
-
- if len(advices) > 0 {
- for _, item := range advices {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- if item.StopDoctor > 0 {
- operatorIDs = append(operatorIDs, item.StopDoctor)
- }
- }
- }
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- //获取长期医嘱
- longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "operators": operators,
- "total": total,
- "advicetwo": advicestwo,
- "longAdvice": longAdvice,
- "is_open": hisconfig.IsOpen,
- })
- return
- } else {
- advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
- advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
-
- if len(advices) > 0 {
- for _, item := range advices {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- if item.StopDoctor > 0 {
- operatorIDs = append(operatorIDs, item.StopDoctor)
- }
- }
- }
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "operators": operators,
- "total": total,
- "advicetwo": advicestwo,
- "is_open": hisconfig.IsOpen,
- })
- return
- }
-
- }
-
- func (c *PatientApiController) GetPatientSchedules() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- todayTime := time.Now().Format("2006-01-02")
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
- theStartTime = theTime.Unix()
-
- schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
- if len(schedules) > 0 {
- for index, item := range schedules {
- _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
- schedules[index].Week = int64(week)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "schedules": schedules,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientDialysisRecords() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- mode_id, _ := c.GetInt64("mode_id", 0)
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminInfo := c.GetAdminUserInfo()
- records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
- fmt.Println("长度", len(records))
- if len(records) == 0 {
- list, _ := service.GetAllDialysisOrder(patientID, theStartTIme, theEndtTIme)
- for _, item := range list {
- schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
- prescribeOne, _ := service.GetDialysisPrescribeOne(adminInfo.CurrentOrgId, item.PatientId, item.DialysisDate)
-
- service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID, prescribeOne.ModeId)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "records": records,
- })
- return
- }
-
- func (c *PatientApiController) ProEducation() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminInfo := c.GetAdminUserInfo()
- edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "edus": edus,
- })
- return
- }
-
- func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- isChild := false
-
- if action == "create" {
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
- utils.ErrorLog("advice_type != 1&&2")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceType = adviceType
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceDate = theTime.Unix()
- advice.RecordDate = theTime.Unix()
-
- if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
- parentId := int64(dataBody["parent_id"].(float64))
- advice.ParentId = parentId
- if parentId > 0 {
- isChild = true
- }
- }
- }
-
- if !isChild {
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- code = enums.ErrorCodeParamWrong
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.StartTime = theTime.Unix()
-
- // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
- // utils.ErrorLog("advice_doctor")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
- // if adviceDoctor <= 0 {
- // utils.ErrorLog("advice_doctor <=0")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // advice.AdviceDoctor = adviceDoctor
-
- if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
- deliveryWay, _ := dataBody["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
- executionFrequency, _ := dataBody["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if advice.AdviceType == 1 && advice.ParentId == 0 {
-
- if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
- frequency_type := int64(dataBody["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
- week_day, _ := dataBody["week_days"].(string)
- advice.WeekDay = week_day
- }
- }
-
- }
-
- if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceName, _ := dataBody["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceName = adviceName
-
- if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
- adviceDsc, _ := dataBody["advice_desc"].(string)
- advice.AdviceDesc = adviceDsc
- }
-
- if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
- dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
- advice.DialysisOrderId = int64(dialysisOrderId)
- }
-
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
- singleDose := dataBody["single_dose"].(float64)
- advice.SingleDose = singleDose
- }
-
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
- tmp := dataBody["single_dose_unit"].(float64)
- singleDoseUnit := service.TypeConversion(tmp)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
- prescribingNumber := dataBody["prescribing_number"].(float64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- advice.Remark = remark
- }
-
- if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
- drug_id, _ := dataBody["drug_id"].(string)
- tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
- advice.DrugId = tmpDrugId
- }
- if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
- drug_id, _ := dataBody["drug_id"].(float64)
- advice.DrugId = int64(drug_id)
- }
-
- if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
- drug_name_id, _ := dataBody["drug_name_id"].(float64)
- advice.DrugNameId = int64(drug_name_id)
- }
-
- if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
- way, _ := dataBody["way"].(float64)
- advice.Way = int64(way)
- }
-
- if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
- push_start_time, _ := dataBody["push_start_time"].(string)
- var startTime int64
- if len(push_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- advice.PushStartTime = startTime
- }
-
- return
- }
-
- func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
-
- if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
- bloodFilter := int64(dataBody["blood_filter"].(float64))
- solution.BloodFilter = bloodFilter
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- return
- }
-
- func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if method == "create" {
- if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
- utils.ErrorLog("mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- mode := int64(dataBody["mode"].(float64))
- if mode <= 0 {
- utils.ErrorLog("mode <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeId = mode
-
- if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
- utils.ErrorLog("mode_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- modeName, _ := dataBody["mode_name"].(string)
- if len(modeName) == 0 {
- utils.ErrorLog("len(mode_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeName = modeName
- solution.Name = modeName
-
- }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
- targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
- solution.TargetUltrafiltration = targetUltrafiltration
- }
-
- if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
- dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
- solution.DialysateFormulation = dialysateFormulation
- }
-
- if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
- dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
- solution.DialysisDurationHour = int64(dialysisDurationHour)
- }
-
- if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
- dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
- solution.DialysisDurationMinute = int64(dialysisDurationMinute)
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
- if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
- dialyzer := int64(dataBody["dialyzer"].(float64))
- solution.Dialyzer = dialyzer
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
- dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
- solution.Dewater = dewater
- }
-
- if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
- displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
- solution.DisplaceLiqui = displaceLiqui
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
- glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
- solution.Glucose = glucose
- }
-
- // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- // solution.DryWeight = dryWeight
- // }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
- dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
- solution.DialysateTemperature = dialysateTemperature
- }
-
- if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
- conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
- solution.Conductivity = conductivity
- }
-
- if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
- replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
- solution.ReplacementTotal = replacementTotal
- }
-
- if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
- dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
- solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
- }
-
- if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
- body_fluid := int64(dataBody["body_fluid"].(float64))
- solution.BodyFluid = body_fluid
- }
-
- if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
- body_fluid_other := dataBody["body_fluid_other"].(string)
- solution.BodyFluidOther = body_fluid_other
- }
-
- if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
- special_medicine := int64(dataBody["special_medicine"].(float64))
- solution.SpecialMedicine = special_medicine
- }
-
- if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
- special_medicine_other := dataBody["special_medicine_other"].(string)
- solution.SpecialMedicineOther = special_medicine_other
- }
-
- if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
- displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
- solution.DisplaceLiquiPart = displace_liqui_part
- }
- if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
- displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
- solution.DisplaceLiquiValue = displace_liqui_value
- }
- if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
- blood_access := int64(dataBody["blood_access"].(float64))
- solution.BloodAccess = blood_access
- }
-
- if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
- ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
- solution.Ultrafiltration = ultrafiltration
- }
-
- if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
- target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
- solution.TargetKtv = target_ktv
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- solution.Remark = remark
- }
-
- if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
- hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
- solution.HemodialysisPipelines = hemodialysis_pipelines
- }
-
- if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
- hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
- solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
- }
-
- if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
- puncture_needle := dataBody["puncture_needle"].(string)
- solution.PunctureNeedle = puncture_needle
- }
-
- if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
- puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
- solution.PunctureNeedleCount = puncture_needle_count
- }
-
- if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
- epo := dataBody["epo"].(string)
- solution.Epo = epo
- }
-
- if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
- epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
- solution.EpoCount = epo_count
- }
-
- if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
- created_time := int64(dataBody["created_time"].(float64))
-
- solution.CreatedTime = created_time
- }
-
- if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
- dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
- solution.DialysisDialyszers = dialysisDialyszers
- }
-
- if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
- dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
- solution.DialysisIrrigation = dialysisIrrigation
- }
-
- if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
- dialysis_strainer := dataBody["dialysis_strainer"].(string)
- solution.DialysisStrainer = dialysis_strainer
- }
-
- if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
- plasmaSeparator := dataBody["plasma_separator"].(string)
- solution.PlasmaSeparator = plasmaSeparator
- }
-
- if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
- bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
- solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
- }
-
- if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
- oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
- solution.OxygenUptake = oxygen_uptake
- }
-
- if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
- oxygen_flow := dataBody["oxygen_flow"].(string)
- solution.OxygenFlow = oxygen_flow
- }
-
- if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
- oxygen_time := dataBody["oxygen_time"].(string)
- solution.OxygenTime = oxygen_time
- }
-
- if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
- max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
- solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
- }
-
- if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
- amylaceum := dataBody["amylaceum"].(string)
- solution.Amylaceum = amylaceum
- }
-
- if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
- chaptalization := dataBody["chaptalization"].(string)
- solution.Chaptalization = chaptalization
- }
-
- if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
- blood_access_part_id := dataBody["blood_access_part_id"].(string)
- solution.BloodAccessPartId = blood_access_part_id
- }
- return
- }
-
- func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if method == "create" {
-
- if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
- utils.ErrorLog("parent_id")
- code = enums.ErrorCodeParamWrong
- return
- }
- parentID := int64(dataBody["parent_id"].(float64))
- if parentID <= 0 {
- utils.ErrorLog("parentID <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ParentId = parentID
-
- if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
- utils.ErrorLog("sub_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- subName, _ := dataBody["sub_name"].(string)
- if len(subName) == 0 {
- utils.ErrorLog("len(sub_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.SubName = subName
- }
-
- if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
- utils.ErrorLog("initiate_mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- initiateMode := int64(dataBody["initiate_mode"].(float64))
- if initiateMode != 1 && initiateMode != 2 {
- utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.InitiateMode = initiateMode
-
- if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- utils.ErrorLog("doctor")
- code = enums.ErrorCodeParamWrong
- return
- }
- doctor := int64(dataBody["doctor"].(float64))
- if doctor <= 0 {
- utils.ErrorLog("doctor <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.Doctor = doctor
-
- if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
- blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
- solution.BloodAccessPartId = blood_access_part_id
- }
- return
- }
-
- func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &patientBody)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
- formItem, _ := patientBody["formItem"].([]interface{})
-
- if len(formItem) > 0 {
- for _, item := range formItem {
- items := item.(map[string]interface{})
- project_name, _ := items["project_name"].(string)
- fmt.Println(project_name)
-
- range_type := int64(items["range_type"].(float64))
- fmt.Println(range_type)
-
- project_id := int64(items["project_id"].(float64))
- fmt.Println(project_id)
-
- item_id := int64(items["item_id"].(float64))
- fmt.Println(item_id)
-
- item, _ := items["item"].(string)
-
- fmt.Println(items["item"].(string))
-
- item_name, _ := items["item_name"].(string)
- fmt.Println(item_name)
-
- value, _ := items["value"].(string)
- fmt.Println(items["value"].(string))
-
- var form models.FormItem
- form.ProjectName = project_name
- form.RangeType = range_type
- form.ProjectId = project_id
- form.ItemId = item_id
- form.Item = item
- form.ItemName = item_name
- form.Value = value
- formItems = append(formItems, &form)
- }
- }
- }
- if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
- utils.ErrorLog("avatar")
- code = enums.ErrorCodeParamWrong
- return
- }
- avatar, _ := patientBody["avatar"].(string)
-
- if len(avatar) == 0 {
- utils.ErrorLog("len(avatar) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Avatar = avatar
-
- if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
- utils.ErrorLog("name")
- code = enums.ErrorCodeParamWrong
- return
- }
- name, _ := patientBody["name"].(string)
- if len(name) == 0 {
- utils.ErrorLog("len(name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Name = name
-
- if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
- alias := patientBody["alias"].(string)
- patient.Alias = alias
- }
-
- if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
- nation := patientBody["nation"].(string)
- patient.Nation = nation
- }
- if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
- native_place := patientBody["native_place"].(string)
- patient.NativePlace = native_place
- }
-
- if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
- utils.ErrorLog("idCardNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- idCardNo, _ := patientBody["idCardNo"].(string)
- if len(idCardNo) == 0 {
- utils.ErrorLog("len(idCardNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.IdCardNo = idCardNo
-
- patient.PatientType = 1
-
- if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
- utils.ErrorLog("dialysisNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- dialysisNo, _ := patientBody["dialysisNo"].(string)
- if len(dialysisNo) == 0 {
- utils.ErrorLog("len(dialysisNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.DialysisNo = dialysisNo
- // }
-
- if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
- utils.ErrorLog("lapseto")
- code = enums.ErrorCodeParamWrong
- return
- }
- lapseto := int64(patientBody["lapseto"].(float64))
- if lapseto <= 0 {
- utils.ErrorLog("lapseto == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Lapseto = lapseto
-
- if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
- utils.ErrorLog("gender")
- code = enums.ErrorCodeParamWrong
- return
- }
- gender := int64(patientBody["gender"].(float64))
- if gender <= 0 {
- utils.ErrorLog("gender <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Gender = gender
-
- if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
- response_result := patientBody["response_result"].(string)
- patient.ResponseResult = response_result
- }
-
- if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
- utils.ErrorLog("age")
- code = enums.ErrorCodeParamWrong
- return
- }
- age := int64(patientBody["age"].(float64))
- patient.Age = age
-
- if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
- user_sys_before_count := patientBody["user_sys_before_count"].(string)
- count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
- patient.UserSysBeforeCount = count
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
- utils.ErrorLog("birth")
- code = enums.ErrorCodeParamWrong
- return
- }
- birth, _ := patientBody["birth"].(string)
- if len(birth) == 0 {
- utils.ErrorLog("len(birth) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
- if err != nil {
- utils.ErrorLog("birthTime")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Birthday = birthTime.Unix()
-
- if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
- height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
- patient.Height = height
- }
-
- if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
- maritalStatus := int64(patientBody["maritalStatus"].(float64))
- patient.MaritalStatus = maritalStatus
- }
-
- if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
- children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
- patient.Children = children
- }
-
- if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
- admissionNumber, _ := patientBody["admissionNumber"].(string)
- patient.AdmissionNumber = admissionNumber
- }
-
- if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
- reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
- patient.ReimbursementWayId = reimbursementWayID
- }
-
- if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
- healthCareNo := patientBody["healthCareNo"].(string)
- patient.HealthCareNo = healthCareNo
- }
-
- if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
- utils.ErrorLog("phone")
- code = enums.ErrorCodeParamWrong
- return
- }
- phone := patientBody["phone"].(string)
- if len(phone) == 0 {
- utils.ErrorLog("len(phone) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- if !utils.CheckMobile(phone) {
- utils.ErrorLog("!phone")
- code = enums.ErrorCodeMobileFormat
- return
- }
- patient.Phone = phone
-
- if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
- homeTelephone := patientBody["homeTelephone"].(string)
- patient.HomeTelephone = homeTelephone
- }
-
- if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
- relativePhone := patientBody["relative_phone"].(string)
- patient.RelativePhone = relativePhone
- }
-
- if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
- relativeRelations := patientBody["relative_relations"].(string)
- patient.RelativeRelations = relativeRelations
- }
-
- if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
- homeAddress := patientBody["homeAddress"].(string)
- patient.HomeAddress = homeAddress
- }
-
- if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
- work := patientBody["work"].(string)
- patient.WorkUnit = work
- }
-
- if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
- unitAddress := patientBody["unit_address"].(string)
- patient.UnitAddress = unitAddress
- }
-
- if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
- profession := int64(patientBody["profession"].(float64))
- patient.Profession = profession
- }
-
- if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
- education := int64(patientBody["education"].(float64))
- patient.EducationLevel = education
- }
-
- if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
- utils.ErrorLog("source")
- code = enums.ErrorCodeParamWrong
- return
- }
- source := int64(patientBody["source"].(float64))
- if source <= 0 {
- utils.ErrorLog("source <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Source = source
-
- zb_patient_id := patientBody["zb_patient_id"].(string)
- patient.ZbPatientId = zb_patient_id
-
- if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
- isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
- patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
- }
-
- if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
- firstDialysisDate := patientBody["firstDialysisDate"].(string)
- firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
- if err == nil {
- patient.FirstDialysisDate = firstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
- firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
- patient.FirstDialysisHospital = firstDialysisHospital
- }
-
- if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
- thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
- if len(thePredialysisCondition) > 0 {
- conditions := make([]string, 0)
- for _, item := range thePredialysisCondition {
- if reflect.TypeOf(item).String() != "string" {
- continue
- }
- condition := item.(string)
- if len(condition) > 0 {
- conditions = append(conditions, condition)
- }
- }
- patient.PredialysisCondition = strings.Join(conditions, ",")
- }
- }
-
- if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
- preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
- patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
- }
-
- if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
- preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
- patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
- }
- if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
- hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
- hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
- if err == nil {
- patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
- partition := int64(patientBody["partition"].(float64))
- patient.PartitionId = partition
- }
- if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
- bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
- patient.BedId = bed
- }
-
- if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
- healthCareDueDate := patientBody["healthCareDueDate"].(string)
- healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
- if err == nil {
- patient.HealthCareDueDate = healthCareDueDateTime.Unix()
- }
- }
-
- if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
- blood := int64(patientBody["blood"].(float64))
- patient.BloodType = blood
- }
-
- if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
- rh := int64(patientBody["rh"].(float64))
- patient.Rh = rh
- }
-
- if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
- healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
- healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
- if err == nil {
- patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
- }
- }
-
- if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
- receivingDate := patientBody["receivingDate"].(string)
- receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
- if err == nil {
- patient.ReceivingDate = receivingDateTime.Unix()
- }
- }
-
- if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
- induction := int64(patientBody["induction"].(float64))
- patient.InductionPeriod = induction
- }
-
- if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
- initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
- patient.InitialDialysis = initial
- }
-
- if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
- dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
- patient.TotalDialysis = dialysisTotal
- }
-
- if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
- thisContagions, _ := patientBody["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- }
-
- if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
- doctor := int64(patientBody["doctor"].(float64))
- patient.AttendingDoctorId = doctor
- }
-
- if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
- nurse := int64(patientBody["nurse"].(float64))
- patient.HeadNurseId = nurse
- }
-
- if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
- assessment := patientBody["assessment"].(string)
- patient.Evaluate = assessment
- }
-
- if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
- thisDiseases, _ := patientBody["diseases"].([]interface{})
- if len(thisDiseases) > 0 {
- for _, item := range thisDiseases {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- disease := int64(item.(float64))
- if disease > 0 {
- diseases = append(diseases, disease)
- }
- }
- }
- }
-
- if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
- diagnose := patientBody["diagnose"].(string)
- patient.Diagnose = diagnose
- }
-
- if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
- remark := patientBody["remark"].(string)
- patient.Remark = remark
- }
-
- if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
- sch_remark := patientBody["sch_remark"].(string)
- patient.SchRemark = sch_remark
- }
-
- if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
- patient_complains := patientBody["patient_complains"].(string)
- patient.PatientComplains = patient_complains
- }
-
- if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
- present_history := patientBody["present_history"].(string)
- patient.PresentHistory = present_history
- }
-
- if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
- past_history := patientBody["past_history"].(string)
- patient.PastHistory = past_history
- }
-
- if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
- temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
- patient.Temperature = temperature
- }
-
- if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
- pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
- patient.Pulse = pulse
- }
-
- if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
- respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
- patient.Respiratory = respiratory
- }
-
- if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
- sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
- patient.SBP = sbp
- }
-
- if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
- dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
- patient.DBP = dbp
- }
-
- if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
- dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
- patient.DialysisAge = dialysis_age
- }
- fmt.Println(patient.DialysisAge)
- if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
- first_treatment_date := patientBody["first_treatment_date"].(string)
- first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
- if err == nil {
- patient.FirstTreatmentDate = first_treatment_time.Unix()
- }
- }
- if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
- expense_kind := int64(patientBody["expense_kind"].(float64))
- patient.ExpenseKind = expense_kind
- }
- fmt.Println(patient.ExpenseKind)
- if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
- tell_phone := patientBody["tell_phone"].(string)
- patient.TellPhone = tell_phone
- }
- if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
- contact_name := patientBody["contact_name"].(string)
- patient.ContactName = contact_name
- }
- if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
- troble_shoot := int64(patientBody["troble_shoot"].(float64))
- patient.TrobleShoot = troble_shoot
- }
-
- if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
- treatment_plan := patientBody["treatment_plan"].(string)
- patient.TreatmentPlan = treatment_plan
- }
-
- if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
- doctor := int64(patientBody["doctor"].(float64))
- patient.Doctor = doctor
- }
-
- if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
- record_number := patientBody["record_number"].(string)
- patient.RecordNumber = record_number
- }
-
- patient_source := int64(patientBody["patient_source"].(float64))
- if patient_source <= 0 {
- utils.ErrorLog("patient_source <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.PatientSource = patient_source
-
- if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
- patient_start_time := patientBody["patient_start_time"].(string)
- var startTime int64
- if len(patient_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- patient.PatientStartTime = startTime
- }
-
- if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
- patient_end_time := patientBody["patient_end_time"].(string)
- var endTime int64
- if len(patient_end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
-
- endTime = theTime.Unix()
- }
- patient.PatientEndTime = endTime
- }
-
- if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
- record_number := patientBody["infectious_remark"].(string)
- patient.InfectiousRemark = record_number
- }
-
- if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
- allergic_history := patientBody["allergic_history"].(string)
- patient.AllergicHistory = allergic_history
- }
-
- if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
- patient_address := patientBody["patient_address"].(string)
- patient.PatientAddress = patient_address
- }
-
- if patientBody["famality_record"] != nil && reflect.TypeOf(patientBody["famality_record"]).String() == "string" {
- famality_record := patientBody["famality_record"].(string)
- patient.FamalityRecord = famality_record
- }
-
- if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
- print_date := patientBody["print_date"].(string)
- printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
- if err == nil {
- patient.PrintDate = printDateTime.Unix()
- }
- }
-
- if patientBody["patient_type"] != nil && reflect.TypeOf(patientBody["patient_type"]).String() == "float64" {
- patient_type := int64(patientBody["patient_type"].(float64))
- patient.PatientType = patient_type
- }
- return
-
- }
-
- func (c *PatientApiController) GetPatientsByKeyWord() {
- keyWord := c.GetString("keyword")
- adminUserInfo := c.GetAdminUserInfo()
- patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *PatientApiController) QueryPatientById() {
- id, _ := c.GetInt64("id")
- fmt.Println(id)
- patientInfo := service.QueryPatientById(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientInfo,
- })
- return
- }
-
- func (c *PatientApiController) GetRemindPatientList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- adminUserInfo := c.GetAdminUserInfo()
- total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
- _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
- if errcode == gorm.ErrRecordNotFound {
- information, err := service.GetAdminUserRoleInformation(0)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- "information": information,
- })
- } else if errcode == nil {
- information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- "information": information,
- })
- }
- }
-
- func (c *PatientApiController) PostIsOpenRemind() {
- patient_id, _ := c.GetInt64("id", 1)
- is_open_remind, _ := c.GetInt64("is_open_remind", 1)
- adminUserInfo := c.GetAdminUserInfo()
-
- err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "成功",
- "is_open_remind": is_open_remind,
- })
- } else if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- }
-
- func (c *PatientApiController) GetPatientScheduleOne() {
- id, _ := c.GetInt64("id")
- //查询该病人是否当天是排班
- nowDateTime := time.Now()
- nowDate := nowDateTime.Format("2006-01-02")
- nowDate += " 00:00:00"
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
- nowdate := theTime.Unix()
- fmt.Println("nowdate", nowdate)
- adminUser := c.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- fmt.Println("orgid", orgId)
- scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "scheduls": scheduls,
- })
- }
-
- func (c *PatientApiController) ExportPatients() {
- dataBody := make(map[string]interface{}, 0)
-
- all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
-
- //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
-
- org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
-
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- export_time := time.Now().Unix()
- var patients []*models.Patients
- var total_patients []interface{}
- if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
- tempPatients := dataBody["patients"].([]interface{})
- total_patients = tempPatients
- for index, patientMap := range tempPatients {
- patientNameM := patientMap.(map[string]interface{})
- var patient models.Patients
-
- if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
- utils.ErrorLog("name")
- return
- }
- name, _ := patientNameM["name"].(string)
- if len(name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Name = name
-
- if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
- gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
- if gender == 0 { //性别不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.Gender = gender
- }
- }
-
- if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
- phone, _ := patientNameM["phone"].(string)
- if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
- if len(phone) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- } else {
- //var tempPatient *models.Patients
- //for _, item := range all_patient {
- // if item.Phone == phone {
- // tempPatient = item
- // }
- //}
-
- //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
- count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Phone = phone
- }
- }
-
- if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
- id_card_no, _ := patientNameM["id_card_no"].(string)
-
- count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- //if tempPatient != nil && tempPatient.ID > 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- //}
- patient.IdCardNo = id_card_no
- //patient.Birthday = GetBirthDay(id_card_no).Unix()
- if GetBirthDay(id_card_no) == nil {
- patient.Birthday = 0
- } else {
- patient.Birthday = GetBirthDay(id_card_no).Unix()
-
- }
-
- }
-
- fmt.Println("111112222")
- if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
- first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
- timeLayout := "2006/01/02"
- loc, _ := time.LoadLocation("Local")
- first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
-
- if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
-
- } else {
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
-
- if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.FirstDialysisDate = first_dialysis_date.Unix()
- }
-
- }
-
- }
- }
-
- if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
- source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
- if source == 0 { //患者来源不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if source == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Source = source
- }
- }
-
- if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
- lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
- if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if lapseto == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Lapseto = lapseto
- }
- }
-
- if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
- is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
- if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if is_infectious == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.IsInfectious = is_infectious
- }
- }
-
- if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
- var contagions []int64
- thisContagions, _ := patientNameM["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- patient.ContagionIds = contagions
- }
-
- if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
- diagnose, _ := patientNameM["diagnose"].(string)
- patient.Diagnose = diagnose
-
- }
-
- if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
- dialysis_no, _ := patientNameM["dialysis_no"].(string)
- var tempPatient *models.Patients
- for _, item := range all_patient {
- if item.DialysisNo == dialysis_no {
- tempPatient = item
- }
- }
- if tempPatient != nil && tempPatient.ID > 0 {
- patient.DialysisNo = GenerateDialysisNoTwo(patients)
- } else {
- patient.DialysisNo = dialysis_no
- }
- }
-
- if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
- height, _ := patientNameM["height"].(string)
- heights, _ := strconv.ParseFloat(height, 64)
- patient.Height = int64(heights)
- }
-
- if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
- home_address, _ := patientNameM["home_address"].(string)
- patient.HomeAddress = home_address
- }
- if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
- dry_weight, _ := patientNameM["dry_weight"].(string)
- dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
- patient.DryWeight = dry_weights
-
- }
- patient.CreatedTime = time.Now().Unix()
- patient.UpdatedTime = time.Now().Unix()
- patient.Status = 1
- patient.Avatar = "https://images.shengws.com/201809182128111.png"
- patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- patient.IsExcelExport = 1
- patient.PatientType = 1
- patients = append(patients, &patient)
- }
- }
- errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(patients) > 0 {
- for _, item := range patients {
-
- hans := item.Name // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 输出拼音
- fmt.Println("Pinyin:", pinyinSlice)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- item.FirstLetter = firstLetter
- service.CreateExportPatient(item, item.ContagionIds, org.Creator)
- }
-
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func GetBirthDay(IDCardNo string) *time.Time {
- dayStr := IDCardNo[6:14]
- birthDay, err := time.Parse("20060102", dayStr)
- if err != nil {
- fmt.Println(err)
- return nil
- }
- return &birthDay
- }
-
- func IsIdCard(id string) (res bool) {
- id = strings.ToUpper(id)
- if len(id) != 15 && len(id) != 18 {
- fmt.Println("1111111")
- return false
- }
- r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
- if !r.MatchString(id) {
- fmt.Println("222222")
-
- return false
- }
- if len(id) == 15 {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
- if tm2.Unix() == 0 {
- fmt.Println("44444443333")
-
- return false
- }
- return true
- } else {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
- fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
- fmt.Println(tm2.Unix())
-
- if tm2.Unix() == 0 {
-
- fmt.Println("44445555555")
-
- return false
- }
- //检验18位身份证的校验码是否正确。
- //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
- arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
- sign := 0
- for k, v := range arr_int {
- int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
- sign += int_temp * v
- }
- n := sign % 11
- val_num := arr_ch[n]
- if val_num != string([]byte(id)[17:18]) {
- fmt.Println("5556666666")
-
- return false
- }
- return true
- }
- }
-
- func (c *PatientApiController) SaveEditAdvices() {
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- startTime := c.GetString("start_time")
-
- theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
-
- groupno, _ := c.GetInt64("groupno")
- fmt.Println("组", groupno)
- date, _ := c.GetInt64("date")
- fmt.Println("date", date)
- patient_id, _ := c.GetInt64("patient_id")
- fmt.Println("paitent_id", patient_id)
- advice := models.XtDoctorAdvice{
- StartTime: theTime.Unix(),
- }
- err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
- key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
- redis := service.RedisClient()
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- scheduleTime := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
- fmt.Println("keyFour323223323232323232", keyFour)
- redis.Set(keyFour, "", time.Second)
-
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- }
-
- func (c *PatientApiController) GetMaxDialysisNo() {
- dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_no": dialysisNo,
- })
-
- }
-
- func GenerateDialysisNoTwo(patients []*models.Patients) string {
- dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
- var tempPatient *models.Patients
- for _, item := range patients {
- if item.DialysisNo == dialysisNo2 {
- tempPatient = item
- }
- }
- if tempPatient == nil || tempPatient.ID == 0 {
- return dialysisNo2
- }
- return GenerateDialysisNoTwo(patients)
- }
-
- func (c *PatientApiController) GetBanner() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- _, errcodes := service.GetOrgFollowIsExist(orgId)
-
- if errcodes == gorm.ErrRecordNotFound {
- information, err := service.GetAdminUserRoleInformation(0)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- })
- } else if errcodes == nil {
- information, err := service.GetAdminUserRoleInformation(orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- })
- }
- }
-
- func (c *PatientApiController) GetPatientDialysisLongSolution() {
-
- patient_id, _ := c.GetInt64("id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if patient_id <= 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": nil,
- })
- return
- }
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- //获取该患者分组的透析模式
- list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
-
- for _, item := range list {
- //获取该模式最新的1条数据
- solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
- //更新状态值
- service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
- }
-
- solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
- stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solution,
- "total": total,
- "stockType": stockType,
- })
- }
-
- func (c *PatientApiController) GetDialysisSolutionDetailList() {
-
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- }
-
- func (c *PatientApiController) SaveFallOutBedPrint() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- outPrint := models.XtFallOutPrint{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- //查询该机构是否存在
- list, err := service.GetOutPrintList(orgid)
-
- if list.ID == 0 {
- service.CreateFallOutBedPrint(outPrint)
- }
-
- if list.ID > 0 {
- service.UpdateFallOutBedPrint(list.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) GetFallOutBedPrintList() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- list, _ := service.GetFallOutBedPrintList(orgid)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) SaveFilterInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
- informed := models.XtFilterInformed{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- filterInformed, _ := service.GetFilterInformed(orgid)
-
- if filterInformed.ID == 0 {
-
- service.CreateFilterInformed(informed)
- }
-
- if filterInformed.ID > 0 {
-
- service.UpdateFilterInformed(filterInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "informed": informed,
- })
-
- }
-
- func (c *PatientApiController) GetFilterInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- filterInformed, _ := service.GetFilterInformed(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": filterInformed,
- })
- }
-
- func (c *PatientApiController) SaveProfundaInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- informed := models.XtProfundaInformed{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- profundaInformed, _ := service.GetProfundaInformed(orgid)
-
- if profundaInformed.ID == 0 {
- service.CreateProfundaInformed(informed)
- }
-
- if profundaInformed.ID > 0 {
-
- service.UpdateProfundaInformed(profundaInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": profundaInformed,
- })
- }
-
- func (c *PatientApiController) GetProfundaInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- profundaInformed, _ := service.GetProfundaInformed(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": profundaInformed,
- })
- }
-
- func (c *PatientApiController) SaveArterOvenous() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- arterOvenous := models.XtArterOvenous{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- list, _ := service.GetArterOvenousList(orgid)
-
- if list.ID == 0 {
-
- service.CreateArterOvernous(arterOvenous)
- }
-
- if list.ID > 0 {
- service.UpdateArterOvernous(list.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) GetArterOverNous() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- list, _ := service.GetArterOvenousList(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- func (c *PatientApiController) SaveHighRikInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- risk := models.XtHightRisk{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- highRik, _ := service.GetHightRikInformed(orgid)
-
- if highRik.ID == 0 {
-
- service.CreateHighRik(risk)
- }
-
- if highRik.ID > 0 {
-
- service.UpdateHighRik(highRik.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": risk,
- })
- }
-
- func (c *PatientApiController) GetHighRiskInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- rikInformed, _ := service.GetHightRikInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": rikInformed,
- })
- }
-
- func (c *PatientApiController) SaveAnticoagulation() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- auticoagutionPrint := models.XtAuticoagutionPrint{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- anticoagulation, _ := service.GetAnticoagulation(orgId)
-
- if anticoagulation.ID == 0 {
-
- service.CreateAnticoagulation(auticoagutionPrint)
- }
-
- if anticoagulation.ID > 0 {
-
- service.UpdateAnticoagulation(anticoagulation.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": auticoagutionPrint,
- })
-
- }
-
- func (c *PatientApiController) GetAnticoagulationInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- anticoagulation, _ := service.GetAnticoagulation(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": anticoagulation,
- })
- }
-
- func (c *PatientApiController) SaveCriticalInfomed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- criticalinfomedPrint := models.XtCriticalinfomedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- infomed, _ := service.GetCriticalInfomed(orgId)
-
- if infomed.ID == 0 {
- service.CreatedCriticalInfomed(criticalinfomedPrint)
- }
-
- if infomed.ID > 0 {
- service.UpdateCriticalInfomed(infomed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": criticalinfomedPrint,
- })
- }
-
- func (c *PatientApiController) GetCriticalInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- infomed, _ := service.GetCriticalInfomed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": infomed,
- })
- }
-
- func (c *PatientApiController) SaveHemoperfusionInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- informed, _ := service.GetHemoperfusionInformed(orgId)
-
- if informed.ID == 0 {
-
- service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
- }
-
- if informed.ID > 0 {
-
- service.UpdateHemoperfusionInformed(informed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": hemoperfusionmedPrint,
- })
- }
-
- func (c *PatientApiController) GetHemoperfusionInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- informed, _ := service.GetHemoperfusionInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveBringInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- bringinformedPrint := models.XtBringinformedPrint{
- Content: content,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- }
-
- informed, _ := service.GetBringInformed(orgId)
-
- if informed.ID == 0 {
- service.CreateBringInformed(bringinformedPrint)
- }
- if informed.ID > 0 {
- service.UpdateBringInformed(informed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": bringinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetInformedContsent() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- informed, _ := service.GetBringInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveCatheterization() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- cathetercationPrint := models.XtCathetercationPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- catheterization, _ := service.GetCatheterization(orgId)
-
- if cathetercationPrint.ID == 0 {
-
- service.CreateCatheteriztion(cathetercationPrint)
- }
-
- if cathetercationPrint.ID > 0 {
-
- service.UpdateCatheterization(catheterization.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": catheterization,
- })
- }
-
- func (c *PatientApiController) GetCatheterization() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- catheterization, _ := service.GetCatheterization(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": catheterization,
- })
- }
-
- func (c *PatientApiController) SaveDialyzerInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- dialyszerinformedPrint := models.XtDialyszerinformedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- informed, _ := service.GetDialyzerInformed(orgId)
-
- if informed.ID == 0 {
-
- service.CreateDialyzerInformed(dialyszerinformedPrint)
- }
-
- if informed.ID > 0 {
- service.UpdateDialyszerInformed(informed.ID, content)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": dialyszerinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetDialyzerInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- informed, _ := service.GetDialyzerInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveTheapyInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- theapyinformedPrint := models.XtTheapyinformedPrint{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- theapyInformed, _ := service.GetTheapyInformed(orgId)
-
- if theapyInformed.ID == 0 {
-
- service.CreateTheapyInformed(theapyinformedPrint)
- }
-
- if theapyInformed.ID > 0 {
-
- service.UpdateTheaphInformed(theapyInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyinformedPrint,
- })
-
- }
-
- func (c *PatientApiController) GetTherapyInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- theapyInformed, _ := service.GetTheapyInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyInformed,
- })
- }
-
- func (c *PatientApiController) SaveMedicalHistory() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
- patient_id := int64(dataBody["patient_id"].(float64))
- medicalHistory := models.XtMedicalHistory{
- UserOrgId: orgId,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- Content: content,
- }
-
- //
- history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
-
- if history.ID > 0 {
- service.UpdatePatientMedicalHistory(history.ID, content)
- }
- if history.ID == 0 {
- service.CreatePatientMedicalHistory(medicalHistory)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "medicalHistory": medicalHistory,
- })
-
- }
-
- func (c *PatientApiController) SavePatientCritaicalInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- patientCritical := models.XtPatientCritical{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
-
- if patientCritaicalInformed.ID == 0 {
- service.CreatePatientCritaicalinformed(patientCritical)
- }
- if patientCritaicalInformed.ID > 0 {
- service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patientCritical": patientCritical,
- })
- }
-
- func (c *PatientApiController) GetPatientCriticalList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patientCritaicalInformed": patientCritaicalInformed,
- })
- }
-
- func (c *PatientApiController) SavePatientCriticalInformedOne() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- criticalOne := models.XtPatientCriticalOne{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
-
- if critical.ID == 0 {
- service.CreatePatientCritical(criticalOne)
- }
-
- if critical.ID > 0 {
- service.UpdatePatientCriticalOne(orgId, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "criticalOne": criticalOne,
- })
-
- }
-
- func (c *PatientApiController) GetPatientCriticalOneList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetPatientCriticalOneList(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) DeleteSolution() {
-
- id, _ := c.GetInt64("id")
- solution, _ := service.DeleteSolutionById(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- })
- }
-
- func (c *PatientApiController) SaveTreatmentPlan() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- theapyinformedPrint := models.XtTreatmentPlan{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- treamentPlan, _ := service.GetTreamentPland(orgId)
-
- if treamentPlan.ID == 0 {
-
- service.CreateTreatqmentPland(theapyinformedPrint)
- }
-
- if treamentPlan.ID > 0 {
-
- service.UpdateTheatmentPland(treamentPlan.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetTreatMentPlanList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- treamentPlan, _ := service.GetTreamentPland(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "treamentPlan": treamentPlan,
- })
- }
-
- func (c *PatientApiController) GetPatientByPatientId() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- id, _ := c.GetInt64("id")
-
- patients, _ := service.GetPatientByIDOne(orgId, id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- }
-
- func (c *PatientApiController) SavePatientLapse() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- admin_user_id := int64(dataBody["admin_user_id"].(float64))
-
- lapse_class := int64(dataBody["lapse_class"].(float64))
-
- lapse_type := int64(dataBody["lapse_type"].(float64))
-
- lapse_reason := dataBody["lapse_reason"].(string)
-
- record_date := dataBody["record_date"].(string)
-
- lapse_type_name := dataBody["lapse_type_name"].(string)
-
- his_bed := dataBody["his_bed"].(string)
-
- his_zone := dataBody["his_zone"].(string)
-
- his_type := int64(dataBody["his_type"].(float64))
-
- patient_address := dataBody["patient_address"].(string)
-
- start_time := dataBody["start_time"].(string)
-
- end_time := dataBody["end_time"].(string)
-
- start_time_one := dataBody["start_time_one"].(string)
-
- end_time_one := dataBody["end_time_one"].(string)
-
- is_check := int64(dataBody["is_check"].(float64))
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- var startTimeOne int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTimeOne = theTime.Unix()
- }
-
- var endTimeOne int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeOne = theTime.Unix()
- }
-
- remark := dataBody["remark"].(string)
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- record := models.XtPatientLaspseRecord{
- PatientId: patient_id,
- RecordDate: recordDate,
- LapseDate: recordDate,
- LapseType: lapse_type,
- LapseClass: lapse_class,
- LapseReason: lapse_reason,
- AdminUserId: admin_user_id,
- Remark: remark,
- UserOrgId: org_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: lapse_type_name,
- HisBed: his_bed,
- HisType: his_type,
- HisZone: his_zone,
- StartTime: startTime,
- EndTime: endTime,
- StartTimeOne: startTimeOne,
- EndTimeOne: endTimeOne,
- PatientAddress: patient_address,
- }
-
- //病人转出
- if lapse_type == 2 {
-
- service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
-
- if is_check == 2 {
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- }
-
- //病人转出
- if lapse_type == 3 {
-
- service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
-
- if is_check == 2 {
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- }
-
- if lapse_type == 11 {
-
- service.UpdatePatientLasetoType(patient_id, lapse_type)
- }
-
- //病人转出
- if lapse_type == 1 {
-
- service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
-
- }
-
- service.CreatePatientRecord(record)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
-
- }
-
- func (c *PatientApiController) GetPatientLapsorecord() {
-
- id, _ := c.GetInt64("id")
-
- lapsorecord, _ := service.GetPatientLapsorecord(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "lapsorecord": lapsorecord,
- })
- }
-
- func (this *DialysisApiController) GetPatientLapseRecord() {
-
- patient_id, _ := this.GetInt64("patient_id")
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- record, total, _ := service.GetPatientLapseRecord(patient_id, limit, page, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- "total": total,
- })
- }
-
- func (c *DialysisApiController) UpdatePatientLapseRecord() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- admin_user_id := int64(dataBody["admin_user_id"].(float64))
-
- lapse_class := int64(dataBody["lapse_class"].(float64))
-
- lapse_type := int64(dataBody["lapse_type"].(float64))
-
- lapse_reason := dataBody["lapse_reason"].(string)
-
- record_date := dataBody["record_date"].(string)
-
- lapse_type_name := dataBody["lapse_type_name"].(string)
-
- his_bed := dataBody["his_bed"].(string)
-
- his_zone := dataBody["his_zone"].(string)
-
- his_type := int64(dataBody["his_type"].(float64))
-
- patient_address := dataBody["patient_address"].(string)
-
- start_time := dataBody["start_time"].(string)
-
- end_time := dataBody["end_time"].(string)
-
- start_time_one := dataBody["start_time_one"].(string)
-
- end_time_one := dataBody["end_time_one"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- var startTimeOne int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTimeOne = theTime.Unix()
- }
-
- var endTimeOne int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeOne = theTime.Unix()
- }
-
- remark := dataBody["remark"].(string)
-
- id := int64(dataBody["id"].(float64))
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- record := models.XtPatientLaspseRecord{
- ID: id,
- PatientId: patient_id,
- RecordDate: recordDate,
- LapseDate: recordDate,
- LapseType: lapse_type,
- LapseClass: lapse_class,
- LapseReason: lapse_reason,
- AdminUserId: admin_user_id,
- Remark: remark,
- UserOrgId: org_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: lapse_type_name,
- HisZone: his_zone,
- HisBed: his_bed,
- HisType: his_type,
- StartTime: startTime,
- StartTimeOne: startTimeOne,
- EndTime: endTime,
- EndTimeOne: endTimeOne,
- PatientAddress: patient_address,
- }
-
- //病人转出
- if lapse_type == 2 {
- service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- if lapse_type == 3 {
- service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- //病人转出
- if lapse_type == 1 {
-
- service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
-
- }
-
- if lapse_type == 11 {
- service.UpdatePatientLasetoType(patient_id, lapse_type)
- }
-
- service.SavePatientLapseRecord(record)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
-
- func (c *DialysisApiController) DeletePatientLapseRecord() {
-
- id, _ := c.GetInt64("id")
-
- service.DeletePatientLapseRecord(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
-
- }
-
- func (c *DialysisApiController) GetPatientLapseList() {
-
- fmt.Println("除非哈哈哈哈哈")
-
- list, _ := service.GetAllpatientFivty()
-
- if len(list) > 0 {
-
- for _, item := range list {
-
- patientLaspseRecord := models.XtPatientLaspseRecord{
- PatientId: item.ID,
- RecordDate: 0,
- LapseDate: item.CreatedTime,
- LapseType: 1,
- LapseClass: 0,
- LapseReason: "",
- AdminUserId: item.RegistrarsId,
- Remark: "",
- UserOrgId: item.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: "",
- HisType: 0,
- HisZone: "",
- HisBed: "",
- PatientAddress: "",
- StartTime: 0,
- EndTime: 0,
- StartTimeOne: 0,
- EndTimeOne: 0,
- }
-
- service.CreatePatientRecord(patientLaspseRecord)
- }
- }
-
- //list, _ := service.GetPatientLapsorecordListOne()
- //
- //if len(list) > 0 {
- // for _, item := range list {
- // //查询患者的信息
- // patients, _ := service.GetPatientByIDTwoOne(item.PatientId)
- //
- // if patients.Lapseto == 2 || patients.Lapseto == 3 {
- //
- // patientLaspseRecord := models.XtPatientLaspseRecord{
- // PatientId: item.PatientId,
- // RecordDate: patients.DeathTime,
- // LapseDate: patients.DeathTime,
- // LapseType: patients.Lapseto,
- // LapseClass: patients.Lapseto,
- // LapseReason: patients.OutReason,
- // AdminUserId: 0,
- // Remark: "",
- // UserOrgId: patients.UserOrgId,
- // Ctime: time.Now().Unix(),
- // Mtime: time.Now().Unix(),
- // Status: 1,
- // LapseTypeName: "",
- // HisType: 0,
- // HisZone: "",
- // HisBed: "",
- // PatientAddress: "",
- // StartTime: patients.PatientStartTime,
- // EndTime: patients.PatientEndTime,
- // StartTimeOne: patients.PatientStartTime,
- // EndTimeOne: patients.PatientEndTime,
- // }
- //
- // service.CreatePatientRecord(patientLaspseRecord)
- // }
- // }
- //}
- //fmt.Println("lsit", list)
-
- //for _, item := range list {
- //
- //
- //}
- }
-
- func (c *DialysisApiController) AddDeathSummary() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- id := int64(dataBody["id"].(float64))
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- record_date := dataBody["record_date"].(string)
-
- last_record_date := dataBody["last_record_date"].(string)
-
- reason_one := dataBody["reason_one"].(string)
-
- reason_two := dataBody["reason_two"].(string)
-
- reason_three := dataBody["reason_three"].(string)
-
- reason_four := dataBody["reason_four"].(string)
-
- death_way := dataBody["death_way"].(string)
-
- replace_way := dataBody["replace_way"].(string)
-
- replace_reason := dataBody["replace_reason"].(string)
-
- transplant := dataBody["transplant"].(string)
-
- remark := dataBody["remark"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- var lastRecordDate int64
- if len(last_record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", last_record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- lastRecordDate = theTime.Unix()
- }
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- admin_user_id := c.GetAdminUserInfo().AdminUser.Id
-
- deathSummary := models.XtDeathSummary{
- ID: id,
- PatientId: patient_id,
- UserOrgId: orgId,
- RecordDate: recordDate,
- ReasonOne: reason_one,
- ReasonTwo: reason_two,
- ReasonThree: reason_three,
- ReasonFour: reason_four,
- DeathWay: death_way,
- ReplaceWay: replace_way,
- ReplaceReason: replace_reason,
- Transplant: transplant,
- Ctime: time.Now().Unix(),
- Remark: remark,
- Mtime: time.Now().Unix(),
- Status: 1,
- AdminUserId: admin_user_id,
- UpdateCreater: admin_user_id,
- LastRecordDate: lastRecordDate,
- }
-
- service.CreateDeathSummary(deathSummary)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "deathSummary": deathSummary,
- })
- }
-
- func (c *DialysisApiController) GetPatientDeathSummary() {
-
- patient_id, _ := c.GetInt64("patient_id")
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- deathSummary, _ := service.GetPatientDeathSummary(patient_id, orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "deathSummary": deathSummary,
- })
- }
-
- func (c *DialysisApiController) DeletePatientDeathSummary() {
-
- id, _ := c.GetInt64("id")
-
- service.DeletePatientDeathSummary(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- func (this *PatientApiController) CreateNewSickHistoryRecord() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- record_date := dataBody["record_time"].(string)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- id := int64(dataBody["id"].(float64))
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- doctor_id := int64(dataBody["doctor_id"].(float64))
-
- guominyaowu_desc := dataBody["guominyaowu_desc"].(string)
-
- is_fumotouxishi := int64(dataBody["is_fumotouxishi"].(float64))
-
- is_guominyaowu := int64(dataBody["is_guominyaowu"].(float64))
-
- is_shenyizhishi := int64(dataBody["is_shenyizhishi"].(float64))
-
- content := dataBody["content"].(string)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- patientSickHistory := models.XtPatientSickHistory{
- ID: id,
- OrgId: orgId,
- PatientId: patient_id,
- Recorder: 0,
- RecordTime: recordDate,
- RecordDate: recordDate,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Title: "",
- IsShenyizhiHistory: is_shenyizhishi,
- IsFumoDialysisHistory: is_fumotouxishi,
- HypersusceptibilityDesc: guominyaowu_desc,
- DoctorId: doctor_id,
- IsHypersusceptibility: is_guominyaowu,
- }
-
- service.CreateNewSickHistoryRecord(patientSickHistory)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "patientSickHistory": patientSickHistory,
- })
- }
-
- func (this *PatientApiController) GetNewSickHistory() {
-
- patient_id, _ := this.GetInt64("patient_id")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetNewSickHistory(patient_id, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *PatientApiController) DeleteNewSickHistory() {
-
- id, _ := this.GetInt64("id")
-
- service.DeleteNewSickHistory(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (this *PatientApiController) SaveSickHistoryTemplate() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- title := dataBody["title"].(string)
-
- content := dataBody["content"].(string)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- sickHistoryTemplate := models.XtSickHistoryTemplate{
- Content: content,
- UserOrgId: orgId,
- Title: title,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- }
-
- service.CreateSickHistoryTemplate(sickHistoryTemplate)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "sickHistoryTemplate": "sickHistoryTemplate",
- })
- }
-
- func (this *PatientApiController) GetSickHistoryTemplate() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- templateList, _ := service.GetSickHistoryTemplate(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "templateList": templateList,
- })
- }
-
- func (this *PatientApiController) ModifySickHistoryTemplate() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- template_id := int64(dataBody["template_id"].(float64))
- content := dataBody["content"].(string)
-
- service.ModifySickHistoryTemplate(template_id, content)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (this *PatientApiController) DeleteSickHistoryTemplate() {
-
- template_id, _ := this.GetInt64("template_id")
-
- service.DeleteSickHistoryTemplate(template_id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (this *PatientApiController) CreateNewCourseOfDiaseaseRecord() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- record_date := dataBody["record_date"].(string)
-
- id := int64(dataBody["id"].(float64))
-
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_date)
-
- content := dataBody["content"].(string)
- admin_user_id := int64(dataBody["admin_user_id"].(float64))
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- patientCourse := models.PatientDiseaseCourse{
- ID: id,
- OrgID: orgId,
- PatientID: patient_id,
- Recorder: admin_user_id,
- RecordTime: recordDate.Unix(),
- Content: content,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- Title: "",
- }
-
- service.CreateNewCourseOfDiaseaseRecord(patientCourse)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- }
-
- func (this *PatientApiController) GetPatientCoureseOfDiseasesList() {
-
- patient_id, _ := this.GetInt64("patient_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetPatientCoureseOfDiseasesList(patient_id, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *PatientApiController) DeleteNewCourseOfDisease() {
-
- id, _ := this.GetInt64("id")
-
- service.DeleteNewCourseOfDisease(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (this *PatientApiController) CreateNewCourseTemplate() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- title := dataBody["title"].(string)
-
- content := dataBody["content"].(string)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- courseTemplate := models.XtPatientCourseTemplate{
- Content: content,
- UserOrgId: orgId,
- Title: title,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- service.CreateCourseTemplate(courseTemplate)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (this *PatientApiController) SavePatientDeathRecord() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- dialyszerinformedPrint := models.XtDeathRecord{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- informed, _ := service.GetPatientDeathRecord(orgId)
-
- if informed.ID == 0 {
-
- service.CreatePatientDeathRecord(dialyszerinformedPrint)
- }
-
- if informed.ID > 0 {
- service.UpdatePatientDeathRecord(informed.ID, content)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": dialyszerinformedPrint,
- })
- }
-
- func (this *PatientApiController) GetPatientDeathRecordOne() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- record, _ := service.GetPatientDeathRecordList(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
-
- func (this *PatientApiController) SaveCoureseTemplateTitle() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- title := dataBody["title"].(string)
- content := dataBody["content"].(string)
-
- courseTemplate := models.XtPatientCourseTemplate{
- Content: content,
- UserOrgId: orgId,
- Title: title,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- service.SaveCoureseTemplateTitle(courseTemplate)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "courseTemplate": courseTemplate,
- })
-
- }
-
- func (this *PatientApiController) GetPatientCourseOfTemplate() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetPatientCourseOfTemplate(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "templateList": list,
- })
- }
-
- func (this *PatientApiController) SaveCourseOfNewTemplate() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- id := int64(dataBody["template_id"].(float64))
- content := dataBody["content"].(string)
-
- service.SaveCourseOfNewTemplate(id, content)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- }
-
- func (this *PatientApiController) DeleteCouseTemplate() {
-
- id, _ := this.GetInt64("id")
-
- fmt.Println("id==================", id)
- service.DeleteCouseTemplate(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- }
|