patient_api_controller.go 237KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "math"
  5. "math/rand"
  6. "reflect"
  7. "regexp"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "github.com/jinzhu/gorm"
  16. "github.com/mozillazg/go-pinyin"
  17. "fmt"
  18. "github.com/astaxie/beego"
  19. )
  20. type PatientApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func PatientApiRegistRouters() {
  24. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  25. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  26. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  27. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  28. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  29. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  30. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  31. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  33. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  34. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  35. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  36. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  37. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  38. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  39. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  40. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  41. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  42. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  43. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  44. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  45. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  46. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  47. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  48. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  49. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  50. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  51. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  52. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  53. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  54. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  55. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  56. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  57. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  58. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  59. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  60. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  61. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  62. beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
  63. //长期医嘱新接口
  64. beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
  65. beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
  66. beego.Router("/api/patient/getexportlist", &PatientApiController{}, "Get:GetExportList")
  67. beego.Router("/api/patient/savefalloutbedprint", &PatientApiController{}, "Post:SaveFallOutBedPrint")
  68. beego.Router("/api/patient/getfalloutbedprintlist", &PatientApiController{}, "Get:GetFallOutBedPrintList")
  69. beego.Router("/api/patient/savefilterinformed", &PatientApiController{}, "Post:SaveFilterInformed")
  70. beego.Router("/api/patient/getfilterinformed", &PatientApiController{}, "Get:GetFilterInformed")
  71. beego.Router("/api/patient/saveprofundainformed", &PatientApiController{}, "Post:SaveProfundaInformed")
  72. beego.Router("/api/patient/getprofundainformed", &PatientApiController{}, "Get:GetProfundaInformed")
  73. beego.Router("/api/patient/arterovenous", &PatientApiController{}, "Post:SaveArterOvenous")
  74. beego.Router("/api/patient/getarterovernous", &PatientApiController{}, "Get:GetArterOverNous")
  75. beego.Router("/api/patient/savehighrikinformed", &PatientApiController{}, "Post:SaveHighRikInformed")
  76. beego.Router("/api/patient/gethighriskinformed", &PatientApiController{}, "Get:GetHighRiskInformed")
  77. beego.Router("/api/patient/saveanticoagulation", &PatientApiController{}, "Post:SaveAnticoagulation")
  78. beego.Router("/api/patient/getanticoagulationInformed", &PatientApiController{}, "Get:GetAnticoagulationInformed")
  79. beego.Router("/api/patient/savecriticalinfomed", &PatientApiController{}, "Post:SaveCriticalInfomed")
  80. beego.Router("/api/patient/getcriticalinformed", &PatientApiController{}, "Get:GetCriticalInformed")
  81. beego.Router("/api/patient/savehemoperfusioninformed", &PatientApiController{}, "Post:SaveHemoperfusionInformed")
  82. beego.Router("/api/patient/gethemoperfusioninformed", &PatientApiController{}, "Get:GetHemoperfusionInformed")
  83. beego.Router("/api/patient/savebringinformed", &PatientApiController{}, "Post:SaveBringInformed")
  84. beego.Router("/api/patient/getinformedcontsent", &PatientApiController{}, "Get:GetInformedContsent")
  85. beego.Router("/api/patient/savecatheterization", &PatientApiController{}, "Post:SaveCatheterization")
  86. beego.Router("/api/patient/getcatheterization", &PatientApiController{}, "Get:GetCatheterization")
  87. beego.Router("/api/patient/savedialyzerInformed", &PatientApiController{}, "Post:SaveDialyzerInformed")
  88. beego.Router("/api/patient/getdialyzerinformed", &PatientApiController{}, "Get:GetDialyzerInformed")
  89. beego.Router("/api/patient/savetheapyinformed", &PatientApiController{}, "Post:SaveTheapyInformed")
  90. beego.Router("/api/patient/savetreamentplan", &PatientApiController{}, "Post:SaveTreatmentPlan")
  91. beego.Router("api/patient/gettherapyinformed", &PatientApiController{}, "Get:GetTherapyInformed")
  92. beego.Router("/api/patient/savemedicalhistory", &PatientApiController{}, "Post:SaveMedicalHistory")
  93. beego.Router("/api/patient/savepatientcritaicalinformed", &PatientApiController{}, "Post:SavePatientCritaicalInformed")
  94. beego.Router("/api/patient/getPatientCriticalList", &PatientApiController{}, "Get:GetPatientCriticalList")
  95. beego.Router("/api/patient/savepatientcriticalcalinformedone", &PatientApiController{}, "Post:SavePatientCriticalInformedOne")
  96. beego.Router("/api/patient/getpatientcriticalonelist", &PatientApiController{}, "Get:GetPatientCriticalOneList")
  97. beego.Router("/api/patient/deletesolution", &PatientApiController{}, "Get:DeleteSolution")
  98. beego.Router("/api/patient/gettreamentplan", &PatientApiController{}, "Get:GetTreatMentPlanList")
  99. }
  100. func (c *PatientApiController) GetExportList() {
  101. startTime := c.GetString("start_time")
  102. endTime := c.GetString("end_time")
  103. schedulType, _ := c.GetInt64("schedul_type", 0)
  104. timeLayout := "2006-01-02"
  105. loc, _ := time.LoadLocation("Local")
  106. adminUserInfo := c.GetAdminUserInfo()
  107. var theStartTIme int64
  108. if len(startTime) > 0 {
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. theStartTIme = theTime.Unix()
  115. }
  116. var theEndtTIme int64
  117. if len(endTime) > 0 {
  118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  119. if err != nil {
  120. utils.ErrorLog(err.Error())
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. return
  123. }
  124. theEndtTIme = theTime.Unix()
  125. }
  126. timeNowStr := time.Now().Format("2006-01-02")
  127. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  128. schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
  129. fmt.Println("schedule23333333333333333", schedule)
  130. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  131. c.ServeSuccessJSON(map[string]interface{}{
  132. "schedule": schedule,
  133. "patientsList": patientsList,
  134. })
  135. return
  136. }
  137. // GetPatientsList 取患者列表
  138. func (c *PatientApiController) GetPatientsList() {
  139. var err error
  140. defer func() {
  141. if rec := recover(); rec != nil {
  142. err = fmt.Errorf("程序异常:%v", rec)
  143. }
  144. if err != nil {
  145. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  146. }
  147. }()
  148. page, _ := c.GetInt64("page", 1)
  149. limit, _ := c.GetInt64("limit", 10)
  150. schedulType, _ := c.GetInt64("schedul_type", 0)
  151. bindingState, _ := c.GetInt64("binding_state", 0)
  152. lapseto, _ := c.GetInt64("lapseto", 0)
  153. source, _ := c.GetInt64("source", 0)
  154. startTime := c.GetString("start_time", "")
  155. endTime := c.GetString("end_time", "")
  156. keywords := c.GetString("keywords", "")
  157. contagion, _ := c.GetInt64("contagion", 0)
  158. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  159. isscheduling, _ := c.GetInt64("isscheduling", 0)
  160. isprescription, _ := c.GetInt64("isprescription", 0)
  161. patientSoureType, _ := c.GetInt64("patientSoureType")
  162. nurse, _ := c.GetInt64("nurse")
  163. if page <= 0 {
  164. page = 1
  165. }
  166. if limit <= 0 {
  167. limit = 10
  168. }
  169. adminUserInfo := c.GetAdminUserInfo()
  170. timeLayout := "2006-01-02"
  171. loc, _ := time.LoadLocation("Local")
  172. var isStartTime bool
  173. var theStartTIme int64
  174. if len(startTime) > 0 {
  175. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  176. if err != nil {
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  178. return
  179. }
  180. isStartTime = true
  181. theStartTIme = theTime.Unix()
  182. }
  183. var isEndTime bool
  184. var theEndtTIme int64
  185. if len(endTime) > 0 {
  186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  187. if err != nil {
  188. utils.ErrorLog(err.Error())
  189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  190. return
  191. }
  192. isEndTime = true
  193. theEndtTIme = theTime.Unix()
  194. }
  195. var patients []*models.Patients
  196. var total int64
  197. 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)
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "patients": patients,
  200. "total": total,
  201. })
  202. return
  203. }
  204. // GetPatientTotal
  205. func (c *PatientApiController) GetPatientTotal() {
  206. adminUserInfo := c.GetAdminUserInfo()
  207. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  208. c.ServeSuccessJSON(map[string]interface{}{
  209. "total": total,
  210. })
  211. return
  212. }
  213. func (c *PatientApiController) GetPatientsAllList() {
  214. adminUserInfo := c.GetAdminUserInfo()
  215. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  216. c.ServeSuccessJSON(map[string]interface{}{
  217. "patients": patients,
  218. "total": total,
  219. })
  220. return
  221. }
  222. // GenerateDialysisNo 生成透析号
  223. func (c *PatientApiController) GenerateDialysisNo() {
  224. adminUserInfo := c.GetAdminUserInfo()
  225. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  226. if dialysisNo == 0 {
  227. dialysisNo = 1
  228. } else {
  229. dialysisNo++
  230. }
  231. no := strconv.FormatInt(dialysisNo, 10)
  232. rep := 3 - len(no)
  233. if rep > 0 {
  234. no = strings.Repeat("0", rep) + no
  235. }
  236. c.ServeSuccessJSON(map[string]interface{}{
  237. "no": no,
  238. })
  239. return
  240. }
  241. // CreatePatient 创建患者
  242. func (c *PatientApiController) CreatePatient() {
  243. record_date := c.GetString("record_date")
  244. is_infectious, _ := c.GetInt64("is_infectious")
  245. remind_cycle, _ := c.GetInt64("remind_cycle")
  246. adminUserInfo := c.GetAdminUserInfo()
  247. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  248. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  249. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  250. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  251. // return
  252. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  254. // return
  255. //}
  256. var patient models.Patients
  257. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  258. if code > 0 {
  259. c.ServeFailJSONWithSGJErrorCode(code)
  260. return
  261. }
  262. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  263. if thisPatient.ID > 0 {
  264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  265. return
  266. }
  267. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  268. if thisPatient.ID > 0 {
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  270. return
  271. }
  272. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  273. if thisPatient.ID > 0 {
  274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  275. return
  276. }
  277. patient.RemindCycle = remind_cycle
  278. patient.IsInfectious = is_infectious
  279. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  280. patient.Status = 1
  281. patient.CreatedTime = time.Now().Unix()
  282. patient.UserOrgId = adminUserInfo.CurrentOrgId
  283. patient.UpdatedTime = time.Now().Unix()
  284. patient.BindingState = 2
  285. // patient.Lapseto = 1
  286. hans := patient.Name // 要转换的汉字字符串
  287. // 创建一个拼音转换器
  288. p := pinyin.NewArgs()
  289. // 将汉字转为拼音
  290. pinyinSlice := pinyin.Pinyin(hans, p)
  291. // 获取首字母
  292. firstLetter := ""
  293. for _, py := range pinyinSlice {
  294. if len(py) > 0 {
  295. firstLetter += string(py[0][0])
  296. }
  297. }
  298. patient.FirstLetter = firstLetter
  299. err := service.CreatePatient(&patient, contagions, diseases)
  300. fmt.Println("创建病人失败err")
  301. if err != nil {
  302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  303. return
  304. }
  305. //获取老表的最后一条数据
  306. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  307. patientsNew := models.XtPatientsNew{
  308. UserOrgId: adminUserInfo.CurrentOrgId,
  309. UserId: 0,
  310. Avatar: patients.Avatar,
  311. PatientType: patients.PatientType,
  312. DialysisNo: patients.DialysisNo,
  313. AdmissionNumber: patients.AdmissionNumber,
  314. Source: patients.Source,
  315. Lapseto: patients.Lapseto,
  316. PartitionId: patients.PartitionId,
  317. BedId: patients.BedId,
  318. Name: patients.Name,
  319. Alias: patients.Alias,
  320. Gender: patients.Gender,
  321. MaritalStatus: patients.MaritalStatus,
  322. IdCardNo: patients.IdCardNo,
  323. Birthday: patients.Birthday,
  324. ReimbursementWayId: patients.ReimbursementWayId,
  325. HealthCareType: patients.HealthCareType,
  326. HealthCareNo: patients.HealthCareNo,
  327. HealthCareDueDate: patients.HealthCareDueDate,
  328. Height: patients.Height,
  329. BloodType: patients.BloodType,
  330. Rh: patients.Rh,
  331. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  332. EducationLevel: patients.EducationLevel,
  333. Profession: patients.Profession,
  334. Phone: patients.Phone,
  335. HomeTelephone: patients.HomeTelephone,
  336. RelativePhone: patients.RelativePhone,
  337. RelativeRelations: patients.RelativeRelations,
  338. HomeAddress: patients.HomeAddress,
  339. WorkUnit: patients.WorkUnit,
  340. UnitAddress: patients.UnitAddress,
  341. Children: patients.Children,
  342. ReceivingDate: patients.ReceivingDate,
  343. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  344. FirstDialysisDate: patients.FirstDialysisDate,
  345. FirstDialysisHospital: patients.FirstDialysisHospital,
  346. PredialysisCondition: patients.PredialysisCondition,
  347. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  348. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  349. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  350. InductionPeriod: patients.InductionPeriod,
  351. InitialDialysis: patients.InitialDialysis,
  352. TotalDialysis: patients.TotalDialysis,
  353. AttendingDoctorId: patients.AttendingDoctorId,
  354. HeadNurseId: patients.HeadNurseId,
  355. Evaluate: patients.Evaluate,
  356. Diagnose: patients.Diagnose,
  357. Remark: patients.Remark,
  358. RegistrarsId: patients.RegistrarsId,
  359. Registrars: patients.Registrars,
  360. QrCode: patients.QrCode,
  361. BindingState: patients.BindingState,
  362. PatientComplains: patients.PatientComplains,
  363. PresentHistory: patients.PresentHistory,
  364. PastHistory: patients.PresentHistory,
  365. Temperature: patients.Temperature,
  366. Pulse: patients.Pulse,
  367. Respiratory: patients.Respiratory,
  368. Sbp: patients.SBP,
  369. Dbp: patients.DBP,
  370. Status: patients.Status,
  371. CreatedTime: patients.CreatedTime,
  372. UpdatedTime: patients.UpdatedTime,
  373. Nation: patients.Nation,
  374. NativePlace: patients.NativePlace,
  375. Age: patients.Age,
  376. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  377. IsInfectious: patients.IsInfectious,
  378. RemindCycle: patients.RemindCycle,
  379. ResponseResult: patients.ResponseResult,
  380. IsOpenRemind: patients.IsOpenRemind,
  381. FirstTreatmentDate: patients.FirstTreatmentDate,
  382. DialysisAge: patients.DialysisAge,
  383. ExpenseKind: patients.ExpenseKind,
  384. TellPhone: patients.TellPhone,
  385. ContactName: patients.ContactName,
  386. BloodPatients: 1,
  387. SlowPatients: 0,
  388. MemberPatients: 0,
  389. EcommerPatients: "",
  390. BloodId: patients.ID,
  391. SlowId: 0,
  392. MemberId: 0,
  393. MemberFistdate: 0,
  394. MemberPatienttype: 0,
  395. MemberTreatement: 0,
  396. EquitmentId: "",
  397. UserSysBeforeCount: patient.UserSysBeforeCount,
  398. TrobleShoot: patient.TrobleShoot,
  399. TreatmentPlan: patient.TreatmentPlan,
  400. Doctor: patient.Doctor,
  401. RecordNumber: patient.RecordNumber,
  402. PatientSource: patient.PatientSource,
  403. PatientEndTime: patient.PatientEndTime,
  404. PatientStartTime: patient.PatientStartTime,
  405. InfectiousRemark: patient.InfectiousRemark,
  406. AllergicHistory: patient.AllergicHistory,
  407. PatientAddress: patient.PatientAddress,
  408. PrintDate: patient.PrintDate,
  409. }
  410. patientsNew.FirstLetter = firstLetter
  411. err = service.CreatePatientsNew(&patientsNew)
  412. fmt.Print("创建失败", err)
  413. allergic := models.XtPatientAllergic{
  414. UserOrgId: adminUserInfo.CurrentOrgId,
  415. PatientId: patient.ID,
  416. StartTime: patient.PatientStartTime,
  417. EndTime: patient.PatientEndTime,
  418. PatientSource: patient.PatientSource,
  419. PatientAddress: patient.PatientAddress,
  420. Remake: patient.Remark,
  421. Status: 1,
  422. Ctime: time.Now().Unix(),
  423. }
  424. if len(patient.PatientAddress) > 0 {
  425. service.CreateAllergic(allergic)
  426. }
  427. if len(record_date) > 0 {
  428. var recordTime int64
  429. timeLayout := "2006-01-02"
  430. loc, _ := time.LoadLocation("Local")
  431. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  432. if err != nil {
  433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  434. return
  435. }
  436. recordTime = theTime.Unix()
  437. inspections := make([]models.Inspection, 0)
  438. for _, item := range formItems {
  439. var inspection models.Inspection
  440. inspection.OrgId = adminUserInfo.CurrentOrgId
  441. inspection.PatientId = patient.ID
  442. inspection.ProjectId = item.ProjectId
  443. inspection.ItemId = item.ItemId
  444. inspection.ItemName = item.ItemName
  445. inspection.ProjectName = item.ProjectName
  446. inspection.InspectType = item.RangeType
  447. inspection.InspectValue = item.Value
  448. inspection.InspectDate = recordTime
  449. inspection.Status = 1
  450. inspection.CreatedTime = time.Now().Unix()
  451. inspection.UpdatedTime = time.Now().Unix()
  452. inspections = append(inspections, inspection)
  453. }
  454. err = service.CreatePatientInspection(inspections)
  455. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  456. var record_time int64
  457. switch remind_cycle {
  458. case 1: //1个月
  459. ts := time.Unix(infectiousRecord.InspectDate, 0)
  460. record_time = ts.AddDate(0, 1, 0).Unix()
  461. break
  462. case 2: //2个月
  463. ts := time.Unix(infectiousRecord.InspectDate, 0)
  464. record_time = ts.AddDate(0, 2, 0).Unix()
  465. break
  466. case 3: //3个月
  467. ts := time.Unix(infectiousRecord.InspectDate, 0)
  468. record_time = ts.AddDate(0, 3, 0).Unix()
  469. break
  470. case 4: //6个月
  471. ts := time.Unix(infectiousRecord.InspectDate, 0)
  472. record_time = ts.AddDate(0, 6, 0).Unix()
  473. break
  474. case 5: //12个月
  475. ts := time.Unix(infectiousRecord.InspectDate, 0)
  476. record_time = ts.AddDate(0, 12, 0).Unix()
  477. break
  478. }
  479. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  480. if errs != nil {
  481. utils.ErrorLog("更新日期出错:%v", errs)
  482. }
  483. }
  484. redis := service.RedisClient()
  485. defer redis.Close()
  486. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  487. c.ServeSuccessJSON(map[string]interface{}{
  488. "msg": "ok",
  489. })
  490. return
  491. }
  492. // EditPatient 修改
  493. func (c *PatientApiController) EditPatient() {
  494. id, _ := c.GetInt64("id", 0)
  495. record_date := c.GetString("record_date")
  496. is_infectious, _ := c.GetInt64("is_infectious")
  497. remind_cycle, _ := c.GetInt64("remind_cycle")
  498. if id <= 0 {
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. adminUserInfo := c.GetAdminUserInfo()
  503. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  504. if patient.ID == 0 {
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  506. return
  507. }
  508. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  509. if code > 0 {
  510. c.ServeFailJSONWithSGJErrorCode(code)
  511. return
  512. }
  513. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  514. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  516. return
  517. }
  518. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  519. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  521. return
  522. }
  523. patient.UpdatedTime = time.Now().Unix()
  524. patient.IsInfectious = is_infectious
  525. patient.RemindCycle = remind_cycle
  526. err := service.UpdatePatient(&patient, contagions, diseases)
  527. if err != nil {
  528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  529. return
  530. }
  531. ////更新转归状态
  532. //lapseto := models.PatientLapseto{
  533. // LapsetoType: patient.Lapseto,
  534. // LapsetoTime: time.Now().Unix(),
  535. // UpdatedTime: time.Now().Unix(),
  536. //}
  537. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  538. //fmt.Println("更新转归失败", err)
  539. if err != nil {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  541. return
  542. }
  543. patientsNew := models.XtPatientsNew{
  544. UserOrgId: patient.UserOrgId,
  545. UserId: patient.UserId,
  546. Avatar: patient.Avatar,
  547. PatientType: patient.PatientType,
  548. DialysisNo: patient.DialysisNo,
  549. AdmissionNumber: patient.AdmissionNumber,
  550. Source: patient.Source,
  551. PartitionId: patient.PartitionId,
  552. BedId: patient.BedId,
  553. Name: patient.Name,
  554. Alias: patient.Alias,
  555. Gender: patient.Gender,
  556. MaritalStatus: patient.MaritalStatus,
  557. IdCardNo: patient.IdCardNo,
  558. Birthday: patient.Birthday,
  559. ReimbursementWayId: patient.ReimbursementWayId,
  560. HealthCareType: patient.HealthCareType,
  561. HealthCareNo: patient.HealthCareNo,
  562. HealthCareDueDate: patient.HealthCareDueDate,
  563. Height: patient.Height,
  564. BloodType: patient.BloodType,
  565. Rh: patient.Rh,
  566. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  567. EducationLevel: patient.EducationLevel,
  568. Profession: patient.Profession,
  569. Phone: patient.Phone,
  570. HomeTelephone: patient.HomeTelephone,
  571. RelativePhone: patient.RelativePhone,
  572. RelativeRelations: patient.RelativeRelations,
  573. HomeAddress: patient.HomeAddress,
  574. WorkUnit: patient.WorkUnit,
  575. UnitAddress: patient.UnitAddress,
  576. Children: patient.Children,
  577. ReceivingDate: patient.ReceivingDate,
  578. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  579. FirstDialysisDate: patient.FirstDialysisDate,
  580. FirstDialysisHospital: patient.FirstDialysisHospital,
  581. PredialysisCondition: patient.PredialysisCondition,
  582. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  583. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  584. InductionPeriod: patient.InductionPeriod,
  585. InitialDialysis: patient.InitialDialysis,
  586. TotalDialysis: patient.TotalDialysis,
  587. AttendingDoctorId: patient.AttendingDoctorId,
  588. HeadNurseId: patient.HeadNurseId,
  589. Evaluate: patient.Evaluate,
  590. Diagnose: patient.Diagnose,
  591. Remark: patient.Remark,
  592. RegistrarsId: patient.RegistrarsId,
  593. Registrars: patient.Registrars,
  594. QrCode: patient.QrCode,
  595. BindingState: patient.BindingState,
  596. PatientComplains: patient.PatientComplains,
  597. PresentHistory: patient.PresentHistory,
  598. PastHistory: patient.PastHistory,
  599. Temperature: patient.Temperature,
  600. Pulse: patient.Pulse,
  601. Respiratory: patient.Respiratory,
  602. Sbp: patient.SBP,
  603. Dbp: patient.DBP,
  604. Nation: patient.Nation,
  605. NativePlace: patient.NativePlace,
  606. Age: patient.Age,
  607. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  608. IsInfectious: patient.IsInfectious,
  609. RemindCycle: patient.RemindCycle,
  610. ResponseResult: patient.ResponseResult,
  611. IsOpenRemind: patient.IsOpenRemind,
  612. FirstTreatmentDate: patient.FirstTreatmentDate,
  613. DialysisAge: patient.DialysisAge,
  614. ExpenseKind: patient.ExpenseKind,
  615. TellPhone: patient.TellPhone,
  616. ContactName: patient.ContactName,
  617. UpdatedTime: time.Now().Unix(),
  618. BloodPatients: 1,
  619. Lapseto: patient.Lapseto,
  620. TrobleShoot: patient.TrobleShoot,
  621. SchRemark: patient.SchRemark,
  622. TreatmentPlan: patient.TreatmentPlan,
  623. RecordNumber: patient.RecordNumber,
  624. PatientSource: patient.PatientSource,
  625. PatientStartTime: patient.PatientStartTime,
  626. PatientEndTime: patient.PatientEndTime,
  627. InfectiousRemark: patient.InfectiousRemark,
  628. AllergicHistory: patient.AllergicHistory,
  629. PatientAddress: patient.PatientAddress,
  630. PrintDate: patient.PrintDate,
  631. }
  632. // //更新病人ID获取新表病人ID
  633. err = service.UpdatepatientTwo(&patientsNew, id)
  634. allergic := models.XtPatientAllergic{
  635. PatientId: patient.ID,
  636. UserOrgId: adminUserInfo.CurrentOrgId,
  637. StartTime: patient.PatientStartTime,
  638. EndTime: patient.PatientEndTime,
  639. PatientSource: patient.PatientSource,
  640. Status: 1,
  641. Ctime: time.Now().Unix(),
  642. Mtime: time.Now().Unix(),
  643. Remake: patient.Remark,
  644. PatientAddress: patient.PatientAddress,
  645. }
  646. if len(patient.PatientAddress) > 0 {
  647. service.CreateAllergic(allergic)
  648. }
  649. nowTimeUinx := time.Now()
  650. today := nowTimeUinx.Format("2006-01-02")
  651. redis := service.RedisClient()
  652. defer redis.Close()
  653. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  654. redis.Set(key, "", time.Second*60*60*18)
  655. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  656. redis.Set(keyOne, "", time.Second*60*60*18)
  657. if len(record_date) > 0 {
  658. var recordTime int64
  659. timeLayout := "2006-01-02"
  660. loc, _ := time.LoadLocation("Local")
  661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  662. if err != nil {
  663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  664. return
  665. }
  666. recordTime = theTime.Unix()
  667. inspections := make([]models.Inspection, 0)
  668. for _, item := range formItems {
  669. var inspection models.Inspection
  670. inspection.OrgId = adminUserInfo.CurrentOrgId
  671. inspection.PatientId = patient.ID
  672. inspection.ProjectId = item.ProjectId
  673. inspection.ItemId = item.ItemId
  674. inspection.ItemName = item.ItemName
  675. inspection.ProjectName = item.ProjectName
  676. inspection.InspectType = item.RangeType
  677. inspection.InspectValue = item.Value
  678. inspection.InspectDate = recordTime
  679. inspection.Status = 1
  680. inspection.CreatedTime = time.Now().Unix()
  681. inspection.UpdatedTime = time.Now().Unix()
  682. inspections = append(inspections, inspection)
  683. }
  684. err = service.CreatePatientInspection(inspections)
  685. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  686. var record_time int64
  687. switch remind_cycle {
  688. case 1: //1个月
  689. ts := time.Unix(infectiousRecord.InspectDate, 0)
  690. record_time = ts.AddDate(0, 1, 0).Unix()
  691. break
  692. case 2: //2个月
  693. ts := time.Unix(infectiousRecord.InspectDate, 0)
  694. record_time = ts.AddDate(0, 2, 0).Unix()
  695. break
  696. case 3: //3个月
  697. ts := time.Unix(infectiousRecord.InspectDate, 0)
  698. record_time = ts.AddDate(0, 3, 0).Unix()
  699. break
  700. case 4: //6个月
  701. ts := time.Unix(infectiousRecord.InspectDate, 0)
  702. record_time = ts.AddDate(0, 6, 0).Unix()
  703. break
  704. case 5: //12个月
  705. ts := time.Unix(infectiousRecord.InspectDate, 0)
  706. record_time = ts.AddDate(0, 12, 0).Unix()
  707. break
  708. }
  709. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  710. if errs != nil {
  711. utils.ErrorLog("更新日期出错:%v", errs)
  712. }
  713. }
  714. c.ServeSuccessJSON(map[string]interface{}{
  715. "msg": "ok",
  716. })
  717. return
  718. }
  719. func (c *PatientApiController) EditLapseto() {
  720. id, _ := c.GetInt64("id", 0)
  721. if id <= 0 {
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. start_time := c.GetString("start_time")
  726. end_time := c.GetString("end_time")
  727. timeLayout := "2006-01-02"
  728. loc, _ := time.LoadLocation("Local")
  729. var startTime int64
  730. if len(start_time) > 0 {
  731. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  732. if err != nil {
  733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  734. return
  735. }
  736. startTime = theTime.Unix()
  737. }
  738. var endTime int64
  739. if len(end_time) > 0 {
  740. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  741. if err != nil {
  742. utils.ErrorLog(err.Error())
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  744. return
  745. }
  746. endTime = theTime.Unix()
  747. }
  748. patient_address := c.GetString("patient_address")
  749. adminUserInfo := c.GetAdminUserInfo()
  750. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  751. if patient.ID == 0 {
  752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  753. return
  754. }
  755. patientBody := make(map[string]interface{}, 0)
  756. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  757. if err != nil {
  758. utils.ErrorLog(err.Error())
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  760. return
  761. }
  762. var lapseto models.PatientLapseto
  763. lapseto.PatientId = patient.ID
  764. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  765. utils.ErrorLog("lapseto_type")
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  767. return
  768. }
  769. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  770. lapseto.LapsetoType = lapsetoType
  771. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  772. utils.ErrorLog("lapseto_time")
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  774. return
  775. }
  776. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  777. //if len(lapsetoTime) == 0 {
  778. // utils.ErrorLog("len(lapsetoTime) == 0")
  779. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  780. // return
  781. //}
  782. out_reason, _ := patientBody["out_reason"].(string)
  783. //if len(out_reason) == 0 {
  784. // utils.ErrorLog("len(out_reason) == 0")
  785. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  786. // return
  787. //}
  788. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  789. //if err != nil {
  790. // utils.ErrorLog("lapsetoTimeUnix")
  791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  792. // return
  793. //}
  794. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  795. lapseto.UpdatedTime = time.Now().Unix()
  796. lapseto.CreatedTime = time.Now().Unix()
  797. lapseto.Status = 1
  798. patient.Lapseto = lapseto.LapsetoType
  799. patient.OutReason = out_reason
  800. patient.DeathTime = lapsetoTimeUnix.Unix()
  801. patient.PatientStartTime = startTime
  802. patient.PatientEndTime = endTime
  803. patient.PatientAddress = patient_address
  804. //if patient.Lapseto == 1 {
  805. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  806. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  807. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  809. // return
  810. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  812. // return
  813. // }
  814. //}
  815. err = service.EditPatientLapseto(&patient, &lapseto)
  816. if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  817. fmt.Println("lapsetoTimeUnix.Unix()", lapsetoTimeUnix.Unix())
  818. if adminUserInfo.CurrentOrgId == 10340 {
  819. service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
  820. service.UpdateScheduleItemByPatientId(id)
  821. } else {
  822. timeStr := time.Now().Format("2006-01-02")
  823. timeLayout := "2006-01-02 15:04:05"
  824. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  825. timenow := timeStringToTime.Unix()
  826. service.UpdateScheduleByDeathTime(id, timenow)
  827. service.UpdateScheduleItemByPatientId(id)
  828. }
  829. }
  830. allergic := models.XtPatientAllergic{
  831. UserOrgId: adminUserInfo.CurrentOrgId,
  832. PatientId: patient.ID,
  833. StartTime: patient.PatientStartTime,
  834. EndTime: patient.PatientEndTime,
  835. PatientSource: patient.Lapseto,
  836. PatientAddress: patient.PatientAddress,
  837. Remake: patient.Remark,
  838. Status: 1,
  839. Ctime: time.Now().Unix(),
  840. }
  841. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  842. allergic.StartTime = lapseto.LapsetoTime
  843. allergic.EndTime = lapseto.LapsetoTime
  844. }
  845. service.CreateAllergic(allergic)
  846. if err != nil {
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  848. return
  849. }
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "msg": "ok",
  852. })
  853. return
  854. }
  855. func (c *PatientApiController) GetPatient() {
  856. id, _ := c.GetInt64("id", 0)
  857. if id <= 0 {
  858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  859. return
  860. }
  861. adminUserInfo := c.GetAdminUserInfo()
  862. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  863. if patient.ID == 0 {
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  865. return
  866. }
  867. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  868. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  869. diseases := service.GetPatientDiseases(patient.ID)
  870. contagions := service.GetPatientContagions(patient.ID)
  871. c.ServeSuccessJSON(map[string]interface{}{
  872. "patient": patient,
  873. "diseases": diseases,
  874. "contagions": contagions,
  875. "infections": infections,
  876. })
  877. return
  878. }
  879. func (c *PatientApiController) CreateDialysisSolution() {
  880. id, _ := c.GetInt64("patient", 0)
  881. if id <= 0 {
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  883. return
  884. }
  885. adminUserInfo := c.GetAdminUserInfo()
  886. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  887. if patient.ID == 0 {
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  889. return
  890. }
  891. var solution models.DialysisSolution
  892. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  893. if code > 0 {
  894. c.ServeFailJSONWithSGJErrorCode(code)
  895. return
  896. }
  897. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  898. //if thisSolution.ID > 0 {
  899. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  900. // return
  901. //}
  902. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  903. solution.Doctor = adminUserInfo.AdminUser.Id
  904. solution.Status = 1
  905. solution.PatientId = id
  906. solution.CreatedTime = time.Now().Unix()
  907. solution.UserOrgId = adminUserInfo.CurrentOrgId
  908. solution.UpdatedTime = time.Now().Unix()
  909. solution.SubName = ""
  910. solution.ParentId = 0
  911. solution.SolutionStatus = 1
  912. //records, _ := service.GetAllSchedules()
  913. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  914. for _, sch := range schs {
  915. var DialysisMachineName string
  916. if len(solution.DialysisDialyszers) > 0 {
  917. DialysisMachineName = solution.DialysisDialyszers
  918. }
  919. if len(solution.DialyzerPerfusionApparatus) > 0 {
  920. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  921. }
  922. if len(solution.DialysisIrrigation) > 0 {
  923. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  924. }
  925. if len(solution.DialysisStrainer) > 0 {
  926. DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
  927. }
  928. sch.DialysisMachineName = DialysisMachineName
  929. service.UpdateSch(sch)
  930. }
  931. err := service.CreatePatientDialysisSolution(&solution)
  932. //获取最新1条
  933. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  934. //更新状态
  935. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  936. if err != nil {
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  938. return
  939. }
  940. c.ServeSuccessJSON(map[string]interface{}{
  941. "msg": "ok",
  942. "solution": solution,
  943. })
  944. return
  945. }
  946. func (c *PatientApiController) UpdateDialysisSolution() {
  947. patient, _ := c.GetInt64("patient", 0)
  948. id, _ := c.GetInt64("id", 0)
  949. if id <= 0 || patient <= 0 {
  950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  951. return
  952. }
  953. adminUserInfo := c.GetAdminUserInfo()
  954. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  955. if solution.ID == 0 || solution.PatientId != patient {
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  957. return
  958. }
  959. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  960. if code > 0 {
  961. c.ServeFailJSONWithSGJErrorCode(code)
  962. return
  963. }
  964. solution.UpdatedTime = time.Now().Unix()
  965. err := service.UpdatePatientDialysisSolution(&solution)
  966. nowTimeUinx := time.Now()
  967. today := nowTimeUinx.Format("2006-01-02")
  968. timeLayout := "2006-01-02"
  969. loc, _ := time.LoadLocation("Local")
  970. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  971. if adminUserInfo.CurrentOrgId == 9538 || adminUserInfo.CurrentOrgId == 10164 {
  972. prescription := models.DialysisPrescription{
  973. Dialyzer: solution.Dialyzer,
  974. Anticoagulant: solution.Anticoagulant,
  975. AnticoagulantShouji: solution.AnticoagulantShouji,
  976. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  977. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  978. ModeId: solution.ModeId,
  979. DialysisDurationHour: solution.DialysisDurationHour,
  980. Kalium: solution.Kalium,
  981. Sodium: solution.Sodium,
  982. Calcium: solution.Calcium,
  983. TargetUltrafiltration: solution.TargetUltrafiltration,
  984. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  985. BloodAccess: solution.BloodAccess,
  986. DialysateFlow: solution.DialysateFlow,
  987. DialysateTemperature: solution.DialysateTemperature,
  988. DialysisIrrigation: solution.DialysisIrrigation,
  989. DialysisDialyszers: solution.DialysisDialyszers,
  990. PlasmaSeparator: solution.PlasmaSeparator,
  991. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  992. OxygenUptake: solution.OxygenUptake,
  993. OxygenFlow: solution.OxygenFlow,
  994. OxygenTime: solution.OxygenTime,
  995. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  996. Amylaceum: solution.Amylaceum,
  997. DialysisStrainer: solution.DialysisStrainer,
  998. Chaptalization: solution.Chaptalization,
  999. BloodAccessPartId: solution.BloodAccessPartId,
  1000. }
  1001. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  1002. }
  1003. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  1004. for _, sch := range schs {
  1005. var DialysisMachineName string
  1006. if len(solution.DialysisDialyszers) > 0 {
  1007. DialysisMachineName = solution.DialysisDialyszers
  1008. }
  1009. if len(solution.DialyzerPerfusionApparatus) > 0 {
  1010. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  1011. }
  1012. if len(solution.DialysisIrrigation) > 0 {
  1013. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  1014. }
  1015. if len(solution.DialysisStrainer) > 0 {
  1016. DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
  1017. }
  1018. sch.DialysisMachineName = DialysisMachineName
  1019. service.UpdateSch(sch)
  1020. }
  1021. if err != nil {
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  1023. return
  1024. }
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "msg": "ok",
  1027. "solution": solution,
  1028. })
  1029. return
  1030. }
  1031. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  1032. patient, _ := c.GetInt64("patient", 0)
  1033. id, _ := c.GetInt64("id", 0)
  1034. if id <= 0 || patient <= 0 {
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. adminUserInfo := c.GetAdminUserInfo()
  1039. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1040. if solution.ID == 0 || solution.PatientId != patient {
  1041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1042. return
  1043. }
  1044. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  1045. if code > 0 {
  1046. c.ServeFailJSONWithSGJErrorCode(code)
  1047. return
  1048. }
  1049. solution.UpdatedTime = time.Now().Unix()
  1050. solution.AffirmState = 1
  1051. err := service.UpdatePatientDialysisSolution(&solution)
  1052. if err != nil {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  1054. return
  1055. }
  1056. c.ServeSuccessJSON(map[string]interface{}{
  1057. "msg": "ok",
  1058. "solution": solution,
  1059. })
  1060. return
  1061. }
  1062. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1063. id, _ := c.GetInt64("id", 0)
  1064. page, _ := c.GetInt64("page", 0)
  1065. limit, _ := c.GetInt64("limit", 0)
  1066. if id <= 0 {
  1067. c.ServeSuccessJSON(map[string]interface{}{
  1068. "solutions": nil,
  1069. })
  1070. return
  1071. }
  1072. if page <= 0 {
  1073. page = 1
  1074. }
  1075. if limit <= 0 {
  1076. limit = 10
  1077. }
  1078. adminUserInfo := c.GetAdminUserInfo()
  1079. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  1080. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  1081. c.ServeSuccessJSON(map[string]interface{}{
  1082. "solutions": solutions,
  1083. "total": total,
  1084. "stockType": stockType,
  1085. })
  1086. return
  1087. }
  1088. func (c *PatientApiController) DeleteDialysisSolution() {
  1089. id, _ := c.GetInt64("id", 0)
  1090. if id <= 0 {
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1092. return
  1093. }
  1094. adminUserInfo := c.GetAdminUserInfo()
  1095. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1096. if solution.ID == 0 {
  1097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1098. return
  1099. }
  1100. if solution.UseState == 1 {
  1101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  1102. return
  1103. }
  1104. solution.UpdatedTime = time.Now().Unix()
  1105. solution.Status = 0
  1106. err := service.DeleteSolution(&solution)
  1107. if err != nil {
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  1109. return
  1110. }
  1111. c.ServeSuccessJSON(map[string]interface{}{
  1112. "msg": "ok",
  1113. })
  1114. return
  1115. }
  1116. // GetDryWeights 取患者干体重调整铺
  1117. func (c *PatientApiController) GetDryWeights() {
  1118. page, _ := c.GetInt64("page", 1)
  1119. limit, _ := c.GetInt64("limit", 10)
  1120. id, _ := c.GetInt64("id", 0)
  1121. if id <= 0 {
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. adminUserInfo := c.GetAdminUserInfo()
  1126. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  1127. c.ServeSuccessJSON(map[string]interface{}{
  1128. "weights": weights,
  1129. "total": total,
  1130. })
  1131. return
  1132. }
  1133. func (c *PatientApiController) CreateDryWeights() {
  1134. patient, _ := c.GetInt64("id", 0)
  1135. if patient <= 0 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1137. return
  1138. }
  1139. adminUserInfo := c.GetAdminUserInfo()
  1140. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1141. if patientInfo.ID == 0 {
  1142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1143. return
  1144. }
  1145. var theWeight models.DryWeightAdjust
  1146. dataBody := make(map[string]interface{}, 0)
  1147. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1148. if err != nil {
  1149. utils.ErrorLog(err.Error())
  1150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1151. return
  1152. }
  1153. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1155. return
  1156. }
  1157. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  1158. theWeight.Weight = weight
  1159. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  1160. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. // return
  1162. // }
  1163. // doctor := int64(dataBody["doctor"].(float64))
  1164. // theWeight.Doctor = doctor
  1165. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1166. remark, _ := dataBody["remark"].(string)
  1167. theWeight.Remark = remark
  1168. }
  1169. theWeight.CreatedTime = time.Now().Unix()
  1170. theWeight.UpdatedTime = time.Now().Unix()
  1171. theWeight.Status = 1
  1172. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  1173. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  1174. theWeight.PatientId = patient
  1175. theWeight.Doctor = adminUserInfo.AdminUser.Id
  1176. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  1177. if old.ID > 0 {
  1178. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1179. }
  1180. err = service.CreateDryWeightAdjust(&theWeight)
  1181. if err != nil {
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1183. return
  1184. }
  1185. c.ServeSuccessJSON(map[string]interface{}{
  1186. "msg": "ok",
  1187. "weight": theWeight,
  1188. })
  1189. return
  1190. }
  1191. func (c *PatientApiController) CreateGroupAdvice() {
  1192. var err error
  1193. defer func() {
  1194. if rec := recover(); rec != nil {
  1195. err = fmt.Errorf("程序异常:%v", rec)
  1196. }
  1197. if err != nil {
  1198. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1199. }
  1200. }()
  1201. patient, _ := c.GetInt64("id", 0)
  1202. groupNo, _ := c.GetInt64("groupno", 0)
  1203. if patient <= 0 {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. adminUserInfo := c.GetAdminUserInfo()
  1208. var patientInfo models.Patients
  1209. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1210. if patientInfo.ID == 0 {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1212. return
  1213. }
  1214. dataBody := make(map[string]interface{}, 0)
  1215. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1216. if err != nil {
  1217. utils.ErrorLog(err.Error())
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. utils.ErrorLog("%v", dataBody)
  1222. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1223. if appRole.UserType == 3 {
  1224. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1225. if getPermissionErr != nil {
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1227. return
  1228. } else if headNursePermission == nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1230. return
  1231. }
  1232. }
  1233. timeLayout := "2006-01-02"
  1234. loc, _ := time.LoadLocation("Local")
  1235. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1236. utils.ErrorLog("advice_type")
  1237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1238. return
  1239. }
  1240. adviceType := int64(dataBody["advice_type"].(float64))
  1241. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1242. utils.ErrorLog("advice_type != 1&&2")
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1247. utils.ErrorLog("advice_date")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1252. utils.ErrorLog("start_time")
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. startTime2, _ := dataBody["start_time"].(string)
  1257. time_arr := strings.Split(startTime2, " ")
  1258. if len(time_arr) > 0 {
  1259. startTime2 = time_arr[0]
  1260. }
  1261. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1262. utils.ErrorLog("advice_date")
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1264. return
  1265. }
  1266. adviceDate := startTime2
  1267. if len(adviceDate) == 0 {
  1268. utils.ErrorLog("len(adviceDate) == 0")
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1270. return
  1271. }
  1272. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1273. if err != nil {
  1274. utils.ErrorLog(err.Error())
  1275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1276. return
  1277. }
  1278. AdviceDate := theTime.Unix()
  1279. RecordDate := theTime.Unix()
  1280. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1281. utils.ErrorLog("start_time")
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1283. return
  1284. }
  1285. startTime, _ := dataBody["start_time"].(string)
  1286. if len(startTime) == 0 {
  1287. utils.ErrorLog("len(start_time) == 0")
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1289. return
  1290. }
  1291. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1292. if err != nil {
  1293. utils.ErrorLog(err.Error())
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1295. return
  1296. }
  1297. StartTime := theTime.Unix()
  1298. Remark := ""
  1299. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1300. remark, _ := dataBody["remark"].(string)
  1301. Remark = remark
  1302. }
  1303. var advices []*models.GroupAdvice
  1304. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1305. utils.ErrorLog("adviceNames")
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. adviceNames := dataBody["adviceNames"].([]interface{})
  1310. for _, adviceNameMap := range adviceNames {
  1311. adviceNameM := adviceNameMap.(map[string]interface{})
  1312. var advice models.GroupAdvice
  1313. advice.Remark = Remark
  1314. advice.AdviceType = adviceType
  1315. advice.StartTime = StartTime
  1316. advice.AdviceDate = AdviceDate
  1317. advice.RecordDate = RecordDate
  1318. advice.Status = 1
  1319. advice.CreatedTime = time.Now().Unix()
  1320. advice.UpdatedTime = time.Now().Unix()
  1321. advice.StopState = 2
  1322. advice.ExecutionState = 2
  1323. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1324. advice.PatientId = patientInfo.ID
  1325. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1326. advice.IsSettle = 2
  1327. //创建步骤表
  1328. finish := models.XtDialysisFinish{
  1329. IsFinish: 1,
  1330. UserOrgId: adminUserInfo.CurrentOrgId,
  1331. Status: 1,
  1332. Ctime: time.Now().Unix(),
  1333. Mtime: 0,
  1334. Module: 4,
  1335. RecordDate: advice.RecordDate,
  1336. Sourse: 1,
  1337. PatientId: patient,
  1338. }
  1339. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
  1340. if dialysisFinish.ID == 0 {
  1341. service.CreateDialysisFinish(finish)
  1342. }
  1343. // 查询信息规挡的设置天数
  1344. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1345. if infor.ID > 0 && infor.WeekDay > 0 {
  1346. var cha_time int64
  1347. timeNowStr := time.Now().Format("2006-01-02")
  1348. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1349. //今日的日期减去设置的日期
  1350. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1351. if cha_time >= advice.AdviceDate {
  1352. //查询审核是否允许
  1353. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1354. //申请状态不允许的情况 拒绝修改
  1355. if infor.ApplicationStatus != 1 {
  1356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1357. return
  1358. }
  1359. }
  1360. }
  1361. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1362. utils.ErrorLog("advice_name")
  1363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1364. return
  1365. }
  1366. adviceName, _ := adviceNameM["advice_name"].(string)
  1367. if len(adviceName) == 0 {
  1368. utils.ErrorLog("len(advice_name) == 0")
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. advice.AdviceName = adviceName
  1373. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1374. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1375. advice.DrugSpec = drugSpec
  1376. }
  1377. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1378. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1379. advice.AdviceDesc = adviceDesc
  1380. }
  1381. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1382. template_id, _ := adviceNameM["template_id"].(string)
  1383. advice.TemplateId = template_id
  1384. }
  1385. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1386. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1387. advice.DrugSpecUnit = drugSpecUnit
  1388. }
  1389. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1390. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1391. advice.SingleDose = singleDose
  1392. }
  1393. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1394. singleDose := adviceNameM["single_dose"].(float64)
  1395. advice.SingleDose = singleDose
  1396. }
  1397. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1398. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1399. advice.SingleDoseUnit = singleDoseUnit
  1400. }
  1401. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1402. tmp := adviceNameM["single_dose_unit"].(float64)
  1403. singleDoseUnit := service.TypeConversion(tmp)
  1404. advice.SingleDoseUnit = singleDoseUnit
  1405. }
  1406. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1407. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1408. advice.PrescribingNumber = prescribingNumber
  1409. }
  1410. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1411. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1412. advice.PrescribingNumber = prescribingNumber
  1413. }
  1414. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1415. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1416. advice.PrescribingNumberUnit = prescribingNumberUnit
  1417. }
  1418. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1419. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1420. advice.DeliveryWay = deliveryWay
  1421. }
  1422. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1423. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1424. advice.ExecutionFrequency = executionFrequency
  1425. }
  1426. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1427. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1428. advice.Way = int64(way)
  1429. }
  1430. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1431. way := int64(adviceNameM["way"].(float64))
  1432. advice.Way = way
  1433. }
  1434. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1435. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1436. advice.DrugId = int64(drug_id)
  1437. }
  1438. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1439. drug_id := int64(adviceNameM["drug_id"].(float64))
  1440. advice.DrugId = drug_id
  1441. }
  1442. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1443. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1444. advice.DrugNameId = drug_name_id
  1445. }
  1446. remark, _ := adviceNameM["remark"].(string)
  1447. advice.Remark = remark
  1448. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1449. if advice.PrescribingNumber == 0 {
  1450. advice.PrescribingNumber = 1
  1451. }
  1452. //查询该患者今日有没有双人核对
  1453. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1454. fmt.Println("chek", check)
  1455. if check.ID > 0 {
  1456. advice.Checker = check.Modifier
  1457. advice.CheckState = 1
  1458. advice.CheckTime = time.Now().Unix()
  1459. }
  1460. }
  1461. if adviceType == 1 {
  1462. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1463. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1464. advice.FrequencyType = frequency_type
  1465. }
  1466. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1467. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1468. advice.DayCount = day_count
  1469. }
  1470. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1471. week_day, _ := adviceNameM["week_days"].(string)
  1472. advice.WeekDay = week_day
  1473. }
  1474. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1475. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1476. var startTime int64
  1477. if len(push_start_time) > 0 {
  1478. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1479. startTime = theTime.Unix()
  1480. }
  1481. advice.PushStartTime = startTime
  1482. }
  1483. }
  1484. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1485. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1486. advice.ExecutionFrequency = executionFrequency
  1487. }
  1488. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1489. children := adviceNameM["children"].([]interface{})
  1490. if len(children) > 0 {
  1491. for _, childrenMap := range children {
  1492. childMap := childrenMap.(map[string]interface{})
  1493. var child models.GroupAdvice
  1494. child.Remark = Remark
  1495. child.AdviceType = adviceType
  1496. child.StartTime = StartTime
  1497. child.AdviceDate = AdviceDate
  1498. child.RecordDate = RecordDate
  1499. child.Status = 1
  1500. child.CreatedTime = time.Now().Unix()
  1501. child.UpdatedTime = time.Now().Unix()
  1502. child.StopState = 2
  1503. child.ExecutionState = 2
  1504. child.UserOrgId = adminUserInfo.CurrentOrgId
  1505. child.PatientId = patientInfo.ID
  1506. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1507. child.IsSettle = 2
  1508. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1509. utils.ErrorLog("child advice_name")
  1510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1511. return
  1512. }
  1513. childAdviceName, _ := childMap["advice_name"].(string)
  1514. if len(childAdviceName) == 0 {
  1515. utils.ErrorLog("len(child advice_name) == 0")
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1517. return
  1518. }
  1519. child.AdviceName = childAdviceName
  1520. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1521. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1522. child.AdviceDesc = childAdviceDesc
  1523. }
  1524. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1525. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1526. child.DrugSpec = childDrugSpec
  1527. }
  1528. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1529. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1530. child.DrugSpecUnit = childDrugSpecUnit
  1531. }
  1532. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1533. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1534. child.SingleDose = childSingleDose
  1535. }
  1536. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1537. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1538. child.SingleDoseUnit = childSingleDoseUnit
  1539. }
  1540. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1541. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1542. child.PrescribingNumber = childPrescribingNumber
  1543. }
  1544. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1545. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1546. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1547. }
  1548. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1549. drug_id := int64(childMap["drug_id"].(float64))
  1550. child.DrugId = drug_id
  1551. }
  1552. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1553. way := int64(childMap["way"].(float64))
  1554. child.Way = way
  1555. }
  1556. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1557. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1558. child.DrugNameId = drug_name_id
  1559. }
  1560. child.DeliveryWay = advice.DeliveryWay
  1561. child.ExecutionFrequency = advice.ExecutionFrequency
  1562. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1563. if child.PrescribingNumber == 0 {
  1564. child.PrescribingNumber = 1
  1565. }
  1566. //查询该患者今日有没有双人核对
  1567. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1568. if check.ID > 0 {
  1569. child.Checker = check.Modifier
  1570. child.CheckState = 1
  1571. child.CheckTime = time.Now().Unix()
  1572. }
  1573. }
  1574. advice.Children = append(advice.Children, &child)
  1575. }
  1576. }
  1577. }
  1578. advices = append(advices, &advice)
  1579. }
  1580. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1581. for _, item := range advices {
  1582. //记录日志
  1583. byterequest, _ := json.Marshal(item)
  1584. adviceLog := models.XtDoctorAdviceLog{
  1585. UserOrgId: item.UserOrgId,
  1586. PatientId: item.PatientId,
  1587. AdminUserId: adminUserInfo.AdminUser.Id,
  1588. Module: 1,
  1589. ErrLog: string(byterequest),
  1590. Status: 1,
  1591. Ctime: time.Now().Unix(),
  1592. Mtime: 0,
  1593. Source: "电导端批量插入医嘱",
  1594. RecordDate: item.AdviceDate,
  1595. }
  1596. service.CreateDoctorAdviceLog(adviceLog)
  1597. }
  1598. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1599. redis := service.RedisClient()
  1600. defer redis.Close()
  1601. redis.Set(key, "", time.Second)
  1602. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1603. redis.Set(keyOne, "", time.Second)
  1604. if err != nil {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1606. return
  1607. }
  1608. c.ServeSuccessJSON(map[string]interface{}{
  1609. "msg": "ok",
  1610. "advices": list,
  1611. })
  1612. return
  1613. }
  1614. func (c *PatientApiController) CreateDoctorAdvice() {
  1615. patient, _ := c.GetInt64("id", 0)
  1616. if patient <= 0 {
  1617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1618. return
  1619. }
  1620. adminUserInfo := c.GetAdminUserInfo()
  1621. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1622. if patientInfo.ID == 0 {
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1624. return
  1625. }
  1626. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1627. if appRole.UserType == 3 {
  1628. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1629. if getPermissionErr != nil {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1631. return
  1632. } else if headNursePermission == nil {
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1634. return
  1635. }
  1636. }
  1637. var advice models.DoctorAdvice
  1638. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1639. if code > 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(code)
  1641. return
  1642. }
  1643. if advice.ParentId > 0 {
  1644. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1645. if old.ID == 0 || old.PatientId != patient {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1647. return
  1648. }
  1649. if old.StopState == 1 || old.ExecutionState == 1 {
  1650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1651. return
  1652. }
  1653. if old.ParentId > 0 {
  1654. advice.ParentId = old.ParentId
  1655. }
  1656. advice.StartTime = old.StartTime
  1657. advice.AdviceDoctor = old.AdviceDoctor
  1658. advice.DeliveryWay = old.DeliveryWay
  1659. advice.ExecutionFrequency = old.ExecutionFrequency
  1660. advice.GroupNo = old.GroupNo
  1661. }
  1662. advice.Status = 1
  1663. advice.CreatedTime = time.Now().Unix()
  1664. advice.UpdatedTime = time.Now().Unix()
  1665. advice.StopState = 2
  1666. advice.ExecutionState = 2
  1667. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1668. advice.PatientId = patient
  1669. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1670. // 查询信息规挡的设置天数
  1671. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1672. if infor.ID > 0 && infor.WeekDay > 0 {
  1673. var cha_time int64
  1674. timeNowStr := time.Now().Format("2006-01-02")
  1675. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1676. //今日的日期减去设置的日期
  1677. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1678. if cha_time >= advice.AdviceDate {
  1679. //查询审核是否允许
  1680. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1681. //申请状态不允许的情况 拒绝修改
  1682. if infor.ApplicationStatus != 1 {
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1684. return
  1685. }
  1686. }
  1687. }
  1688. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1689. if advice.PrescribingNumber == 0 {
  1690. advice.PrescribingNumber = 1
  1691. }
  1692. //查询该患者今日有没有双人核对
  1693. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1694. if check.ID > 0 {
  1695. advice.Checker = check.Modifier
  1696. advice.CheckState = 1
  1697. advice.CheckTime = time.Now().Unix()
  1698. }
  1699. }
  1700. err := service.CreateDoctorAdvice(&advice)
  1701. //记录日志
  1702. byterequest, _ := json.Marshal(advice)
  1703. adviceLog := models.XtDoctorAdviceLog{
  1704. UserOrgId: advice.UserOrgId,
  1705. PatientId: advice.PatientId,
  1706. AdminUserId: adminUserInfo.AdminUser.Id,
  1707. Module: 1,
  1708. ErrLog: string(byterequest),
  1709. Status: 1,
  1710. Ctime: time.Now().Unix(),
  1711. Mtime: 0,
  1712. Source: "电脑新增医嘱",
  1713. RecordDate: advice.RecordDate,
  1714. }
  1715. service.CreateDoctorAdviceLog(adviceLog)
  1716. //创建步骤表
  1717. finish := models.XtDialysisFinish{
  1718. IsFinish: 1,
  1719. UserOrgId: adminUserInfo.CurrentOrgId,
  1720. Status: 1,
  1721. Ctime: time.Now().Unix(),
  1722. Mtime: 0,
  1723. Module: 4,
  1724. RecordDate: advice.AdviceDate,
  1725. Sourse: 1,
  1726. PatientId: patient,
  1727. }
  1728. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1729. if dialysisFinish.ID == 0 {
  1730. service.CreateDialysisFinish(finish)
  1731. }
  1732. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1733. redis := service.RedisClient()
  1734. defer redis.Close()
  1735. redis.Set(key, "", time.Second)
  1736. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1737. redis.Set(keyOne, "", time.Second)
  1738. if err != nil {
  1739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1740. return
  1741. }
  1742. c.ServeSuccessJSON(map[string]interface{}{
  1743. "msg": "ok",
  1744. "advice": advice,
  1745. })
  1746. return
  1747. }
  1748. func (c *PatientApiController) ExecGroupAdvice() {
  1749. groupNo, _ := c.GetInt64("groupno", 0)
  1750. executionTime := c.GetString("execution_time")
  1751. if groupNo <= 0 {
  1752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1753. return
  1754. }
  1755. if len(executionTime) <= 0 {
  1756. utils.ErrorLog("execution_time")
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1758. return
  1759. }
  1760. adminUserInfo := c.GetAdminUserInfo()
  1761. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1762. if advice.ID == 0 {
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1764. return
  1765. }
  1766. if advice.ExecutionState == 1 {
  1767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1768. return
  1769. }
  1770. executionStaff := adminUserInfo.AdminUser.Id
  1771. // checker := adminUserInfo.AdminUser.Id
  1772. timeLayout := "2006-01-02 15:04:05"
  1773. loc, _ := time.LoadLocation("Local")
  1774. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1775. if err != nil {
  1776. utils.ErrorLog(err.Error())
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1778. return
  1779. }
  1780. if advice.StartTime > theTime.Unix() {
  1781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1782. return
  1783. }
  1784. exceAdvice := models.DoctorAdvice{
  1785. ExecutionStaff: executionStaff,
  1786. ExecutionTime: theTime.Unix(),
  1787. UpdatedTime: time.Now().Unix(),
  1788. }
  1789. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1790. if err != nil {
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1792. return
  1793. }
  1794. //查询自动扣减是否开启
  1795. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1796. //查询已经执行的医嘱
  1797. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1798. if drugStockConfig.IsOpen == 1 {
  1799. for _, item := range advicelist {
  1800. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1801. //查询这个患者这个患者这个药已经出库的所有数量
  1802. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1803. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1804. var total_count int64
  1805. var drug_count int64
  1806. for _, it := range advicelist {
  1807. if it.PrescribingNumberUnit == medical.MaxUnit {
  1808. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1809. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1810. total_count += prenumber * medical.MinNumber
  1811. }
  1812. if it.PrescribingNumberUnit == medical.MinUnit {
  1813. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1814. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1815. total_count += prenumber
  1816. }
  1817. }
  1818. for _, its := range drugoutlist {
  1819. if its.CountUnit == medical.MaxUnit {
  1820. drug_count += its.Count * medical.MinNumber
  1821. }
  1822. if its.CountUnit == medical.MinUnit {
  1823. drug_count += its.Count
  1824. }
  1825. }
  1826. if total_count == drug_count {
  1827. c.ServeSuccessJSON(map[string]interface{}{
  1828. "msg": "1",
  1829. "advice": advice,
  1830. })
  1831. return
  1832. }
  1833. var total int64
  1834. var prescribing_number_total int64
  1835. //查询默认出库仓库
  1836. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1837. //查询该药品在默认仓库是否有库存
  1838. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1839. //判断单位是否相等
  1840. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1841. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1842. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1843. //转化为最小单位
  1844. total = list.Count*medical.MinNumber + list.StockMinNumber
  1845. prescribing_number_total = count * medical.MinNumber
  1846. }
  1847. if medical.MinUnit == advice.PrescribingNumberUnit {
  1848. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1849. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1850. total = list.Count*medical.MinNumber + list.StockMinNumber
  1851. prescribing_number_total = count
  1852. }
  1853. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1854. c.ServeSuccessJSON(map[string]interface{}{
  1855. "msg": "3",
  1856. "advice": advice,
  1857. })
  1858. return
  1859. }
  1860. if prescribing_number_total > total {
  1861. c.ServeSuccessJSON(map[string]interface{}{
  1862. "msg": "2",
  1863. "advice": advice,
  1864. })
  1865. return
  1866. }
  1867. if prescribing_number_total <= total {
  1868. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1869. if medical.IsUse == 2 {
  1870. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1871. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1872. if drugOutInfo.ID == 0 {
  1873. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1874. }
  1875. }
  1876. if pharmacyConfig.IsOpen != 1 {
  1877. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1878. if drugOutInfo.ID == 0 {
  1879. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1880. }
  1881. }
  1882. //查询默认仓库
  1883. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1884. //查询默认仓库剩余多少库存
  1885. var sum_count int64
  1886. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1887. for _, its := range stockInfo {
  1888. if its.MaxUnit == medical.MaxUnit {
  1889. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1890. }
  1891. sum_count += its.StockMaxNumber + its.StockMinNumber
  1892. }
  1893. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1894. break
  1895. c.ServeSuccessJSON(map[string]interface{}{
  1896. "msg": "1",
  1897. "advice": advice,
  1898. })
  1899. return
  1900. }
  1901. if medical.IsUse == 1 {
  1902. c.ServeSuccessJSON(map[string]interface{}{
  1903. "msg": "1",
  1904. "advice": advice,
  1905. })
  1906. return
  1907. }
  1908. }
  1909. }
  1910. }
  1911. advice.ExecutionStaff = executionStaff
  1912. advice.ExecutionTime = theTime.Unix()
  1913. c.ServeSuccessJSON(map[string]interface{}{
  1914. "msg": "ok",
  1915. "advice": advice,
  1916. })
  1917. return
  1918. }
  1919. func (c *PatientApiController) ExecDoctorAdvice() {
  1920. origin, _ := c.GetInt64("origin", 0)
  1921. patient, _ := c.GetInt64("patient", 0)
  1922. id, _ := c.GetInt64("id", 0)
  1923. executionTime := c.GetString("execution_time")
  1924. if origin != 2 {
  1925. if id <= 0 || patient <= 0 {
  1926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1927. return
  1928. }
  1929. if len(executionTime) <= 0 {
  1930. utils.ErrorLog("execution_time")
  1931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1932. return
  1933. }
  1934. adminUserInfo := c.GetAdminUserInfo()
  1935. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1936. if advice.ID == 0 || advice.PatientId != patient {
  1937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1938. return
  1939. }
  1940. //医嘱已执行
  1941. if advice.ExecutionState == 1 {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1943. return
  1944. }
  1945. executionStaff := adminUserInfo.AdminUser.Id
  1946. timeLayout := "2006-01-02 15:04:05"
  1947. loc, _ := time.LoadLocation("Local")
  1948. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1949. if err != nil {
  1950. utils.ErrorLog(err.Error())
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1952. return
  1953. }
  1954. if advice.StartTime > theTime.Unix() {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1956. return
  1957. }
  1958. exceAdvice := models.DoctorAdvice{
  1959. ExecutionStaff: executionStaff,
  1960. ExecutionTime: theTime.Unix(),
  1961. UpdatedTime: time.Now().Unix(),
  1962. }
  1963. // 查询信息规挡的设置天数
  1964. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1965. if infor.ID > 0 && infor.WeekDay > 0 {
  1966. var cha_time int64
  1967. timeNowStr := time.Now().Format("2006-01-02")
  1968. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1969. //今日的日期减去设置的日期
  1970. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1971. if cha_time >= advice.AdviceDate {
  1972. //查询审核是否允许
  1973. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1974. //申请状态不允许的情况 拒绝修改
  1975. if infor.ApplicationStatus != 1 {
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1977. return
  1978. }
  1979. }
  1980. }
  1981. if advice.ParentId > 0 {
  1982. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1983. //记录日志
  1984. byterequest, _ := json.Marshal(exceAdvice)
  1985. doctorAdviceLog := models.XtDoctorAdviceLog{
  1986. UserOrgId: exceAdvice.UserOrgId,
  1987. PatientId: exceAdvice.PatientId,
  1988. AdminUserId: adminUserInfo.AdminUser.Id,
  1989. Module: 2,
  1990. ErrLog: string(byterequest),
  1991. Status: 1,
  1992. Ctime: time.Now().Unix(),
  1993. Mtime: 0,
  1994. Source: "电脑端执行医嘱",
  1995. RecordDate: exceAdvice.RecordDate,
  1996. }
  1997. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1998. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1999. redis := service.RedisClient()
  2000. //清空key 值
  2001. redis.Set(key, "", time.Second)
  2002. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2003. redis.Set(keyTwo, "", time.Second)
  2004. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2005. redis.Set(keyThree, "", time.Second)
  2006. theTimes := theTime.Format("2006-01-02")
  2007. fmt.Println("theTIME", theTime)
  2008. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2009. redis.Set(keyFour, "", time.Second)
  2010. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2011. redis.Set(keyFive, "", time.Second)
  2012. defer redis.Close()
  2013. } else {
  2014. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(exceAdvice)
  2017. doctorAdviceLog := models.XtDoctorAdviceLog{
  2018. UserOrgId: exceAdvice.UserOrgId,
  2019. PatientId: exceAdvice.PatientId,
  2020. AdminUserId: adminUserInfo.AdminUser.Id,
  2021. Module: 2,
  2022. ErrLog: string(byterequest),
  2023. Status: 1,
  2024. Ctime: time.Now().Unix(),
  2025. Mtime: 0,
  2026. Source: "电脑端执行医嘱",
  2027. RecordDate: exceAdvice.RecordDate,
  2028. }
  2029. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2030. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2031. redis := service.RedisClient()
  2032. //清空key 值
  2033. redis.Set(key, "", time.Second)
  2034. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2035. redis.Set(keyTwo, "", time.Second)
  2036. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2037. redis.Set(keyThree, "", time.Second)
  2038. theTimes := theTime.Format("2006-01-02")
  2039. fmt.Println("theTIME", theTime)
  2040. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2041. redis.Set(keyFour, "", time.Second)
  2042. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2043. redis.Set(keyFive, "", time.Second)
  2044. defer redis.Close()
  2045. }
  2046. if err != nil {
  2047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2048. return
  2049. }
  2050. advice.ExecutionStaff = executionStaff
  2051. advice.ExecutionTime = theTime.Unix()
  2052. //处理出库相关逻辑
  2053. //1.判断是否启用药品管理和自备药出库功能
  2054. //药品管理信息
  2055. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2056. //自备药信息
  2057. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2058. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2059. if drugStockConfig.IsOpen == 1 {
  2060. var total int64
  2061. var prescribing_number_total int64
  2062. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2063. for _, item := range advices {
  2064. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2065. //查询该药品是否有库存
  2066. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2067. //查询改药品信息
  2068. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2069. //判断单位是否相等
  2070. if medical.MaxUnit == item.PrescribingNumberUnit {
  2071. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2072. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2073. //转化为最小单位
  2074. total = list.Count*medical.MinNumber + list.StockMinNumber
  2075. prescribing_number_total = count * medical.MinNumber
  2076. }
  2077. if medical.MinUnit == item.PrescribingNumberUnit {
  2078. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2079. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2080. total = list.Count*medical.MinNumber + list.StockMinNumber
  2081. prescribing_number_total = count
  2082. }
  2083. if medical.IsUse != 1 {
  2084. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2085. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2086. advice.ExecutionState = 2
  2087. advice.ExecutionStaff = 0
  2088. advice.ExecutionTime = 0
  2089. c.ServeSuccessJSON(map[string]interface{}{
  2090. "msg": "3",
  2091. "advice": advice,
  2092. })
  2093. return
  2094. }
  2095. if prescribing_number_total > total {
  2096. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2097. advice.ExecutionState = 2
  2098. advice.ExecutionStaff = 0
  2099. advice.ExecutionTime = 0
  2100. c.ServeSuccessJSON(map[string]interface{}{
  2101. "msg": "2",
  2102. "advice": advice,
  2103. })
  2104. return
  2105. }
  2106. }
  2107. if medical.IsUse == 1 {
  2108. c.ServeSuccessJSON(map[string]interface{}{
  2109. "msg": "1",
  2110. "advice": advice,
  2111. })
  2112. return
  2113. }
  2114. if prescribing_number_total <= total {
  2115. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2116. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2117. if adviceSetting.IsAdviceOpen == 1 {
  2118. //查询是否出库按钮开启
  2119. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2120. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2121. if prescriptionConfig.IsOpen == 1 {
  2122. if medical.IsUse == 2 {
  2123. //是通过药房发药
  2124. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2125. //执行出库
  2126. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2127. if drugOutInfo.ID == 0 {
  2128. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2129. }
  2130. }
  2131. //不通过药房发药
  2132. if pharmacyConfig.IsOpen != 1 {
  2133. //执行出库
  2134. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2135. if drugOutInfo.ID == 0 {
  2136. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2137. }
  2138. }
  2139. //查询默认仓库
  2140. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2141. //查询默认仓库剩余多少库存
  2142. var sum_count int64
  2143. //更新字典里面的库存
  2144. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2145. for _, its := range stockInfo {
  2146. if its.MaxUnit == medical.MaxUnit {
  2147. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2148. }
  2149. sum_count += its.StockMaxNumber + its.StockMinNumber
  2150. }
  2151. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2152. //剩余库存
  2153. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2154. break
  2155. c.ServeSuccessJSON(map[string]interface{}{
  2156. "msg": "1",
  2157. "advice": advice,
  2158. })
  2159. return
  2160. }
  2161. if medical.IsUse == 1 {
  2162. c.ServeSuccessJSON(map[string]interface{}{
  2163. "msg": "1",
  2164. "advice": advice,
  2165. })
  2166. return
  2167. }
  2168. } else {
  2169. if medical.IsUse == 1 {
  2170. c.ServeSuccessJSON(map[string]interface{}{
  2171. "msg": "1",
  2172. "advice": advice,
  2173. })
  2174. return
  2175. }
  2176. }
  2177. } else {
  2178. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2179. if medical.IsUse == 2 {
  2180. //是通过药房发药
  2181. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2182. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2183. if drugOutInfo.ID == 0 {
  2184. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2185. }
  2186. }
  2187. //不通过药房发药
  2188. if pharmacyConfig.IsOpen != 1 {
  2189. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2190. if drugOutInfo.ID == 0 {
  2191. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2192. }
  2193. }
  2194. //更新字典里面的库存
  2195. var sum_count int64
  2196. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2197. for _, its := range stockInfo {
  2198. if its.MaxUnit == medical.MaxUnit {
  2199. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2200. }
  2201. sum_count += its.StockMaxNumber + its.StockMinNumber
  2202. }
  2203. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2204. //剩余库存
  2205. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2206. break
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "msg": "1",
  2209. "advice": advice,
  2210. })
  2211. return
  2212. }
  2213. if medical.IsUse == 1 {
  2214. c.ServeSuccessJSON(map[string]interface{}{
  2215. "msg": "1",
  2216. "advice": advice,
  2217. })
  2218. return
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2225. for _, item := range advices {
  2226. if item.Way == 2 {
  2227. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2228. if item.ExecutionState == 1 {
  2229. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2230. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2231. timeStr := time.Now().Format("2006-01-02")
  2232. timeArr := strings.Split(timeStr, "-")
  2233. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2234. total = total + 1
  2235. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2236. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2237. number = number + total
  2238. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2239. //插入自备药出库单
  2240. outStock := models.XtSelfOutStock{
  2241. DrugName: item.AdviceName,
  2242. DrugNameId: item.DrugId,
  2243. DrugSpec: item.AdviceDesc,
  2244. OutstoreNumber: count,
  2245. AdminUserId: adminUserInfo.AdminUser.Id,
  2246. StorckTime: item.RecordDate,
  2247. UserOrgId: adminUserInfo.CurrentOrgId,
  2248. CreatedTime: time.Now().Unix(),
  2249. Status: 1,
  2250. PatientId: item.PatientId,
  2251. ExitMode: 2,
  2252. MedicId: item.DrugId,
  2253. StockOutNumber: warehousing_out_order,
  2254. }
  2255. service.CreateOutStock(&outStock)
  2256. }
  2257. }
  2258. }
  2259. }
  2260. c.ServeSuccessJSON(map[string]interface{}{
  2261. "msg": "1",
  2262. "advice": advice,
  2263. })
  2264. return
  2265. } else {
  2266. if id <= 0 || patient <= 0 {
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2268. return
  2269. }
  2270. if len(executionTime) <= 0 {
  2271. utils.ErrorLog("execution_time")
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2273. return
  2274. }
  2275. adminUserInfo := c.GetAdminUserInfo()
  2276. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2277. if advice.ID == 0 || advice.PatientId != patient {
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2279. return
  2280. }
  2281. //医嘱已执行
  2282. if advice.ExecutionState == 1 {
  2283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2284. return
  2285. }
  2286. executionStaff := adminUserInfo.AdminUser.Id
  2287. timeLayout := "2006-01-02 15:04:05"
  2288. loc, _ := time.LoadLocation("Local")
  2289. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2290. if err != nil {
  2291. utils.ErrorLog(err.Error())
  2292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2293. return
  2294. }
  2295. if advice.StartTime > theTime.Unix() {
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2297. return
  2298. }
  2299. exceAdvice := models.HisDoctorAdviceInfo{
  2300. ExecutionStaff: executionStaff,
  2301. ExecutionTime: theTime.Unix(),
  2302. UpdatedTime: time.Now().Unix(),
  2303. }
  2304. if advice.ParentId > 0 {
  2305. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2306. //记录日志
  2307. byterequest, _ := json.Marshal(exceAdvice)
  2308. doctorAdviceLog := models.XtDoctorAdviceLog{
  2309. UserOrgId: exceAdvice.UserOrgId,
  2310. PatientId: exceAdvice.PatientId,
  2311. AdminUserId: adminUserInfo.AdminUser.Id,
  2312. Module: 2,
  2313. ErrLog: string(byterequest),
  2314. Status: 1,
  2315. Ctime: time.Now().Unix(),
  2316. Mtime: 0,
  2317. Source: "电脑端执行His医嘱",
  2318. RecordDate: exceAdvice.RecordDate,
  2319. }
  2320. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2321. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2322. redis := service.RedisClient()
  2323. //清空key 值
  2324. redis.Set(key, "", time.Second)
  2325. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2326. redis.Set(keyTwo, "", time.Second)
  2327. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2328. redis.Set(keyThree, "", time.Second)
  2329. theTimes := theTime.Format("2006-01-02")
  2330. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2331. redis.Set(keyFour, "", time.Second)
  2332. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2333. redis.Set(keyFive, "", time.Second)
  2334. defer redis.Close()
  2335. } else {
  2336. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2337. //记录日志
  2338. byterequest, _ := json.Marshal(exceAdvice)
  2339. doctorAdviceLog := models.XtDoctorAdviceLog{
  2340. UserOrgId: exceAdvice.UserOrgId,
  2341. PatientId: exceAdvice.PatientId,
  2342. AdminUserId: adminUserInfo.AdminUser.Id,
  2343. Module: 2,
  2344. ErrLog: string(byterequest),
  2345. Status: 1,
  2346. Ctime: time.Now().Unix(),
  2347. Mtime: 0,
  2348. Source: "电脑端执行His医嘱",
  2349. RecordDate: exceAdvice.RecordDate,
  2350. }
  2351. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2352. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2353. redis := service.RedisClient()
  2354. //清空key 值
  2355. redis.Set(key, "", time.Second)
  2356. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2357. redis.Set(keyTwo, "", time.Second)
  2358. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2359. redis.Set(keyThree, "", time.Second)
  2360. theTimes := theTime.Format("2006-01-02")
  2361. fmt.Println("theTIME", theTime)
  2362. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2363. redis.Set(keyFour, "", time.Second)
  2364. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2365. redis.Set(keyFive, "", time.Second)
  2366. defer redis.Close()
  2367. }
  2368. if err != nil {
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2370. return
  2371. }
  2372. advice.ExecutionStaff = executionStaff
  2373. advice.ExecutionTime = theTime.Unix()
  2374. //处理出库相关逻辑
  2375. //1.判断是否启用药品管理和自备药出库功能
  2376. //药品自动出库开关管理信息
  2377. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2378. if drugStockConfig.IsOpen == 1 {
  2379. //查询已经执行的医嘱
  2380. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2381. for _, item := range advices {
  2382. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2383. var total int64
  2384. var prescribing_number_total int64
  2385. //药品保存处方出库
  2386. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2387. if config.IsOpen != 1 {
  2388. //查询默认出库仓库
  2389. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2390. //查询该药品在默认仓库是否有库存
  2391. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2392. //判断单位是否相等
  2393. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2394. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2395. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2396. //转化为最小单位
  2397. total = list.Count*medical.MinNumber + list.StockMinNumber
  2398. prescribing_number_total = count * medical.MinNumber
  2399. }
  2400. if medical.MinUnit == advice.PrescribingNumberUnit {
  2401. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2402. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2403. total = list.Count*medical.MinNumber + list.StockMinNumber
  2404. prescribing_number_total = count
  2405. }
  2406. if medical.IsUse == 1 {
  2407. drugError := models.XtDrugError{
  2408. UserOrgId: item.UserOrgId,
  2409. DrugId: item.DrugId,
  2410. RecordDate: item.AdviceDate,
  2411. PatientId: item.PatientId,
  2412. Remark: "电脑端零用药品",
  2413. Status: 1,
  2414. Ctime: time.Now().Unix(),
  2415. Mtime: 0,
  2416. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2417. Prescribingnumber: item.PrescribingNumber,
  2418. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2419. }
  2420. service.CreateDrugError(drugError)
  2421. c.ServeSuccessJSON(map[string]interface{}{
  2422. "msg": "1",
  2423. "advice": advice,
  2424. })
  2425. return
  2426. }
  2427. if medical.IsUse != 1 {
  2428. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2429. drugError := models.XtDrugError{
  2430. UserOrgId: item.UserOrgId,
  2431. DrugId: item.DrugId,
  2432. RecordDate: item.AdviceDate,
  2433. PatientId: item.PatientId,
  2434. Remark: "电脑端药品库存不足",
  2435. Status: 1,
  2436. Ctime: time.Now().Unix(),
  2437. Mtime: 0,
  2438. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2439. Prescribingnumber: item.PrescribingNumber,
  2440. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2441. }
  2442. service.CreateDrugError(drugError)
  2443. c.ServeSuccessJSON(map[string]interface{}{
  2444. "msg": "3",
  2445. "advice": advice,
  2446. })
  2447. return
  2448. }
  2449. if prescribing_number_total > total {
  2450. drugError := models.XtDrugError{
  2451. UserOrgId: item.UserOrgId,
  2452. DrugId: item.DrugId,
  2453. RecordDate: item.AdviceDate,
  2454. PatientId: item.PatientId,
  2455. Remark: "电脑端出库数量大于总库存",
  2456. Status: 1,
  2457. Ctime: time.Now().Unix(),
  2458. Mtime: 0,
  2459. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2460. Prescribingnumber: item.PrescribingNumber,
  2461. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2462. }
  2463. service.CreateDrugError(drugError)
  2464. c.ServeSuccessJSON(map[string]interface{}{
  2465. "msg": "2",
  2466. "advice": advice,
  2467. })
  2468. return
  2469. }
  2470. }
  2471. if prescribing_number_total <= total {
  2472. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2473. if medical.IsUse == 2 {
  2474. if config.IsOpen != 1 {
  2475. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2476. // 开始主事务
  2477. db := service.XTWriteDB()
  2478. tx := db.Begin()
  2479. // 在函数结束时处理事务回滚
  2480. defer func() {
  2481. if r := recover(); r != nil {
  2482. tx.Rollback()
  2483. }
  2484. }()
  2485. creater := c.GetAdminUserInfo().AdminUser.Id
  2486. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2487. var out_count int64
  2488. if len(outListExport) > 0 {
  2489. for _, item := range outListExport {
  2490. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2491. out_count = item.Count * medical.MinNumber
  2492. }
  2493. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2494. out_count = item.Count
  2495. }
  2496. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2497. out_count = item.Count * medical.MinNumber
  2498. }
  2499. }
  2500. }
  2501. newadviceInfo := &models.HisDoctorAdviceInfo{
  2502. ID: item.ID,
  2503. UserOrgId: item.UserOrgId,
  2504. PatientId: item.PatientId,
  2505. HisPatientId: item.HisPatientId,
  2506. AdviceType: item.AdviceType,
  2507. AdviceDate: item.AdviceDate,
  2508. StartTime: item.StartTime,
  2509. AdviceName: item.AdviceName,
  2510. AdviceDesc: item.AdviceDesc,
  2511. ReminderDate: item.ReminderDate,
  2512. SingleDose: item.SingleDose,
  2513. SingleDoseUnit: item.SingleDoseUnit,
  2514. PrescribingNumber: item.PrescribingNumber,
  2515. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2516. DeliveryWay: item.DeliveryWay,
  2517. ExecutionFrequency: item.ExecutionFrequency,
  2518. AdviceDoctor: item.AdviceDoctor,
  2519. Status: item.Status,
  2520. CreatedTime: item.CreatedTime,
  2521. UpdatedTime: item.UpdatedTime,
  2522. AdviceAffirm: item.AdviceAffirm,
  2523. Remark: item.Remark,
  2524. StopTime: item.StopTime,
  2525. StopReason: item.StopReason,
  2526. StopDoctor: item.StopDoctor,
  2527. StopState: item.StopState,
  2528. ParentId: item.ParentId,
  2529. ExecutionTime: item.ExecutionTime,
  2530. ExecutionStaff: item.ExecutionStaff,
  2531. ExecutionState: item.ExecutionState,
  2532. Checker: item.Checker,
  2533. RecordDate: item.RecordDate,
  2534. DialysisOrderId: item.DialysisOrderId,
  2535. CheckTime: item.CheckTime,
  2536. CheckState: item.CheckState,
  2537. DrugSpec: item.DrugSpec,
  2538. DrugSpecUnit: item.DrugSpecUnit,
  2539. Groupno: item.Groupno,
  2540. RemindType: item.RemindType,
  2541. FrequencyType: item.FrequencyType,
  2542. DayCount: item.DayCount,
  2543. WeekDay: item.WeekDay,
  2544. TemplateId: item.TemplateId,
  2545. Modifier: item.Modifier,
  2546. DrugId: item.DrugId,
  2547. Price: item.Price,
  2548. PrescriptionId: item.PrescriptionId,
  2549. MedListCodg: item.MedListCodg,
  2550. FeedetlSn: item.FeedetlSn,
  2551. Day: item.DayCount,
  2552. ChildDoctorAdvice: nil,
  2553. Drug: models.Drug{},
  2554. Diagnosis: item.Diagnosis,
  2555. Way: item.Way,
  2556. HospApprFlag: item.HospApprFlag,
  2557. LmtUsedFlag: item.LmtUsedFlag,
  2558. HisOrderInfo: models.HisOrderInfo{},
  2559. IsMedicine: item.IsMedicine,
  2560. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2561. Child: nil,
  2562. IsSettle: item.IsSettle,
  2563. IsMobile: item.IsMobile,
  2564. IsSelfDrug: item.IsSelfDrug,
  2565. DrugWayCount: item.DrugWayCount,
  2566. }
  2567. //如果当前医嘱数量大于历史出库数据则需要出库
  2568. if prescribing_number_total > out_count {
  2569. //按最小单位出库
  2570. var cha_count = prescribing_number_total - out_count
  2571. item.PrescribingNumber = float64(cha_count)
  2572. item.PrescribingNumberUnit = medical.MinUnit
  2573. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2574. }
  2575. //如果当前医嘱数量小于历史出库数据则需要退库
  2576. if prescribing_number_total < out_count {
  2577. var cha_count = out_count - prescribing_number_total
  2578. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2579. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2580. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2581. }
  2582. if prescribing_number_total == out_count {
  2583. if out_count == 0 {
  2584. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2585. }
  2586. }
  2587. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2588. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2589. //查询该药品是否有出库记录
  2590. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2591. if len(flowMap) == 0 {
  2592. errs := service.UpdateHisAdviceById(item.ID)
  2593. if errs != nil {
  2594. drugError := models.XtDrugError{
  2595. UserOrgId: item.UserOrgId,
  2596. DrugId: item.DrugId,
  2597. RecordDate: item.AdviceDate,
  2598. PatientId: item.PatientId,
  2599. Remark: "出库记录为空,更新执行人失败",
  2600. Status: 1,
  2601. Ctime: time.Now().Unix(),
  2602. Mtime: 0,
  2603. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2604. Prescribingnumber: item.PrescribingNumber,
  2605. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2606. }
  2607. service.CreateDrugError(drugError)
  2608. }
  2609. c.ServeSuccessJSON(map[string]interface{}{
  2610. "msg": "6",
  2611. "advice": advice,
  2612. })
  2613. return
  2614. }
  2615. }
  2616. tx.Commit()
  2617. }
  2618. //不通过药房发药
  2619. if pharmacyConfig.IsOpen != 1 {
  2620. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2621. // 开始主事务
  2622. db := service.XTWriteDB()
  2623. tx := db.Begin()
  2624. // 在函数结束时处理事务回滚
  2625. defer func() {
  2626. if r := recover(); r != nil {
  2627. tx.Rollback()
  2628. }
  2629. }()
  2630. creater := c.GetAdminUserInfo().AdminUser.Id
  2631. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2632. var out_count int64
  2633. if len(outListExport) > 0 {
  2634. for _, item := range outListExport {
  2635. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2636. out_count = item.Count * medical.MinNumber
  2637. }
  2638. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2639. out_count = item.Count
  2640. }
  2641. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2642. out_count = item.Count * medical.MinNumber
  2643. }
  2644. }
  2645. }
  2646. newadviceInfo := &models.HisDoctorAdviceInfo{
  2647. ID: item.ID,
  2648. UserOrgId: item.UserOrgId,
  2649. PatientId: item.PatientId,
  2650. HisPatientId: item.HisPatientId,
  2651. AdviceType: item.AdviceType,
  2652. AdviceDate: item.AdviceDate,
  2653. StartTime: item.StartTime,
  2654. AdviceName: item.AdviceName,
  2655. AdviceDesc: item.AdviceDesc,
  2656. ReminderDate: item.ReminderDate,
  2657. SingleDose: item.SingleDose,
  2658. SingleDoseUnit: item.SingleDoseUnit,
  2659. PrescribingNumber: item.PrescribingNumber,
  2660. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2661. DeliveryWay: item.DeliveryWay,
  2662. ExecutionFrequency: item.ExecutionFrequency,
  2663. AdviceDoctor: item.AdviceDoctor,
  2664. Status: item.Status,
  2665. CreatedTime: item.CreatedTime,
  2666. UpdatedTime: item.UpdatedTime,
  2667. AdviceAffirm: item.AdviceAffirm,
  2668. Remark: item.Remark,
  2669. StopTime: item.StopTime,
  2670. StopReason: item.StopReason,
  2671. StopDoctor: item.StopDoctor,
  2672. StopState: item.StopState,
  2673. ParentId: item.ParentId,
  2674. ExecutionTime: item.ExecutionTime,
  2675. ExecutionStaff: item.ExecutionStaff,
  2676. ExecutionState: item.ExecutionState,
  2677. Checker: item.Checker,
  2678. RecordDate: item.RecordDate,
  2679. DialysisOrderId: item.DialysisOrderId,
  2680. CheckTime: item.CheckTime,
  2681. CheckState: item.CheckState,
  2682. DrugSpec: item.DrugSpec,
  2683. DrugSpecUnit: item.DrugSpecUnit,
  2684. Groupno: item.Groupno,
  2685. RemindType: item.RemindType,
  2686. FrequencyType: item.FrequencyType,
  2687. DayCount: item.DayCount,
  2688. WeekDay: item.WeekDay,
  2689. TemplateId: item.TemplateId,
  2690. Modifier: item.Modifier,
  2691. DrugId: item.DrugId,
  2692. Price: item.Price,
  2693. PrescriptionId: item.PrescriptionId,
  2694. MedListCodg: item.MedListCodg,
  2695. FeedetlSn: item.FeedetlSn,
  2696. Day: item.DayCount,
  2697. ChildDoctorAdvice: nil,
  2698. Drug: models.Drug{},
  2699. Diagnosis: item.Diagnosis,
  2700. Way: item.Way,
  2701. HospApprFlag: item.HospApprFlag,
  2702. LmtUsedFlag: item.LmtUsedFlag,
  2703. HisOrderInfo: models.HisOrderInfo{},
  2704. IsMedicine: item.IsMedicine,
  2705. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2706. Child: nil,
  2707. IsSettle: item.IsSettle,
  2708. IsMobile: item.IsMobile,
  2709. IsSelfDrug: item.IsSelfDrug,
  2710. DrugWayCount: item.DrugWayCount,
  2711. }
  2712. //如果当前医嘱数量大于历史出库数据则需要出库
  2713. if prescribing_number_total > out_count {
  2714. //按最小单位出库
  2715. var cha_count = prescribing_number_total - out_count
  2716. newadviceInfo.PrescribingNumber = float64(cha_count)
  2717. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2718. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2719. }
  2720. //如果当前医嘱数量小于历史出库数据则需要退库
  2721. if prescribing_number_total < out_count {
  2722. var cha_count = out_count - prescribing_number_total
  2723. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2724. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2725. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2726. }
  2727. if prescribing_number_total == out_count {
  2728. if out_count == 0 {
  2729. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2730. }
  2731. }
  2732. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2733. tx.Commit()
  2734. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2735. //查询该药品是否有出库记录
  2736. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2737. if len(flowMap) == 0 {
  2738. errs := service.UpdateHisAdviceById(item.ID)
  2739. if errs != nil {
  2740. drugError := models.XtDrugError{
  2741. UserOrgId: item.UserOrgId,
  2742. DrugId: item.DrugId,
  2743. RecordDate: item.AdviceDate,
  2744. PatientId: item.PatientId,
  2745. Remark: "出库记录为空,更新执行人失败",
  2746. Status: 1,
  2747. Ctime: time.Now().Unix(),
  2748. Mtime: 0,
  2749. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2750. Prescribingnumber: item.PrescribingNumber,
  2751. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2752. }
  2753. service.CreateDrugError(drugError)
  2754. }
  2755. c.ServeSuccessJSON(map[string]interface{}{
  2756. "msg": "6",
  2757. "advice": advice,
  2758. })
  2759. return
  2760. }
  2761. }
  2762. }
  2763. //查询默认仓库
  2764. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2765. //查询默认仓库剩余多少库存
  2766. var sum_count int64
  2767. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2768. for _, its := range stockInfo {
  2769. if its.MaxUnit == medical.MaxUnit {
  2770. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2771. }
  2772. sum_count += its.StockMaxNumber + its.StockMinNumber
  2773. }
  2774. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2775. //出库数量累加
  2776. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2777. //剩余库存
  2778. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2779. break
  2780. c.ServeSuccessJSON(map[string]interface{}{
  2781. "msg": "1",
  2782. "advice": advice,
  2783. })
  2784. return
  2785. }
  2786. }
  2787. if medical.IsUse == 1 {
  2788. c.ServeSuccessJSON(map[string]interface{}{
  2789. "msg": "1",
  2790. "advice": advice,
  2791. })
  2792. return
  2793. }
  2794. }
  2795. }
  2796. }
  2797. }
  2798. c.ServeSuccessJSON(map[string]interface{}{
  2799. "msg": "1",
  2800. "advice": advice,
  2801. })
  2802. return
  2803. }
  2804. }
  2805. func (c *PatientApiController) CheckGroupAdvice() {
  2806. groupno, _ := c.GetInt64("groupno", 0)
  2807. if groupno <= 0 {
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2809. return
  2810. }
  2811. adminUserInfo := c.GetAdminUserInfo()
  2812. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2813. if advice.ID == 0 {
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2815. return
  2816. }
  2817. if advice.CheckState == 1 {
  2818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2819. return
  2820. }
  2821. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2823. return
  2824. }
  2825. checker := adminUserInfo.AdminUser.Id
  2826. theTime := time.Now()
  2827. exceAdvice := models.DoctorAdvice{
  2828. Checker: checker,
  2829. CheckTime: theTime.Unix(),
  2830. UpdatedTime: time.Now().Unix(),
  2831. }
  2832. var err error
  2833. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2834. if err != nil {
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2836. return
  2837. }
  2838. advice.Checker = checker
  2839. advice.CheckTime = theTime.Unix()
  2840. c.ServeSuccessJSON(map[string]interface{}{
  2841. "msg": "ok",
  2842. "advice": advice,
  2843. })
  2844. return
  2845. }
  2846. func (c *PatientApiController) CheckDoctorAdvice() {
  2847. patient, _ := c.GetInt64("patient", 0)
  2848. id, _ := c.GetInt64("id", 0)
  2849. origin, _ := c.GetInt64("origin", 0)
  2850. if origin != 2 {
  2851. // executionTime := c.GetString("execution_time")
  2852. if id <= 0 || patient <= 0 {
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2854. return
  2855. }
  2856. adminUserInfo := c.GetAdminUserInfo()
  2857. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2858. if advice.ID == 0 || advice.PatientId != patient {
  2859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2860. return
  2861. }
  2862. if advice.CheckState == 1 {
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2864. return
  2865. }
  2866. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2868. return
  2869. }
  2870. // executionStaff := adminUserInfo.AdminUser.Id
  2871. checker := adminUserInfo.AdminUser.Id
  2872. // timeLayout := "2006-01-02 15:04:05"
  2873. // loc, _ := time.LoadLocation("Local")
  2874. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2875. // if err != nil {
  2876. // utils.ErrorLog(err.Error())
  2877. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. // return
  2879. // }
  2880. theTime := time.Now()
  2881. if advice.ExecutionTime > theTime.Unix() {
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2883. return
  2884. }
  2885. exceAdvice := models.DoctorAdvice{
  2886. Checker: checker,
  2887. CheckTime: theTime.Unix(),
  2888. UpdatedTime: time.Now().Unix(),
  2889. }
  2890. var err error
  2891. // 查询信息规挡的设置天数
  2892. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2893. if infor.ID > 0 && infor.WeekDay > 0 {
  2894. var cha_time int64
  2895. timeNowStr := time.Now().Format("2006-01-02")
  2896. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2897. //今日的日期减去设置的日期
  2898. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2899. if cha_time >= advice.AdviceDate {
  2900. //查询审核是否允许
  2901. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2902. //申请状态不允许的情况 拒绝修改
  2903. if infor.ApplicationStatus != 1 {
  2904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2905. return
  2906. }
  2907. }
  2908. }
  2909. if advice.ParentId > 0 {
  2910. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2911. //记录日志
  2912. byterequest, _ := json.Marshal(exceAdvice)
  2913. adviceLog := models.XtDoctorAdviceLog{
  2914. UserOrgId: exceAdvice.UserOrgId,
  2915. PatientId: exceAdvice.PatientId,
  2916. AdminUserId: adminUserInfo.AdminUser.Id,
  2917. Module: 3,
  2918. ErrLog: string(byterequest),
  2919. Status: 1,
  2920. Ctime: time.Now().Unix(),
  2921. Mtime: 0,
  2922. Source: "核对医嘱",
  2923. RecordDate: exceAdvice.AdviceDate,
  2924. }
  2925. service.CreateDoctorAdviceLog(adviceLog)
  2926. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2927. redis := service.RedisClient()
  2928. //清空key 值
  2929. redis.Set(key, "", time.Second)
  2930. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2931. redis.Set(keyTwo, "", time.Second)
  2932. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2933. redis.Set(keyThree, "", time.Second)
  2934. recordDate := theTime.Format("2006-01-02")
  2935. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2936. redis.Set(keyFour, "", time.Second)
  2937. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2938. redis.Set(keyFive, "", time.Second)
  2939. } else {
  2940. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2941. //记录日志
  2942. byterequest, _ := json.Marshal(exceAdvice)
  2943. adviceLog := models.XtDoctorAdviceLog{
  2944. UserOrgId: exceAdvice.UserOrgId,
  2945. PatientId: exceAdvice.PatientId,
  2946. AdminUserId: adminUserInfo.AdminUser.Id,
  2947. Module: 3,
  2948. ErrLog: string(byterequest),
  2949. Status: 1,
  2950. Ctime: time.Now().Unix(),
  2951. Mtime: 0,
  2952. Source: "核对医嘱",
  2953. RecordDate: exceAdvice.AdviceDate,
  2954. }
  2955. service.CreateDoctorAdviceLog(adviceLog)
  2956. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2957. redis := service.RedisClient()
  2958. //清空key 值
  2959. redis.Set(key, "", time.Second)
  2960. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2961. redis.Set(keyTwo, "", time.Second)
  2962. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2963. redis.Set(keyThree, "", time.Second)
  2964. recordDate := theTime.Format("2006-01-02")
  2965. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2966. redis.Set(keyFour, "", time.Second)
  2967. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2968. redis.Set(keyFive, "", time.Second)
  2969. }
  2970. if err != nil {
  2971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2972. return
  2973. }
  2974. // advice.ExecutionStaff = executionStaff
  2975. // advice.ExecutionTime = theTime.Unix()
  2976. advice.Checker = checker
  2977. advice.CheckTime = theTime.Unix()
  2978. c.ServeSuccessJSON(map[string]interface{}{
  2979. "msg": "ok",
  2980. "advice": advice,
  2981. })
  2982. return
  2983. } else {
  2984. if id <= 0 || patient <= 0 {
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. adminUserInfo := c.GetAdminUserInfo()
  2989. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2990. if advice.ID == 0 || advice.PatientId != patient {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2992. return
  2993. }
  2994. if advice.CheckState == 1 {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2996. return
  2997. }
  2998. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3000. return
  3001. }
  3002. checker := adminUserInfo.AdminUser.Id
  3003. theTime := time.Now()
  3004. if advice.ExecutionTime > theTime.Unix() {
  3005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3006. return
  3007. }
  3008. exceAdvice := models.HisDoctorAdviceInfo{
  3009. Checker: checker,
  3010. CheckTime: theTime.Unix(),
  3011. UpdatedTime: time.Now().Unix(),
  3012. }
  3013. var err error
  3014. if advice.ParentId > 0 {
  3015. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3016. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3017. redis := service.RedisClient()
  3018. //清空key 值
  3019. redis.Set(key, "", time.Second)
  3020. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3021. redis.Set(keyTwo, "", time.Second)
  3022. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3023. redis.Set(keyThree, "", time.Second)
  3024. recordDate := theTime.Format("2006-01-02")
  3025. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3026. redis.Set(keyFour, "", time.Second)
  3027. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3028. redis.Set(keyFive, "", time.Second)
  3029. } else {
  3030. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  3031. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3032. redis := service.RedisClient()
  3033. //清空key 值
  3034. redis.Set(key, "", time.Second)
  3035. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3036. redis.Set(keyTwo, "", time.Second)
  3037. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3038. redis.Set(keyThree, "", time.Second)
  3039. recordDate := theTime.Format("2006-01-02")
  3040. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3041. redis.Set(keyFour, "", time.Second)
  3042. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3043. redis.Set(keyFive, "", time.Second)
  3044. }
  3045. if err != nil {
  3046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3047. return
  3048. }
  3049. // advice.ExecutionStaff = executionStaff
  3050. // advice.ExecutionTime = theTime.Unix()
  3051. advice.Checker = checker
  3052. advice.CheckTime = theTime.Unix()
  3053. c.ServeSuccessJSON(map[string]interface{}{
  3054. "msg": "ok",
  3055. "advice": advice,
  3056. })
  3057. return
  3058. }
  3059. }
  3060. func (c *PatientApiController) UpdateDoctorAdvice() {
  3061. patient, _ := c.GetInt64("patient", 0)
  3062. id, _ := c.GetInt64("id", 0)
  3063. if id <= 0 || patient <= 0 {
  3064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3065. return
  3066. }
  3067. adminUserInfo := c.GetAdminUserInfo()
  3068. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3069. if advice.ID == 0 || advice.PatientId != patient {
  3070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3071. return
  3072. }
  3073. //if advice.AdviceType == 1 {
  3074. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  3075. // return
  3076. //}
  3077. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  3078. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3080. return
  3081. }
  3082. }
  3083. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3084. //if appRole.UserType == 3 {
  3085. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3086. // if getPermissionErr != nil {
  3087. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3088. // return
  3089. // } else if headNursePermission == nil {
  3090. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3091. // return
  3092. // }
  3093. //}
  3094. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3095. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  3096. // return
  3097. //}
  3098. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  3099. if code > 0 {
  3100. c.ServeFailJSONWithSGJErrorCode(code)
  3101. return
  3102. }
  3103. advice.UpdatedTime = time.Now().Unix()
  3104. advice.Modifier = adminUserInfo.AdminUser.Id
  3105. // 查询信息规挡的设置天数
  3106. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3107. if infor.ID > 0 && infor.WeekDay > 0 {
  3108. var cha_time int64
  3109. timeNowStr := time.Now().Format("2006-01-02")
  3110. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3111. //今日的日期减去设置的日期
  3112. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3113. if cha_time >= advice.AdviceDate {
  3114. //查询审核是否允许
  3115. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3116. //申请状态不允许的情况 拒绝修改
  3117. if infor.ApplicationStatus != 1 {
  3118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3119. return
  3120. }
  3121. }
  3122. }
  3123. err := service.UpdateDoctorAdvice(&advice)
  3124. //记录日志
  3125. byterequest, _ := json.Marshal(advice)
  3126. doctorAdviceLog := models.XtDoctorAdviceLog{
  3127. UserOrgId: advice.UserOrgId,
  3128. PatientId: advice.PatientId,
  3129. AdminUserId: adminUserInfo.AdminUser.Id,
  3130. Module: 1,
  3131. ErrLog: string(byterequest),
  3132. Status: 1,
  3133. Ctime: time.Now().Unix(),
  3134. Mtime: 0,
  3135. Source: "电脑端修改医嘱",
  3136. RecordDate: advice.AdviceDate,
  3137. }
  3138. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3139. redis := service.RedisClient()
  3140. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3141. redis.Set(key, "", time.Second)
  3142. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3143. redis.Set(keyOne, "", time.Second)
  3144. defer redis.Close()
  3145. if err != nil {
  3146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3147. return
  3148. }
  3149. c.ServeSuccessJSON(map[string]interface{}{
  3150. "msg": "ok",
  3151. "advice": advice,
  3152. })
  3153. return
  3154. }
  3155. func (c *PatientApiController) StopGroupAdvice() {
  3156. groupNo, _ := c.GetInt64("groupno", 0)
  3157. if groupNo <= 0 {
  3158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3159. return
  3160. }
  3161. adminUserInfo := c.GetAdminUserInfo()
  3162. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3163. if advice.ID == 0 {
  3164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3165. return
  3166. }
  3167. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3169. return
  3170. }
  3171. dataBody := make(map[string]interface{}, 0)
  3172. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3173. if err != nil {
  3174. utils.ErrorLog(err.Error())
  3175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3176. return
  3177. }
  3178. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3179. utils.ErrorLog("stop_time")
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3181. return
  3182. }
  3183. stopTime, _ := dataBody["stop_time"].(string)
  3184. if len(stopTime) == 0 {
  3185. utils.ErrorLog("len(stop_time) == 0")
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3187. return
  3188. }
  3189. timeLayout := "2006-01-02"
  3190. loc, _ := time.LoadLocation("Local")
  3191. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3192. if err != nil {
  3193. utils.ErrorLog(err.Error())
  3194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3195. return
  3196. }
  3197. advice.StopTime = theTime.Unix()
  3198. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3199. stopReason, _ := dataBody["stop_reason"].(string)
  3200. advice.StopReason = stopReason
  3201. }
  3202. advice.UpdatedTime = time.Now().Unix()
  3203. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3204. advice.StopState = 1
  3205. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  3206. if err != nil {
  3207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3208. return
  3209. }
  3210. c.ServeSuccessJSON(map[string]interface{}{
  3211. "msg": "ok",
  3212. })
  3213. return
  3214. }
  3215. func (c *PatientApiController) StopDoctorAdvice() {
  3216. id, _ := c.GetInt64("id", 0)
  3217. if id <= 0 {
  3218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3219. return
  3220. }
  3221. adminUserInfo := c.GetAdminUserInfo()
  3222. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3223. //
  3224. //if appRole.UserType == 3 {
  3225. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3226. // if getPermissionErr != nil {
  3227. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3228. // return
  3229. // } else if headNursePermission == nil {
  3230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3231. // return
  3232. // }
  3233. //}
  3234. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3235. if advice.ID == 0 {
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3237. return
  3238. }
  3239. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3241. return
  3242. }
  3243. dataBody := make(map[string]interface{}, 0)
  3244. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3245. if err != nil {
  3246. utils.ErrorLog(err.Error())
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3248. return
  3249. }
  3250. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3251. utils.ErrorLog("stop_time")
  3252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3253. return
  3254. }
  3255. stopTime, _ := dataBody["stop_time"].(string)
  3256. if len(stopTime) == 0 {
  3257. utils.ErrorLog("len(stop_time) == 0")
  3258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3259. return
  3260. }
  3261. timeLayout := "2006-01-02"
  3262. loc, _ := time.LoadLocation("Local")
  3263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3264. if err != nil {
  3265. utils.ErrorLog(err.Error())
  3266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3267. return
  3268. }
  3269. advice.StopTime = theTime.Unix()
  3270. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3271. stopReason, _ := dataBody["stop_reason"].(string)
  3272. advice.StopReason = stopReason
  3273. }
  3274. advice.UpdatedTime = time.Now().Unix()
  3275. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3276. advice.StopState = 1
  3277. err = service.StopDoctorAdvice(&advice)
  3278. if err != nil {
  3279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3280. return
  3281. }
  3282. c.ServeSuccessJSON(map[string]interface{}{
  3283. "msg": "ok",
  3284. "advice": advice,
  3285. })
  3286. return
  3287. }
  3288. func (c *PatientApiController) DeleteDoctorAdvice() {
  3289. id, _ := c.GetInt64("id", 0)
  3290. if id <= 0 {
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3292. return
  3293. }
  3294. adminUserInfo := c.GetAdminUserInfo()
  3295. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3296. if advice.ID == 0 {
  3297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3298. return
  3299. }
  3300. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3301. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3302. // return
  3303. //}
  3304. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3305. //
  3306. //if appRole.UserType == 3 {
  3307. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3308. // if getPermissionErr != nil {
  3309. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3310. // return
  3311. // } else if headNursePermission == nil {
  3312. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3313. // return
  3314. // }
  3315. //}
  3316. advice.UpdatedTime = time.Now().Unix()
  3317. advice.Status = 0
  3318. advice.Modifier = adminUserInfo.AdminUser.Id
  3319. // 查询信息规挡的设置天数
  3320. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3321. if infor.ID > 0 && infor.WeekDay > 0 {
  3322. var cha_time int64
  3323. timeNowStr := time.Now().Format("2006-01-02")
  3324. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3325. //今日的日期减去设置的日期
  3326. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3327. if cha_time >= advice.AdviceDate {
  3328. //查询审核是否允许
  3329. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3330. //申请状态不允许的情况 拒绝修改
  3331. if infor.ApplicationStatus != 1 {
  3332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3333. return
  3334. }
  3335. }
  3336. }
  3337. err := service.DeleteDoctorAdvice(&advice)
  3338. //记录日志
  3339. byterequest, _ := json.Marshal(advice)
  3340. doctorAdviceLog := models.XtDoctorAdviceLog{
  3341. UserOrgId: advice.UserOrgId,
  3342. PatientId: advice.PatientId,
  3343. AdminUserId: adminUserInfo.AdminUser.Id,
  3344. Module: 4,
  3345. ErrLog: string(byterequest),
  3346. Status: 1,
  3347. Ctime: time.Now().Unix(),
  3348. Mtime: 0,
  3349. Source: "电脑端删除医嘱",
  3350. RecordDate: advice.RecordDate,
  3351. }
  3352. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3353. redis := service.RedisClient()
  3354. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3355. redis.Set(keyOne, "", time.Second)
  3356. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3357. redis.Set(key, "", time.Second)
  3358. redis.Close()
  3359. if err != nil {
  3360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3361. return
  3362. }
  3363. c.ServeSuccessJSON(map[string]interface{}{
  3364. "msg": "ok",
  3365. })
  3366. return
  3367. }
  3368. func (c *PatientApiController) DeleteGroupAdvice() {
  3369. groupNo, _ := c.GetInt64("groupno", 0)
  3370. if groupNo <= 0 {
  3371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. return
  3373. }
  3374. adminUserInfo := c.GetAdminUserInfo()
  3375. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3376. if advice.ID == 0 {
  3377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3378. return
  3379. }
  3380. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3381. //if appRole.UserType == 3 {
  3382. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3383. // if getPermissionErr != nil {
  3384. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3385. // return
  3386. // } else if headNursePermission == nil {
  3387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3388. // return
  3389. // }
  3390. //}
  3391. // 查询信息规挡的设置天数
  3392. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3393. if infor.ID > 0 && infor.WeekDay > 0 {
  3394. var cha_time int64
  3395. timeNowStr := time.Now().Format("2006-01-02")
  3396. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3397. //今日的日期减去设置的日期
  3398. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3399. if cha_time >= advice.AdviceDate {
  3400. //查询审核是否允许
  3401. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3402. //申请状态不允许的情况 拒绝修改
  3403. if infor.ApplicationStatus != 1 {
  3404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3405. return
  3406. }
  3407. }
  3408. }
  3409. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3410. byterequest, _ := json.Marshal(advice)
  3411. doctorAdviceLog := models.XtDoctorAdviceLog{
  3412. UserOrgId: advice.UserOrgId,
  3413. PatientId: advice.PatientId,
  3414. AdminUserId: adminUserInfo.AdminUser.Id,
  3415. Module: 4,
  3416. ErrLog: string(byterequest),
  3417. Status: 1,
  3418. Ctime: time.Now().Unix(),
  3419. Mtime: 0,
  3420. Source: "电脑端批量删除医嘱",
  3421. RecordDate: advice.RecordDate,
  3422. }
  3423. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3424. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3425. redis := service.RedisClient()
  3426. redis.Set(key, "", time.Second)
  3427. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3428. redis.Set(keyOne, "", time.Second)
  3429. defer redis.Close()
  3430. if err != nil {
  3431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3432. return
  3433. }
  3434. c.ServeSuccessJSON(map[string]interface{}{
  3435. "msg": "ok",
  3436. })
  3437. return
  3438. }
  3439. // GetDoctorAdvices 医嘱列表
  3440. func (c *PatientApiController) GetDoctorAdvices() {
  3441. id, _ := c.GetInt64("id", 0)
  3442. adviceType, _ := c.GetInt64("advice_type", 0)
  3443. stopType, _ := c.GetInt64("stop_state", 0)
  3444. startTime := c.GetString("start_time", "")
  3445. endTime := c.GetString("end_time", "")
  3446. keywords := c.GetString("keywords", "")
  3447. page, _ := c.GetInt64("page")
  3448. fmt.Println("page", page)
  3449. limit, _ := c.GetInt64("limit")
  3450. fmt.Println("limit", limit)
  3451. adminUserInfo := c.GetAdminUserInfo()
  3452. operatorIDs := make([]int64, 0)
  3453. timeLayout := "2006-01-02"
  3454. loc, _ := time.LoadLocation("Local")
  3455. var theStartTIme int64
  3456. if len(startTime) > 0 {
  3457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3458. if err != nil {
  3459. utils.ErrorLog(err.Error())
  3460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3461. return
  3462. }
  3463. theStartTIme = theTime.Unix()
  3464. }
  3465. var theEndtTIme int64
  3466. if len(endTime) > 0 {
  3467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3468. if err != nil {
  3469. utils.ErrorLog(err.Error())
  3470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3471. return
  3472. }
  3473. theEndtTIme = theTime.Unix()
  3474. }
  3475. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3476. if hisconfig.IsOpen == 1 {
  3477. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3478. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3479. if len(advices) > 0 {
  3480. for _, item := range advices {
  3481. if item.AdviceDoctor > 0 {
  3482. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3483. }
  3484. if item.ExecutionStaff > 0 {
  3485. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3486. }
  3487. if item.Checker > 0 {
  3488. operatorIDs = append(operatorIDs, item.Checker)
  3489. }
  3490. if item.StopDoctor > 0 {
  3491. operatorIDs = append(operatorIDs, item.StopDoctor)
  3492. }
  3493. }
  3494. }
  3495. //相关操作对应的操作人
  3496. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3497. //获取长期医嘱
  3498. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3499. c.ServeSuccessJSON(map[string]interface{}{
  3500. "advices": advices,
  3501. "operators": operators,
  3502. "total": total,
  3503. "advicetwo": advicestwo,
  3504. "longAdvice": longAdvice,
  3505. "is_open": hisconfig.IsOpen,
  3506. })
  3507. return
  3508. } else {
  3509. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3510. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3511. if len(advices) > 0 {
  3512. for _, item := range advices {
  3513. if item.AdviceDoctor > 0 {
  3514. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3515. }
  3516. if item.ExecutionStaff > 0 {
  3517. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3518. }
  3519. if item.Checker > 0 {
  3520. operatorIDs = append(operatorIDs, item.Checker)
  3521. }
  3522. if item.StopDoctor > 0 {
  3523. operatorIDs = append(operatorIDs, item.StopDoctor)
  3524. }
  3525. }
  3526. }
  3527. //相关操作对应的操作人
  3528. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3529. c.ServeSuccessJSON(map[string]interface{}{
  3530. "advices": advices,
  3531. "operators": operators,
  3532. "total": total,
  3533. "advicetwo": advicestwo,
  3534. "is_open": hisconfig.IsOpen,
  3535. })
  3536. return
  3537. }
  3538. }
  3539. func (c *PatientApiController) GetPatientSchedules() {
  3540. id, _ := c.GetInt64("id", 0)
  3541. if id <= 0 {
  3542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3543. return
  3544. }
  3545. adminUserInfo := c.GetAdminUserInfo()
  3546. todayTime := time.Now().Format("2006-01-02")
  3547. timeLayout := "2006-01-02 15:04:05"
  3548. loc, _ := time.LoadLocation("Local")
  3549. var theStartTime int64
  3550. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3551. theStartTime = theTime.Unix()
  3552. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3553. if len(schedules) > 0 {
  3554. for index, item := range schedules {
  3555. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3556. schedules[index].Week = int64(week)
  3557. }
  3558. }
  3559. c.ServeSuccessJSON(map[string]interface{}{
  3560. "schedules": schedules,
  3561. })
  3562. return
  3563. }
  3564. func (c *PatientApiController) GetPatientDialysisRecords() {
  3565. patientID, _ := c.GetInt64("patient_id", 0)
  3566. page, _ := c.GetInt64("page", 0)
  3567. limit, _ := c.GetInt64("limit", 0)
  3568. startTime := c.GetString("start_time", "")
  3569. endTime := c.GetString("end_time", "")
  3570. mode_id, _ := c.GetInt64("mode_id", 0)
  3571. if page <= 0 {
  3572. page = 1
  3573. }
  3574. if limit <= 0 {
  3575. limit = 10
  3576. }
  3577. if patientID <= 0 {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3579. return
  3580. }
  3581. timeLayout := "2006-01-02"
  3582. loc, _ := time.LoadLocation("Local")
  3583. var theStartTIme int64
  3584. if len(startTime) > 0 {
  3585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3586. if err != nil {
  3587. theStartTIme = 0
  3588. }
  3589. theStartTIme = theTime.Unix()
  3590. }
  3591. var theEndtTIme int64
  3592. if len(endTime) > 0 {
  3593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3594. if err != nil {
  3595. theEndtTIme = 0
  3596. }
  3597. theEndtTIme = theTime.Unix()
  3598. }
  3599. adminInfo := c.GetAdminUserInfo()
  3600. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3601. if len(records) == 0 {
  3602. list, _ := service.GetAllDialysisOrder(patientID)
  3603. for _, item := range list {
  3604. schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
  3605. service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
  3606. }
  3607. }
  3608. c.ServeSuccessJSON(map[string]interface{}{
  3609. "total": total,
  3610. "records": records,
  3611. })
  3612. return
  3613. }
  3614. func (c *PatientApiController) ProEducation() {
  3615. patientID, _ := c.GetInt64("patient_id", 0)
  3616. page, _ := c.GetInt64("page", 0)
  3617. limit, _ := c.GetInt64("limit", 0)
  3618. startTime := c.GetString("start_time", "")
  3619. endTime := c.GetString("end_time", "")
  3620. if page <= 0 {
  3621. page = 1
  3622. }
  3623. if limit <= 0 {
  3624. limit = 10
  3625. }
  3626. if patientID <= 0 {
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3628. return
  3629. }
  3630. timeLayout := "2006-01-02"
  3631. loc, _ := time.LoadLocation("Local")
  3632. var theStartTIme int64
  3633. if len(startTime) > 0 {
  3634. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3635. if err != nil {
  3636. theStartTIme = 0
  3637. }
  3638. theStartTIme = theTime.Unix()
  3639. }
  3640. var theEndtTIme int64
  3641. if len(endTime) > 0 {
  3642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3643. if err != nil {
  3644. theEndtTIme = 0
  3645. }
  3646. theEndtTIme = theTime.Unix()
  3647. }
  3648. adminInfo := c.GetAdminUserInfo()
  3649. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3650. c.ServeSuccessJSON(map[string]interface{}{
  3651. "total": total,
  3652. "edus": edus,
  3653. })
  3654. return
  3655. }
  3656. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3657. dataBody := make(map[string]interface{}, 0)
  3658. err := json.Unmarshal(data, &dataBody)
  3659. if err != nil {
  3660. utils.ErrorLog(err.Error())
  3661. code = enums.ErrorCodeParamWrong
  3662. return
  3663. }
  3664. timeLayout := "2006-01-02"
  3665. loc, _ := time.LoadLocation("Local")
  3666. isChild := false
  3667. if action == "create" {
  3668. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3669. utils.ErrorLog("advice_type")
  3670. code = enums.ErrorCodeParamWrong
  3671. return
  3672. }
  3673. adviceType := int64(dataBody["advice_type"].(float64))
  3674. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3675. utils.ErrorLog("advice_type != 1&&2")
  3676. code = enums.ErrorCodeParamWrong
  3677. return
  3678. }
  3679. advice.AdviceType = adviceType
  3680. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3681. utils.ErrorLog("advice_date")
  3682. code = enums.ErrorCodeParamWrong
  3683. return
  3684. }
  3685. adviceDate, _ := dataBody["advice_date"].(string)
  3686. if len(adviceDate) == 0 {
  3687. utils.ErrorLog("len(adviceDate) == 0")
  3688. code = enums.ErrorCodeParamWrong
  3689. return
  3690. }
  3691. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3692. if err != nil {
  3693. utils.ErrorLog(err.Error())
  3694. code = enums.ErrorCodeParamWrong
  3695. return
  3696. }
  3697. advice.AdviceDate = theTime.Unix()
  3698. advice.RecordDate = theTime.Unix()
  3699. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3700. parentId := int64(dataBody["parent_id"].(float64))
  3701. advice.ParentId = parentId
  3702. if parentId > 0 {
  3703. isChild = true
  3704. }
  3705. }
  3706. }
  3707. if !isChild {
  3708. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3709. utils.ErrorLog("start_time")
  3710. code = enums.ErrorCodeParamWrong
  3711. return
  3712. }
  3713. startTime, _ := dataBody["start_time"].(string)
  3714. if len(startTime) == 0 {
  3715. utils.ErrorLog("len(start_time) == 0")
  3716. code = enums.ErrorCodeParamWrong
  3717. return
  3718. }
  3719. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3720. if err != nil {
  3721. utils.ErrorLog(err.Error())
  3722. code = enums.ErrorCodeParamWrong
  3723. return
  3724. }
  3725. advice.StartTime = theTime.Unix()
  3726. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3727. // utils.ErrorLog("advice_doctor")
  3728. // code = enums.ErrorCodeParamWrong
  3729. // return
  3730. // }
  3731. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3732. // if adviceDoctor <= 0 {
  3733. // utils.ErrorLog("advice_doctor <=0")
  3734. // code = enums.ErrorCodeParamWrong
  3735. // return
  3736. // }
  3737. // advice.AdviceDoctor = adviceDoctor
  3738. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3739. deliveryWay, _ := dataBody["delivery_way"].(string)
  3740. advice.DeliveryWay = deliveryWay
  3741. }
  3742. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3743. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3744. advice.ExecutionFrequency = executionFrequency
  3745. }
  3746. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3747. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3748. frequency_type := int64(dataBody["frequency_type"].(float64))
  3749. advice.FrequencyType = frequency_type
  3750. }
  3751. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3752. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3753. advice.DayCount = day_count
  3754. }
  3755. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3756. week_day, _ := dataBody["week_days"].(string)
  3757. advice.WeekDay = week_day
  3758. }
  3759. }
  3760. }
  3761. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3762. utils.ErrorLog("advice_name")
  3763. code = enums.ErrorCodeParamWrong
  3764. return
  3765. }
  3766. adviceName, _ := dataBody["advice_name"].(string)
  3767. if len(adviceName) == 0 {
  3768. utils.ErrorLog("len(advice_name) == 0")
  3769. code = enums.ErrorCodeParamWrong
  3770. return
  3771. }
  3772. advice.AdviceName = adviceName
  3773. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3774. adviceDsc, _ := dataBody["advice_desc"].(string)
  3775. advice.AdviceDesc = adviceDsc
  3776. }
  3777. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3778. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3779. advice.DialysisOrderId = int64(dialysisOrderId)
  3780. }
  3781. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3782. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3783. advice.SingleDose = singleDose
  3784. }
  3785. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3786. singleDose := dataBody["single_dose"].(float64)
  3787. advice.SingleDose = singleDose
  3788. }
  3789. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3790. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3791. advice.SingleDoseUnit = singleDoseUnit
  3792. }
  3793. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3794. tmp := dataBody["single_dose_unit"].(float64)
  3795. singleDoseUnit := service.TypeConversion(tmp)
  3796. advice.SingleDoseUnit = singleDoseUnit
  3797. }
  3798. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3799. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3800. advice.DrugSpec = drugSpec
  3801. }
  3802. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3803. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3804. advice.DrugSpecUnit = drugSpecUnit
  3805. }
  3806. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3807. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3808. advice.PrescribingNumber = prescribingNumber
  3809. }
  3810. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3811. prescribingNumber := dataBody["prescribing_number"].(float64)
  3812. advice.PrescribingNumber = prescribingNumber
  3813. }
  3814. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3815. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3816. advice.PrescribingNumberUnit = prescribingNumberUnit
  3817. }
  3818. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3819. remark, _ := dataBody["remark"].(string)
  3820. advice.Remark = remark
  3821. }
  3822. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3823. drug_id, _ := dataBody["drug_id"].(string)
  3824. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3825. advice.DrugId = tmpDrugId
  3826. }
  3827. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3828. drug_id, _ := dataBody["drug_id"].(float64)
  3829. advice.DrugId = int64(drug_id)
  3830. }
  3831. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3832. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3833. advice.DrugNameId = int64(drug_name_id)
  3834. }
  3835. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3836. way, _ := dataBody["way"].(float64)
  3837. advice.Way = int64(way)
  3838. }
  3839. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3840. push_start_time, _ := dataBody["push_start_time"].(string)
  3841. var startTime int64
  3842. if len(push_start_time) > 0 {
  3843. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3844. startTime = theTime.Unix()
  3845. }
  3846. advice.PushStartTime = startTime
  3847. }
  3848. return
  3849. }
  3850. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3851. dataBody := make(map[string]interface{}, 0)
  3852. err := json.Unmarshal(data, &dataBody)
  3853. utils.InfoLog(string(data))
  3854. if err != nil {
  3855. utils.ErrorLog(err.Error())
  3856. code = enums.ErrorCodeParamWrong
  3857. return
  3858. }
  3859. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3860. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3861. solution.DialysisDuration = dialysisDuration
  3862. }
  3863. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3864. replacementWay := int64(dataBody["replacement_way"].(float64))
  3865. solution.ReplacementWay = replacementWay
  3866. }
  3867. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3868. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3869. solution.BloodFlowVolume = bloodFlowVolume
  3870. }
  3871. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3872. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3873. solution.HemodialysisMachine = hemodialysisMachine
  3874. }
  3875. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3876. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3877. solution.BloodFilter = bloodFilter
  3878. }
  3879. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3880. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3881. solution.PerfusionApparatus = perfusionApparatus
  3882. }
  3883. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3884. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3885. solution.DialysateFlow = dialysateFlow
  3886. }
  3887. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3888. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3889. solution.Kalium = kalium
  3890. }
  3891. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3892. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3893. solution.Sodium = sodium
  3894. }
  3895. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3896. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3897. solution.Calcium = calcium
  3898. }
  3899. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3900. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3901. solution.Bicarbonate = bicarbonate
  3902. }
  3903. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3904. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3905. solution.Anticoagulant = anticoagulant
  3906. }
  3907. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3908. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3909. solution.AnticoagulantShouji = anticoagulantShouji
  3910. }
  3911. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3912. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3913. solution.AnticoagulantWeichi = anticoagulantWeichi
  3914. }
  3915. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3916. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3917. solution.AnticoagulantZongliang = anticoagulantZongliang
  3918. }
  3919. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3920. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3921. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3922. }
  3923. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3924. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3925. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3926. }
  3927. return
  3928. }
  3929. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3930. dataBody := make(map[string]interface{}, 0)
  3931. err := json.Unmarshal(data, &dataBody)
  3932. utils.InfoLog(string(data))
  3933. if err != nil {
  3934. utils.ErrorLog(err.Error())
  3935. code = enums.ErrorCodeParamWrong
  3936. return
  3937. }
  3938. if method == "create" {
  3939. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3940. utils.ErrorLog("mode")
  3941. code = enums.ErrorCodeParamWrong
  3942. return
  3943. }
  3944. mode := int64(dataBody["mode"].(float64))
  3945. if mode <= 0 {
  3946. utils.ErrorLog("mode <= 0")
  3947. code = enums.ErrorCodeParamWrong
  3948. return
  3949. }
  3950. solution.ModeId = mode
  3951. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3952. utils.ErrorLog("mode_name")
  3953. code = enums.ErrorCodeParamWrong
  3954. return
  3955. }
  3956. modeName, _ := dataBody["mode_name"].(string)
  3957. if len(modeName) == 0 {
  3958. utils.ErrorLog("len(mode_name) == 0")
  3959. code = enums.ErrorCodeParamWrong
  3960. return
  3961. }
  3962. solution.ModeName = modeName
  3963. solution.Name = modeName
  3964. }
  3965. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3966. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3967. solution.DialysisDuration = dialysisDuration
  3968. }
  3969. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3970. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3971. solution.TargetUltrafiltration = targetUltrafiltration
  3972. }
  3973. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3974. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3975. solution.DialysateFormulation = dialysateFormulation
  3976. }
  3977. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3978. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3979. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3980. }
  3981. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3982. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3983. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3984. }
  3985. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3986. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3987. solution.HemodialysisMachine = hemodialysisMachine
  3988. }
  3989. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3990. dialyzer := int64(dataBody["dialyzer"].(float64))
  3991. solution.Dialyzer = dialyzer
  3992. }
  3993. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3994. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3995. solution.PerfusionApparatus = perfusionApparatus
  3996. }
  3997. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3998. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3999. solution.BloodFlowVolume = bloodFlowVolume
  4000. }
  4001. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  4002. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  4003. solution.Dewater = dewater
  4004. }
  4005. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  4006. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  4007. solution.DisplaceLiqui = displaceLiqui
  4008. }
  4009. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4010. replacementWay := int64(dataBody["replacement_way"].(float64))
  4011. solution.ReplacementWay = replacementWay
  4012. }
  4013. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4014. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4015. solution.Anticoagulant = anticoagulant
  4016. }
  4017. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4018. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4019. solution.AnticoagulantShouji = anticoagulantShouji
  4020. }
  4021. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4022. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4023. solution.AnticoagulantWeichi = anticoagulantWeichi
  4024. }
  4025. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4026. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4027. solution.AnticoagulantZongliang = anticoagulantZongliang
  4028. }
  4029. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4030. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4031. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4032. }
  4033. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4034. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4035. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4036. }
  4037. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4038. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4039. solution.Kalium = kalium
  4040. }
  4041. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4042. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4043. solution.Sodium = sodium
  4044. }
  4045. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4046. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4047. solution.Calcium = calcium
  4048. }
  4049. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4050. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4051. solution.Bicarbonate = bicarbonate
  4052. }
  4053. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4054. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4055. solution.Glucose = glucose
  4056. }
  4057. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4058. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4059. // solution.DryWeight = dryWeight
  4060. // }
  4061. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4062. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4063. solution.DialysateFlow = dialysateFlow
  4064. }
  4065. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4066. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4067. solution.DialysateTemperature = dialysateTemperature
  4068. }
  4069. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4070. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4071. solution.Conductivity = conductivity
  4072. }
  4073. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  4074. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  4075. solution.ReplacementTotal = replacementTotal
  4076. }
  4077. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  4078. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  4079. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  4080. }
  4081. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  4082. body_fluid := int64(dataBody["body_fluid"].(float64))
  4083. solution.BodyFluid = body_fluid
  4084. }
  4085. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  4086. body_fluid_other := dataBody["body_fluid_other"].(string)
  4087. solution.BodyFluidOther = body_fluid_other
  4088. }
  4089. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  4090. special_medicine := int64(dataBody["special_medicine"].(float64))
  4091. solution.SpecialMedicine = special_medicine
  4092. }
  4093. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  4094. special_medicine_other := dataBody["special_medicine_other"].(string)
  4095. solution.SpecialMedicineOther = special_medicine_other
  4096. }
  4097. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  4098. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  4099. solution.DisplaceLiquiPart = displace_liqui_part
  4100. }
  4101. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  4102. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  4103. solution.DisplaceLiquiValue = displace_liqui_value
  4104. }
  4105. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  4106. blood_access := int64(dataBody["blood_access"].(float64))
  4107. solution.BloodAccess = blood_access
  4108. }
  4109. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  4110. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  4111. solution.Ultrafiltration = ultrafiltration
  4112. }
  4113. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  4114. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  4115. solution.TargetKtv = target_ktv
  4116. }
  4117. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4118. remark := dataBody["remark"].(string)
  4119. solution.Remark = remark
  4120. }
  4121. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  4122. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  4123. solution.HemodialysisPipelines = hemodialysis_pipelines
  4124. }
  4125. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  4126. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  4127. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  4128. }
  4129. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4130. puncture_needle := dataBody["puncture_needle"].(string)
  4131. solution.PunctureNeedle = puncture_needle
  4132. }
  4133. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  4134. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  4135. solution.PunctureNeedleCount = puncture_needle_count
  4136. }
  4137. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  4138. epo := dataBody["epo"].(string)
  4139. solution.Epo = epo
  4140. }
  4141. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  4142. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  4143. solution.EpoCount = epo_count
  4144. }
  4145. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  4146. created_time := int64(dataBody["created_time"].(float64))
  4147. solution.CreatedTime = created_time
  4148. }
  4149. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  4150. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  4151. solution.DialysisDialyszers = dialysisDialyszers
  4152. }
  4153. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  4154. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  4155. solution.DialysisIrrigation = dialysisIrrigation
  4156. }
  4157. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  4158. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  4159. solution.DialysisStrainer = dialysis_strainer
  4160. }
  4161. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  4162. plasmaSeparator := dataBody["plasma_separator"].(string)
  4163. solution.PlasmaSeparator = plasmaSeparator
  4164. }
  4165. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  4166. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  4167. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  4168. }
  4169. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  4170. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  4171. solution.OxygenUptake = oxygen_uptake
  4172. }
  4173. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  4174. oxygen_flow := dataBody["oxygen_flow"].(string)
  4175. solution.OxygenFlow = oxygen_flow
  4176. }
  4177. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  4178. oxygen_time := dataBody["oxygen_time"].(string)
  4179. solution.OxygenTime = oxygen_time
  4180. }
  4181. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  4182. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  4183. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  4184. }
  4185. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  4186. amylaceum := dataBody["amylaceum"].(string)
  4187. solution.Amylaceum = amylaceum
  4188. }
  4189. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  4190. chaptalization := dataBody["chaptalization"].(string)
  4191. solution.Chaptalization = chaptalization
  4192. }
  4193. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4194. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4195. solution.BloodAccessPartId = blood_access_part_id
  4196. }
  4197. return
  4198. }
  4199. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4200. dataBody := make(map[string]interface{}, 0)
  4201. err := json.Unmarshal(data, &dataBody)
  4202. utils.InfoLog(string(data))
  4203. if err != nil {
  4204. utils.ErrorLog(err.Error())
  4205. code = enums.ErrorCodeParamWrong
  4206. return
  4207. }
  4208. if method == "create" {
  4209. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  4210. utils.ErrorLog("parent_id")
  4211. code = enums.ErrorCodeParamWrong
  4212. return
  4213. }
  4214. parentID := int64(dataBody["parent_id"].(float64))
  4215. if parentID <= 0 {
  4216. utils.ErrorLog("parentID <= 0")
  4217. code = enums.ErrorCodeParamWrong
  4218. return
  4219. }
  4220. solution.ParentId = parentID
  4221. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  4222. utils.ErrorLog("sub_name")
  4223. code = enums.ErrorCodeParamWrong
  4224. return
  4225. }
  4226. subName, _ := dataBody["sub_name"].(string)
  4227. if len(subName) == 0 {
  4228. utils.ErrorLog("len(sub_name) == 0")
  4229. code = enums.ErrorCodeParamWrong
  4230. return
  4231. }
  4232. solution.SubName = subName
  4233. }
  4234. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4235. utils.ErrorLog("initiate_mode")
  4236. code = enums.ErrorCodeParamWrong
  4237. return
  4238. }
  4239. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4240. if initiateMode != 1 && initiateMode != 2 {
  4241. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4242. code = enums.ErrorCodeParamWrong
  4243. return
  4244. }
  4245. solution.InitiateMode = initiateMode
  4246. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4247. utils.ErrorLog("doctor")
  4248. code = enums.ErrorCodeParamWrong
  4249. return
  4250. }
  4251. doctor := int64(dataBody["doctor"].(float64))
  4252. if doctor <= 0 {
  4253. utils.ErrorLog("doctor <= 0")
  4254. code = enums.ErrorCodeParamWrong
  4255. return
  4256. }
  4257. solution.Doctor = doctor
  4258. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4259. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4260. solution.BloodAccessPartId = blood_access_part_id
  4261. }
  4262. return
  4263. }
  4264. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4265. patientBody := make(map[string]interface{}, 0)
  4266. err := json.Unmarshal(data, &patientBody)
  4267. if err != nil {
  4268. utils.ErrorLog(err.Error())
  4269. code = enums.ErrorCodeParamWrong
  4270. return
  4271. }
  4272. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4273. formItem, _ := patientBody["formItem"].([]interface{})
  4274. if len(formItem) > 0 {
  4275. for _, item := range formItem {
  4276. items := item.(map[string]interface{})
  4277. project_name, _ := items["project_name"].(string)
  4278. fmt.Println(project_name)
  4279. range_type := int64(items["range_type"].(float64))
  4280. fmt.Println(range_type)
  4281. project_id := int64(items["project_id"].(float64))
  4282. fmt.Println(project_id)
  4283. item_id := int64(items["item_id"].(float64))
  4284. fmt.Println(item_id)
  4285. item, _ := items["item"].(string)
  4286. fmt.Println(items["item"].(string))
  4287. item_name, _ := items["item_name"].(string)
  4288. fmt.Println(item_name)
  4289. value, _ := items["value"].(string)
  4290. fmt.Println(items["value"].(string))
  4291. var form models.FormItem
  4292. form.ProjectName = project_name
  4293. form.RangeType = range_type
  4294. form.ProjectId = project_id
  4295. form.ItemId = item_id
  4296. form.Item = item
  4297. form.ItemName = item_name
  4298. form.Value = value
  4299. formItems = append(formItems, &form)
  4300. }
  4301. }
  4302. }
  4303. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4304. utils.ErrorLog("avatar")
  4305. code = enums.ErrorCodeParamWrong
  4306. return
  4307. }
  4308. avatar, _ := patientBody["avatar"].(string)
  4309. if len(avatar) == 0 {
  4310. utils.ErrorLog("len(avatar) == 0")
  4311. code = enums.ErrorCodeParamWrong
  4312. return
  4313. }
  4314. patient.Avatar = avatar
  4315. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4316. utils.ErrorLog("name")
  4317. code = enums.ErrorCodeParamWrong
  4318. return
  4319. }
  4320. name, _ := patientBody["name"].(string)
  4321. if len(name) == 0 {
  4322. utils.ErrorLog("len(name) == 0")
  4323. code = enums.ErrorCodeParamWrong
  4324. return
  4325. }
  4326. patient.Name = name
  4327. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4328. alias := patientBody["alias"].(string)
  4329. patient.Alias = alias
  4330. }
  4331. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4332. nation := patientBody["nation"].(string)
  4333. patient.Nation = nation
  4334. }
  4335. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4336. native_place := patientBody["native_place"].(string)
  4337. patient.NativePlace = native_place
  4338. }
  4339. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4340. utils.ErrorLog("idCardNo")
  4341. code = enums.ErrorCodeParamWrong
  4342. return
  4343. }
  4344. idCardNo, _ := patientBody["idCardNo"].(string)
  4345. if len(idCardNo) == 0 {
  4346. utils.ErrorLog("len(idCardNo) == 0")
  4347. code = enums.ErrorCodeParamWrong
  4348. return
  4349. }
  4350. patient.IdCardNo = idCardNo
  4351. patient.PatientType = 1
  4352. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4353. utils.ErrorLog("dialysisNo")
  4354. code = enums.ErrorCodeParamWrong
  4355. return
  4356. }
  4357. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4358. if len(dialysisNo) == 0 {
  4359. utils.ErrorLog("len(dialysisNo) == 0")
  4360. code = enums.ErrorCodeParamWrong
  4361. return
  4362. }
  4363. patient.DialysisNo = dialysisNo
  4364. // }
  4365. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4366. utils.ErrorLog("lapseto")
  4367. code = enums.ErrorCodeParamWrong
  4368. return
  4369. }
  4370. lapseto := int64(patientBody["lapseto"].(float64))
  4371. if lapseto <= 0 {
  4372. utils.ErrorLog("lapseto == 0")
  4373. code = enums.ErrorCodeParamWrong
  4374. return
  4375. }
  4376. patient.Lapseto = lapseto
  4377. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4378. utils.ErrorLog("gender")
  4379. code = enums.ErrorCodeParamWrong
  4380. return
  4381. }
  4382. gender := int64(patientBody["gender"].(float64))
  4383. if gender <= 0 {
  4384. utils.ErrorLog("gender <= 0")
  4385. code = enums.ErrorCodeParamWrong
  4386. return
  4387. }
  4388. patient.Gender = gender
  4389. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4390. response_result := patientBody["response_result"].(string)
  4391. patient.ResponseResult = response_result
  4392. }
  4393. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4394. utils.ErrorLog("age")
  4395. code = enums.ErrorCodeParamWrong
  4396. return
  4397. }
  4398. age := int64(patientBody["age"].(float64))
  4399. patient.Age = age
  4400. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4401. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4402. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4403. patient.UserSysBeforeCount = count
  4404. }
  4405. timeLayout := "2006-01-02"
  4406. loc, _ := time.LoadLocation("Local")
  4407. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4408. utils.ErrorLog("birth")
  4409. code = enums.ErrorCodeParamWrong
  4410. return
  4411. }
  4412. birth, _ := patientBody["birth"].(string)
  4413. if len(birth) == 0 {
  4414. utils.ErrorLog("len(birth) == 0")
  4415. code = enums.ErrorCodeParamWrong
  4416. return
  4417. }
  4418. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4419. if err != nil {
  4420. utils.ErrorLog("birthTime")
  4421. code = enums.ErrorCodeParamWrong
  4422. return
  4423. }
  4424. patient.Birthday = birthTime.Unix()
  4425. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4426. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4427. patient.Height = height
  4428. }
  4429. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4430. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4431. patient.MaritalStatus = maritalStatus
  4432. }
  4433. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4434. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4435. patient.Children = children
  4436. }
  4437. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4438. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4439. patient.AdmissionNumber = admissionNumber
  4440. }
  4441. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4442. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4443. patient.ReimbursementWayId = reimbursementWayID
  4444. }
  4445. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4446. healthCareNo := patientBody["healthCareNo"].(string)
  4447. patient.HealthCareNo = healthCareNo
  4448. }
  4449. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4450. utils.ErrorLog("phone")
  4451. code = enums.ErrorCodeParamWrong
  4452. return
  4453. }
  4454. phone := patientBody["phone"].(string)
  4455. if len(phone) == 0 {
  4456. utils.ErrorLog("len(phone) == 0")
  4457. code = enums.ErrorCodeParamWrong
  4458. return
  4459. }
  4460. if !utils.CheckMobile(phone) {
  4461. utils.ErrorLog("!phone")
  4462. code = enums.ErrorCodeMobileFormat
  4463. return
  4464. }
  4465. patient.Phone = phone
  4466. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4467. homeTelephone := patientBody["homeTelephone"].(string)
  4468. patient.HomeTelephone = homeTelephone
  4469. }
  4470. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4471. relativePhone := patientBody["relative_phone"].(string)
  4472. patient.RelativePhone = relativePhone
  4473. }
  4474. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4475. relativeRelations := patientBody["relative_relations"].(string)
  4476. patient.RelativeRelations = relativeRelations
  4477. }
  4478. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4479. homeAddress := patientBody["homeAddress"].(string)
  4480. patient.HomeAddress = homeAddress
  4481. }
  4482. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4483. work := patientBody["work"].(string)
  4484. patient.WorkUnit = work
  4485. }
  4486. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4487. unitAddress := patientBody["unit_address"].(string)
  4488. patient.UnitAddress = unitAddress
  4489. }
  4490. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4491. profession := int64(patientBody["profession"].(float64))
  4492. patient.Profession = profession
  4493. }
  4494. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4495. education := int64(patientBody["education"].(float64))
  4496. patient.EducationLevel = education
  4497. }
  4498. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4499. utils.ErrorLog("source")
  4500. code = enums.ErrorCodeParamWrong
  4501. return
  4502. }
  4503. source := int64(patientBody["source"].(float64))
  4504. if source <= 0 {
  4505. utils.ErrorLog("source <= 0")
  4506. code = enums.ErrorCodeParamWrong
  4507. return
  4508. }
  4509. patient.Source = source
  4510. zb_patient_id := patientBody["zb_patient_id"].(string)
  4511. patient.ZbPatientId = zb_patient_id
  4512. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4513. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4514. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4515. }
  4516. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4517. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4518. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4519. if err == nil {
  4520. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4521. }
  4522. }
  4523. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4524. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4525. patient.FirstDialysisHospital = firstDialysisHospital
  4526. }
  4527. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4528. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4529. if len(thePredialysisCondition) > 0 {
  4530. conditions := make([]string, 0)
  4531. for _, item := range thePredialysisCondition {
  4532. if reflect.TypeOf(item).String() != "string" {
  4533. continue
  4534. }
  4535. condition := item.(string)
  4536. if len(condition) > 0 {
  4537. conditions = append(conditions, condition)
  4538. }
  4539. }
  4540. patient.PredialysisCondition = strings.Join(conditions, ",")
  4541. }
  4542. }
  4543. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4544. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4545. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4546. }
  4547. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4548. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4549. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4550. }
  4551. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4552. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4553. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4554. if err == nil {
  4555. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4556. }
  4557. }
  4558. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4559. partition := int64(patientBody["partition"].(float64))
  4560. patient.PartitionId = partition
  4561. }
  4562. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4563. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4564. patient.BedId = bed
  4565. }
  4566. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4567. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4568. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4569. if err == nil {
  4570. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4571. }
  4572. }
  4573. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4574. blood := int64(patientBody["blood"].(float64))
  4575. patient.BloodType = blood
  4576. }
  4577. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4578. rh := int64(patientBody["rh"].(float64))
  4579. patient.Rh = rh
  4580. }
  4581. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4582. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4583. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4584. if err == nil {
  4585. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4586. }
  4587. }
  4588. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4589. receivingDate := patientBody["receivingDate"].(string)
  4590. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4591. if err == nil {
  4592. patient.ReceivingDate = receivingDateTime.Unix()
  4593. }
  4594. }
  4595. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4596. induction := int64(patientBody["induction"].(float64))
  4597. patient.InductionPeriod = induction
  4598. }
  4599. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4600. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4601. patient.InitialDialysis = initial
  4602. }
  4603. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4604. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4605. patient.TotalDialysis = dialysisTotal
  4606. }
  4607. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4608. thisContagions, _ := patientBody["contagions"].([]interface{})
  4609. if len(thisContagions) > 0 {
  4610. for _, item := range thisContagions {
  4611. if reflect.TypeOf(item).String() != "float64" {
  4612. continue
  4613. }
  4614. contagion := int64(item.(float64))
  4615. if contagion > 0 {
  4616. contagions = append(contagions, contagion)
  4617. }
  4618. }
  4619. }
  4620. }
  4621. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4622. doctor := int64(patientBody["doctor"].(float64))
  4623. patient.AttendingDoctorId = doctor
  4624. }
  4625. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4626. nurse := int64(patientBody["nurse"].(float64))
  4627. patient.HeadNurseId = nurse
  4628. }
  4629. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4630. assessment := patientBody["assessment"].(string)
  4631. patient.Evaluate = assessment
  4632. }
  4633. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4634. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4635. if len(thisDiseases) > 0 {
  4636. for _, item := range thisDiseases {
  4637. if reflect.TypeOf(item).String() != "float64" {
  4638. continue
  4639. }
  4640. disease := int64(item.(float64))
  4641. if disease > 0 {
  4642. diseases = append(diseases, disease)
  4643. }
  4644. }
  4645. }
  4646. }
  4647. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4648. diagnose := patientBody["diagnose"].(string)
  4649. patient.Diagnose = diagnose
  4650. }
  4651. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4652. remark := patientBody["remark"].(string)
  4653. patient.Remark = remark
  4654. }
  4655. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4656. sch_remark := patientBody["sch_remark"].(string)
  4657. patient.SchRemark = sch_remark
  4658. }
  4659. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4660. patient_complains := patientBody["patient_complains"].(string)
  4661. patient.PatientComplains = patient_complains
  4662. }
  4663. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4664. present_history := patientBody["present_history"].(string)
  4665. patient.PresentHistory = present_history
  4666. }
  4667. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4668. past_history := patientBody["past_history"].(string)
  4669. patient.PastHistory = past_history
  4670. }
  4671. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4672. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4673. patient.Temperature = temperature
  4674. }
  4675. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4676. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4677. patient.Pulse = pulse
  4678. }
  4679. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4680. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4681. patient.Respiratory = respiratory
  4682. }
  4683. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4684. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4685. patient.SBP = sbp
  4686. }
  4687. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4688. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4689. patient.DBP = dbp
  4690. }
  4691. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4692. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4693. patient.DialysisAge = dialysis_age
  4694. }
  4695. fmt.Println(patient.DialysisAge)
  4696. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4697. first_treatment_date := patientBody["first_treatment_date"].(string)
  4698. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4699. if err == nil {
  4700. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4701. }
  4702. }
  4703. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4704. expense_kind := int64(patientBody["expense_kind"].(float64))
  4705. patient.ExpenseKind = expense_kind
  4706. }
  4707. fmt.Println(patient.ExpenseKind)
  4708. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4709. tell_phone := patientBody["tell_phone"].(string)
  4710. patient.TellPhone = tell_phone
  4711. }
  4712. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4713. contact_name := patientBody["contact_name"].(string)
  4714. patient.ContactName = contact_name
  4715. }
  4716. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4717. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4718. patient.TrobleShoot = troble_shoot
  4719. }
  4720. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4721. treatment_plan := patientBody["treatment_plan"].(string)
  4722. patient.TreatmentPlan = treatment_plan
  4723. }
  4724. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4725. doctor := int64(patientBody["doctor"].(float64))
  4726. patient.Doctor = doctor
  4727. }
  4728. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4729. record_number := patientBody["record_number"].(string)
  4730. patient.RecordNumber = record_number
  4731. }
  4732. patient_source := int64(patientBody["patient_source"].(float64))
  4733. if patient_source <= 0 {
  4734. utils.ErrorLog("patient_source <= 0")
  4735. code = enums.ErrorCodeParamWrong
  4736. return
  4737. }
  4738. patient.PatientSource = patient_source
  4739. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4740. patient_start_time := patientBody["patient_start_time"].(string)
  4741. var startTime int64
  4742. if len(patient_start_time) > 0 {
  4743. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4744. startTime = theTime.Unix()
  4745. }
  4746. patient.PatientStartTime = startTime
  4747. }
  4748. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4749. patient_end_time := patientBody["patient_end_time"].(string)
  4750. var endTime int64
  4751. if len(patient_end_time) > 0 {
  4752. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4753. endTime = theTime.Unix()
  4754. }
  4755. patient.PatientEndTime = endTime
  4756. }
  4757. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4758. record_number := patientBody["infectious_remark"].(string)
  4759. patient.InfectiousRemark = record_number
  4760. }
  4761. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4762. allergic_history := patientBody["allergic_history"].(string)
  4763. patient.AllergicHistory = allergic_history
  4764. }
  4765. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4766. patient_address := patientBody["patient_address"].(string)
  4767. patient.PatientAddress = patient_address
  4768. }
  4769. if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
  4770. print_date := patientBody["print_date"].(string)
  4771. printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
  4772. if err == nil {
  4773. patient.PrintDate = printDateTime.Unix()
  4774. }
  4775. }
  4776. return
  4777. }
  4778. func (c *PatientApiController) GetPatientsByKeyWord() {
  4779. keyWord := c.GetString("keyword")
  4780. adminUserInfo := c.GetAdminUserInfo()
  4781. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4782. if err != nil {
  4783. utils.ErrorLog(err.Error())
  4784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4785. return
  4786. }
  4787. c.ServeSuccessJSON(map[string]interface{}{
  4788. "patient": patient,
  4789. })
  4790. }
  4791. func (c *PatientApiController) QueryPatientById() {
  4792. id, _ := c.GetInt64("id")
  4793. fmt.Println(id)
  4794. patientInfo := service.QueryPatientById(id)
  4795. c.ServeSuccessJSON(map[string]interface{}{
  4796. "patient": patientInfo,
  4797. })
  4798. return
  4799. }
  4800. func (c *PatientApiController) GetRemindPatientList() {
  4801. page, _ := c.GetInt64("page", 1)
  4802. limit, _ := c.GetInt64("limit", 10)
  4803. adminUserInfo := c.GetAdminUserInfo()
  4804. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4805. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4806. if errcode == gorm.ErrRecordNotFound {
  4807. information, err := service.GetAdminUserRoleInformation(0)
  4808. if err != nil {
  4809. utils.ErrorLog(err.Error())
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4811. return
  4812. }
  4813. c.ServeSuccessJSON(map[string]interface{}{
  4814. "total": total,
  4815. "patients": patients,
  4816. "information": information,
  4817. })
  4818. } else if errcode == nil {
  4819. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4820. if err != nil {
  4821. utils.ErrorLog(err.Error())
  4822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4823. return
  4824. }
  4825. c.ServeSuccessJSON(map[string]interface{}{
  4826. "total": total,
  4827. "patients": patients,
  4828. "information": information,
  4829. })
  4830. }
  4831. }
  4832. func (c *PatientApiController) PostIsOpenRemind() {
  4833. patient_id, _ := c.GetInt64("id", 1)
  4834. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4835. adminUserInfo := c.GetAdminUserInfo()
  4836. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4837. if err == nil {
  4838. c.ServeSuccessJSON(map[string]interface{}{
  4839. "msg": "成功",
  4840. "is_open_remind": is_open_remind,
  4841. })
  4842. } else if err != nil {
  4843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4844. }
  4845. }
  4846. func (c *PatientApiController) GetPatientScheduleOne() {
  4847. id, _ := c.GetInt64("id")
  4848. //查询该病人是否当天是排班
  4849. nowDateTime := time.Now()
  4850. nowDate := nowDateTime.Format("2006-01-02")
  4851. nowDate += " 00:00:00"
  4852. timeLayout := "2006-01-02"
  4853. loc, _ := time.LoadLocation("Local")
  4854. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4855. nowdate := theTime.Unix()
  4856. fmt.Println("nowdate", nowdate)
  4857. adminUser := c.GetAdminUserInfo()
  4858. orgId := adminUser.CurrentOrgId
  4859. fmt.Println("orgid", orgId)
  4860. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4861. if err != nil {
  4862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4863. return
  4864. }
  4865. c.ServeSuccessJSON(map[string]interface{}{
  4866. "scheduls": scheduls,
  4867. })
  4868. }
  4869. func (c *PatientApiController) ExportPatients() {
  4870. dataBody := make(map[string]interface{}, 0)
  4871. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4872. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4873. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4874. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4875. if err != nil {
  4876. utils.ErrorLog(err.Error())
  4877. return
  4878. }
  4879. utils.ErrorLog("%v", dataBody)
  4880. export_time := time.Now().Unix()
  4881. var patients []*models.Patients
  4882. var total_patients []interface{}
  4883. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4884. tempPatients := dataBody["patients"].([]interface{})
  4885. total_patients = tempPatients
  4886. for index, patientMap := range tempPatients {
  4887. patientNameM := patientMap.(map[string]interface{})
  4888. var patient models.Patients
  4889. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4890. utils.ErrorLog("name")
  4891. return
  4892. }
  4893. name, _ := patientNameM["name"].(string)
  4894. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4895. err_log := models.ExportErrLog{
  4896. LogType: 1,
  4897. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4898. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4899. Status: 1,
  4900. CreateTime: time.Now().Unix(),
  4901. UpdateTime: time.Now().Unix(),
  4902. ExportTime: export_time,
  4903. }
  4904. service.CreateExportErrLog(&err_log)
  4905. continue
  4906. }
  4907. patient.Name = name
  4908. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4909. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4910. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4911. err_log := models.ExportErrLog{
  4912. LogType: 1,
  4913. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4914. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4915. Status: 1,
  4916. CreateTime: time.Now().Unix(),
  4917. UpdateTime: time.Now().Unix(),
  4918. ExportTime: export_time,
  4919. }
  4920. service.CreateExportErrLog(&err_log)
  4921. continue
  4922. } else {
  4923. patient.Gender = gender
  4924. }
  4925. }
  4926. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4927. phone, _ := patientNameM["phone"].(string)
  4928. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4929. if len(phone) == 0 {
  4930. err_log := models.ExportErrLog{
  4931. LogType: 1,
  4932. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4933. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4934. Status: 1,
  4935. CreateTime: time.Now().Unix(),
  4936. UpdateTime: time.Now().Unix(),
  4937. ExportTime: export_time,
  4938. }
  4939. service.CreateExportErrLog(&err_log)
  4940. continue
  4941. } else {
  4942. err_log := models.ExportErrLog{
  4943. LogType: 1,
  4944. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4945. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4946. Status: 1,
  4947. CreateTime: time.Now().Unix(),
  4948. UpdateTime: time.Now().Unix(),
  4949. ExportTime: export_time,
  4950. }
  4951. service.CreateExportErrLog(&err_log)
  4952. continue
  4953. }
  4954. } else {
  4955. //var tempPatient *models.Patients
  4956. //for _, item := range all_patient {
  4957. // if item.Phone == phone {
  4958. // tempPatient = item
  4959. // }
  4960. //}
  4961. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4962. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4963. if count >= 1 {
  4964. err_log := models.ExportErrLog{
  4965. LogType: 1,
  4966. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4967. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4968. Status: 1,
  4969. CreateTime: time.Now().Unix(),
  4970. UpdateTime: time.Now().Unix(),
  4971. ExportTime: export_time,
  4972. }
  4973. service.CreateExportErrLog(&err_log)
  4974. continue
  4975. }
  4976. patient.Phone = phone
  4977. }
  4978. }
  4979. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4980. id_card_no, _ := patientNameM["id_card_no"].(string)
  4981. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4982. if len(id_card_no) == 0 {
  4983. err_log := models.ExportErrLog{
  4984. LogType: 1,
  4985. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4986. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4987. Status: 1,
  4988. CreateTime: time.Now().Unix(),
  4989. UpdateTime: time.Now().Unix(),
  4990. ExportTime: export_time,
  4991. }
  4992. service.CreateExportErrLog(&err_log)
  4993. continue
  4994. } else {
  4995. err_log := models.ExportErrLog{
  4996. LogType: 1,
  4997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4998. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4999. Status: 1,
  5000. CreateTime: time.Now().Unix(),
  5001. UpdateTime: time.Now().Unix(),
  5002. ExportTime: export_time,
  5003. }
  5004. service.CreateExportErrLog(&err_log)
  5005. continue
  5006. }
  5007. } else {
  5008. //var tempPatient *models.Patients
  5009. //for _, item := range all_patient {
  5010. // if item.IdCardNo == id_card_no {
  5011. // tempPatient = item
  5012. // }
  5013. //}
  5014. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5015. if count >= 1 {
  5016. //if tempPatient != nil && tempPatient.ID > 0 {
  5017. err_log := models.ExportErrLog{
  5018. LogType: 1,
  5019. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5020. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  5021. Status: 1,
  5022. CreateTime: time.Now().Unix(),
  5023. UpdateTime: time.Now().Unix(),
  5024. ExportTime: export_time,
  5025. }
  5026. service.CreateExportErrLog(&err_log)
  5027. continue
  5028. }
  5029. //}
  5030. patient.IdCardNo = id_card_no
  5031. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  5032. if GetBirthDay(id_card_no) == nil {
  5033. patient.Birthday = 0
  5034. } else {
  5035. patient.Birthday = GetBirthDay(id_card_no).Unix()
  5036. }
  5037. }
  5038. }
  5039. fmt.Println("111112222")
  5040. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  5041. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  5042. timeLayout := "2006/01/02"
  5043. loc, _ := time.LoadLocation("Local")
  5044. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5045. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5046. if len(first_treatment_date) == 0 {
  5047. err_log := models.ExportErrLog{
  5048. LogType: 1,
  5049. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5050. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5051. Status: 1,
  5052. CreateTime: time.Now().Unix(),
  5053. UpdateTime: time.Now().Unix(),
  5054. ExportTime: export_time,
  5055. }
  5056. service.CreateExportErrLog(&err_log)
  5057. continue
  5058. } else {
  5059. err_log := models.ExportErrLog{
  5060. LogType: 1,
  5061. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5062. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5063. Status: 1,
  5064. CreateTime: time.Now().Unix(),
  5065. UpdateTime: time.Now().Unix(),
  5066. ExportTime: export_time,
  5067. }
  5068. service.CreateExportErrLog(&err_log)
  5069. continue
  5070. }
  5071. } else {
  5072. if len(first_treatment_date) == 0 {
  5073. err_log := models.ExportErrLog{
  5074. LogType: 1,
  5075. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5076. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5077. Status: 1,
  5078. CreateTime: time.Now().Unix(),
  5079. UpdateTime: time.Now().Unix(),
  5080. ExportTime: export_time,
  5081. }
  5082. service.CreateExportErrLog(&err_log)
  5083. continue
  5084. } else {
  5085. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5086. err_log := models.ExportErrLog{
  5087. LogType: 1,
  5088. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5089. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5090. Status: 1,
  5091. CreateTime: time.Now().Unix(),
  5092. UpdateTime: time.Now().Unix(),
  5093. ExportTime: export_time,
  5094. }
  5095. service.CreateExportErrLog(&err_log)
  5096. continue
  5097. } else {
  5098. patient.FirstDialysisDate = first_dialysis_date.Unix()
  5099. }
  5100. }
  5101. }
  5102. }
  5103. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  5104. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  5105. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  5106. err_log := models.ExportErrLog{
  5107. LogType: 1,
  5108. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5109. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  5110. Status: 1,
  5111. CreateTime: time.Now().Unix(),
  5112. UpdateTime: time.Now().Unix(),
  5113. ExportTime: export_time,
  5114. }
  5115. service.CreateExportErrLog(&err_log)
  5116. continue
  5117. } else if source == 3 {
  5118. err_log := models.ExportErrLog{
  5119. LogType: 1,
  5120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5121. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  5122. Status: 1,
  5123. CreateTime: time.Now().Unix(),
  5124. UpdateTime: time.Now().Unix(),
  5125. ExportTime: export_time,
  5126. }
  5127. service.CreateExportErrLog(&err_log)
  5128. continue
  5129. } else {
  5130. patient.Source = source
  5131. }
  5132. }
  5133. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  5134. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  5135. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  5136. err_log := models.ExportErrLog{
  5137. LogType: 1,
  5138. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5139. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  5140. Status: 1,
  5141. CreateTime: time.Now().Unix(),
  5142. UpdateTime: time.Now().Unix(),
  5143. ExportTime: export_time,
  5144. }
  5145. service.CreateExportErrLog(&err_log)
  5146. continue
  5147. } else if lapseto == 3 {
  5148. err_log := models.ExportErrLog{
  5149. LogType: 1,
  5150. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5151. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  5152. Status: 1,
  5153. CreateTime: time.Now().Unix(),
  5154. UpdateTime: time.Now().Unix(),
  5155. ExportTime: export_time,
  5156. }
  5157. service.CreateExportErrLog(&err_log)
  5158. continue
  5159. } else {
  5160. patient.Lapseto = lapseto
  5161. }
  5162. }
  5163. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  5164. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  5165. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  5166. err_log := models.ExportErrLog{
  5167. LogType: 1,
  5168. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5169. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  5170. Status: 1,
  5171. CreateTime: time.Now().Unix(),
  5172. UpdateTime: time.Now().Unix(),
  5173. ExportTime: export_time,
  5174. }
  5175. service.CreateExportErrLog(&err_log)
  5176. continue
  5177. } else if is_infectious == 3 {
  5178. err_log := models.ExportErrLog{
  5179. LogType: 1,
  5180. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5181. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  5182. Status: 1,
  5183. CreateTime: time.Now().Unix(),
  5184. UpdateTime: time.Now().Unix(),
  5185. ExportTime: export_time,
  5186. }
  5187. service.CreateExportErrLog(&err_log)
  5188. continue
  5189. } else {
  5190. patient.IsInfectious = is_infectious
  5191. }
  5192. }
  5193. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  5194. var contagions []int64
  5195. thisContagions, _ := patientNameM["contagions"].([]interface{})
  5196. if len(thisContagions) > 0 {
  5197. for _, item := range thisContagions {
  5198. if reflect.TypeOf(item).String() != "float64" {
  5199. continue
  5200. }
  5201. contagion := int64(item.(float64))
  5202. if contagion > 0 {
  5203. contagions = append(contagions, contagion)
  5204. }
  5205. }
  5206. }
  5207. patient.ContagionIds = contagions
  5208. }
  5209. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  5210. diagnose, _ := patientNameM["diagnose"].(string)
  5211. patient.Diagnose = diagnose
  5212. }
  5213. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  5214. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  5215. var tempPatient *models.Patients
  5216. for _, item := range all_patient {
  5217. if item.DialysisNo == dialysis_no {
  5218. tempPatient = item
  5219. }
  5220. }
  5221. if tempPatient != nil && tempPatient.ID > 0 {
  5222. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  5223. } else {
  5224. patient.DialysisNo = dialysis_no
  5225. }
  5226. }
  5227. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  5228. height, _ := patientNameM["height"].(string)
  5229. heights, _ := strconv.ParseFloat(height, 64)
  5230. patient.Height = int64(heights)
  5231. }
  5232. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  5233. home_address, _ := patientNameM["home_address"].(string)
  5234. patient.HomeAddress = home_address
  5235. }
  5236. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5237. dry_weight, _ := patientNameM["dry_weight"].(string)
  5238. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5239. patient.DryWeight = dry_weights
  5240. }
  5241. patient.CreatedTime = time.Now().Unix()
  5242. patient.UpdatedTime = time.Now().Unix()
  5243. patient.Status = 1
  5244. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5245. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5246. patient.IsExcelExport = 1
  5247. patient.PatientType = 1
  5248. patients = append(patients, &patient)
  5249. }
  5250. }
  5251. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5252. if len(patients) > 0 {
  5253. for _, item := range patients {
  5254. hans := item.Name // 要转换的汉字字符串
  5255. // 创建一个拼音转换器
  5256. p := pinyin.NewArgs()
  5257. // 将汉字转为拼音
  5258. pinyinSlice := pinyin.Pinyin(hans, p)
  5259. // 输出拼音
  5260. fmt.Println("Pinyin:", pinyinSlice)
  5261. // 获取首字母
  5262. firstLetter := ""
  5263. for _, py := range pinyinSlice {
  5264. if len(py) > 0 {
  5265. firstLetter += string(py[0][0])
  5266. }
  5267. }
  5268. item.FirstLetter = firstLetter
  5269. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5270. }
  5271. log := models.ExportLog{
  5272. LogType: 1,
  5273. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5274. TotalNum: int64(len(total_patients)),
  5275. FailNum: int64(len(errLogs)),
  5276. SuccessNum: int64(len(patients)),
  5277. CreateTime: time.Now().Unix(),
  5278. UpdateTime: time.Now().Unix(),
  5279. ExportTime: export_time,
  5280. Status: 1,
  5281. }
  5282. service.CreateExportLog(&log)
  5283. c.ServeSuccessJSON(map[string]interface{}{
  5284. "msg": "导入成功",
  5285. "total_num": len(total_patients),
  5286. "success_num": len(patients),
  5287. "fail_num": int64(len(errLogs)),
  5288. })
  5289. } else {
  5290. log := models.ExportLog{
  5291. LogType: 1,
  5292. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5293. TotalNum: int64(len(total_patients)),
  5294. FailNum: int64(len(errLogs)),
  5295. SuccessNum: int64(len(patients)),
  5296. CreateTime: time.Now().Unix(),
  5297. UpdateTime: time.Now().Unix(),
  5298. ExportTime: export_time,
  5299. Status: 1,
  5300. }
  5301. service.CreateExportLog(&log)
  5302. c.ServeSuccessJSON(map[string]interface{}{
  5303. "msg": "导入成功",
  5304. "total_num": len(total_patients),
  5305. "success_num": len(patients),
  5306. "fail_num": int64(len(errLogs)),
  5307. })
  5308. }
  5309. }
  5310. func GetBirthDay(IDCardNo string) *time.Time {
  5311. dayStr := IDCardNo[6:14]
  5312. birthDay, err := time.Parse("20060102", dayStr)
  5313. if err != nil {
  5314. fmt.Println(err)
  5315. return nil
  5316. }
  5317. return &birthDay
  5318. }
  5319. func IsIdCard(id string) (res bool) {
  5320. id = strings.ToUpper(id)
  5321. if len(id) != 15 && len(id) != 18 {
  5322. fmt.Println("1111111")
  5323. return false
  5324. }
  5325. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5326. if !r.MatchString(id) {
  5327. fmt.Println("222222")
  5328. return false
  5329. }
  5330. if len(id) == 15 {
  5331. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5332. if tm2.Unix() == 0 {
  5333. fmt.Println("44444443333")
  5334. return false
  5335. }
  5336. return true
  5337. } else {
  5338. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5339. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5340. fmt.Println(tm2.Unix())
  5341. if tm2.Unix() == 0 {
  5342. fmt.Println("44445555555")
  5343. return false
  5344. }
  5345. //检验18位身份证的校验码是否正确。
  5346. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5347. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5348. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5349. sign := 0
  5350. for k, v := range arr_int {
  5351. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5352. sign += int_temp * v
  5353. }
  5354. n := sign % 11
  5355. val_num := arr_ch[n]
  5356. if val_num != string([]byte(id)[17:18]) {
  5357. fmt.Println("5556666666")
  5358. return false
  5359. }
  5360. return true
  5361. }
  5362. }
  5363. func (c *PatientApiController) SaveEditAdvices() {
  5364. adminInfo := c.GetAdminUserInfo()
  5365. orgid := adminInfo.CurrentOrgId
  5366. startTime := c.GetString("start_time")
  5367. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5368. groupno, _ := c.GetInt64("groupno")
  5369. fmt.Println("组", groupno)
  5370. date, _ := c.GetInt64("date")
  5371. fmt.Println("date", date)
  5372. patient_id, _ := c.GetInt64("patient_id")
  5373. fmt.Println("paitent_id", patient_id)
  5374. advice := models.XtDoctorAdvice{
  5375. StartTime: theTime.Unix(),
  5376. }
  5377. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5378. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5379. redis := service.RedisClient()
  5380. redis.Set(key, "", time.Second)
  5381. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5382. redis.Set(keyOne, "", time.Second)
  5383. scheduleTime := theTime.Format("2006-01-02")
  5384. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5385. fmt.Println("keyFour323223323232323232", keyFour)
  5386. redis.Set(keyFour, "", time.Second)
  5387. defer redis.Close()
  5388. if err != nil {
  5389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5390. return
  5391. }
  5392. c.ServeSuccessJSON(map[string]interface{}{
  5393. "advice": advice,
  5394. })
  5395. }
  5396. func (c *PatientApiController) GetMaxDialysisNo() {
  5397. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5398. c.ServeSuccessJSON(map[string]interface{}{
  5399. "dialysis_no": dialysisNo,
  5400. })
  5401. }
  5402. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5403. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5404. var tempPatient *models.Patients
  5405. for _, item := range patients {
  5406. if item.DialysisNo == dialysisNo2 {
  5407. tempPatient = item
  5408. }
  5409. }
  5410. if tempPatient == nil || tempPatient.ID == 0 {
  5411. return dialysisNo2
  5412. }
  5413. return GenerateDialysisNoTwo(patients)
  5414. }
  5415. func (c *PatientApiController) GetBanner() {
  5416. orgId := c.GetAdminUserInfo().CurrentOrgId
  5417. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5418. if errcodes == gorm.ErrRecordNotFound {
  5419. information, err := service.GetAdminUserRoleInformation(0)
  5420. if err != nil {
  5421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5422. return
  5423. }
  5424. c.ServeSuccessJSON(map[string]interface{}{
  5425. "information": information,
  5426. })
  5427. } else if errcodes == nil {
  5428. information, err := service.GetAdminUserRoleInformation(orgId)
  5429. if err != nil {
  5430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5431. return
  5432. }
  5433. c.ServeSuccessJSON(map[string]interface{}{
  5434. "information": information,
  5435. })
  5436. }
  5437. }
  5438. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5439. patient_id, _ := c.GetInt64("id", 0)
  5440. page, _ := c.GetInt64("page", 0)
  5441. limit, _ := c.GetInt64("limit", 0)
  5442. if patient_id <= 0 {
  5443. c.ServeSuccessJSON(map[string]interface{}{
  5444. "solutions": nil,
  5445. })
  5446. return
  5447. }
  5448. if page <= 0 {
  5449. page = 1
  5450. }
  5451. if limit <= 0 {
  5452. limit = 10
  5453. }
  5454. adminUserInfo := c.GetAdminUserInfo()
  5455. //获取该患者分组的透析模式
  5456. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5457. for _, item := range list {
  5458. //获取该模式最新的1条数据
  5459. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5460. //更新状态值
  5461. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5462. }
  5463. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5464. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5465. if err != nil {
  5466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5467. return
  5468. }
  5469. c.ServeSuccessJSON(map[string]interface{}{
  5470. "solutions": solution,
  5471. "total": total,
  5472. "stockType": stockType,
  5473. })
  5474. }
  5475. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5476. patient_id, _ := c.GetInt64("patient_id")
  5477. mode_id, _ := c.GetInt64("mode_id")
  5478. page, _ := c.GetInt64("page")
  5479. limit, _ := c.GetInt64("limit")
  5480. orgId := c.GetAdminUserInfo().CurrentOrgId
  5481. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5482. if err != nil {
  5483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5484. return
  5485. }
  5486. c.ServeSuccessJSON(map[string]interface{}{
  5487. "list": list,
  5488. "total": total,
  5489. })
  5490. }
  5491. func (c *PatientApiController) SaveFallOutBedPrint() {
  5492. adminInfo := c.GetAdminUserInfo()
  5493. orgid := adminInfo.CurrentOrgId
  5494. dataBody := make(map[string]interface{}, 0)
  5495. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5496. fmt.Println("err", err)
  5497. content := dataBody["content"].(string)
  5498. outPrint := models.XtFallOutPrint{
  5499. UserOrgId: orgid,
  5500. Content: content,
  5501. Status: 1,
  5502. Ctime: time.Now().Unix(),
  5503. Mtime: time.Now().Unix(),
  5504. }
  5505. //查询该机构是否存在
  5506. list, err := service.GetOutPrintList(orgid)
  5507. if list.ID == 0 {
  5508. service.CreateFallOutBedPrint(outPrint)
  5509. }
  5510. if list.ID > 0 {
  5511. service.UpdateFallOutBedPrint(list.ID, content)
  5512. }
  5513. c.ServeSuccessJSON(map[string]interface{}{
  5514. "list": list,
  5515. })
  5516. }
  5517. func (c *PatientApiController) GetFallOutBedPrintList() {
  5518. adminInfo := c.GetAdminUserInfo()
  5519. orgid := adminInfo.CurrentOrgId
  5520. list, _ := service.GetFallOutBedPrintList(orgid)
  5521. c.ServeSuccessJSON(map[string]interface{}{
  5522. "list": list,
  5523. })
  5524. }
  5525. func (c *PatientApiController) SaveFilterInformed() {
  5526. adminInfo := c.GetAdminUserInfo()
  5527. orgid := adminInfo.CurrentOrgId
  5528. dataBody := make(map[string]interface{}, 0)
  5529. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5530. fmt.Println("err", err)
  5531. content := dataBody["content"].(string)
  5532. informed := models.XtFilterInformed{
  5533. UserOrgId: orgid,
  5534. Content: content,
  5535. Status: 1,
  5536. Ctime: time.Now().Unix(),
  5537. Mtime: time.Now().Unix(),
  5538. }
  5539. filterInformed, _ := service.GetFilterInformed(orgid)
  5540. if filterInformed.ID == 0 {
  5541. service.CreateFilterInformed(informed)
  5542. }
  5543. if filterInformed.ID > 0 {
  5544. service.UpdateFilterInformed(filterInformed.ID, content)
  5545. }
  5546. c.ServeSuccessJSON(map[string]interface{}{
  5547. "informed": informed,
  5548. })
  5549. }
  5550. func (c *PatientApiController) GetFilterInformed() {
  5551. adminInfo := c.GetAdminUserInfo()
  5552. orgid := adminInfo.CurrentOrgId
  5553. filterInformed, _ := service.GetFilterInformed(orgid)
  5554. c.ServeSuccessJSON(map[string]interface{}{
  5555. "list": filterInformed,
  5556. })
  5557. }
  5558. func (c *PatientApiController) SaveProfundaInformed() {
  5559. adminInfo := c.GetAdminUserInfo()
  5560. orgid := adminInfo.CurrentOrgId
  5561. dataBody := make(map[string]interface{}, 0)
  5562. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5563. fmt.Println("err", err)
  5564. content := dataBody["content"].(string)
  5565. informed := models.XtProfundaInformed{
  5566. UserOrgId: orgid,
  5567. Content: content,
  5568. Status: 1,
  5569. Ctime: time.Now().Unix(),
  5570. Mtime: time.Now().Unix(),
  5571. }
  5572. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5573. if profundaInformed.ID == 0 {
  5574. service.CreateProfundaInformed(informed)
  5575. }
  5576. if profundaInformed.ID > 0 {
  5577. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5578. }
  5579. c.ServeSuccessJSON(map[string]interface{}{
  5580. "list": profundaInformed,
  5581. })
  5582. }
  5583. func (c *PatientApiController) GetProfundaInformed() {
  5584. adminInfo := c.GetAdminUserInfo()
  5585. orgid := adminInfo.CurrentOrgId
  5586. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5587. c.ServeSuccessJSON(map[string]interface{}{
  5588. "list": profundaInformed,
  5589. })
  5590. }
  5591. func (c *PatientApiController) SaveArterOvenous() {
  5592. adminInfo := c.GetAdminUserInfo()
  5593. orgid := adminInfo.CurrentOrgId
  5594. dataBody := make(map[string]interface{}, 0)
  5595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5596. fmt.Println("err", err)
  5597. content := dataBody["content"].(string)
  5598. arterOvenous := models.XtArterOvenous{
  5599. UserOrgId: orgid,
  5600. Content: content,
  5601. Status: 1,
  5602. Ctime: time.Now().Unix(),
  5603. Mtime: time.Now().Unix(),
  5604. }
  5605. list, _ := service.GetArterOvenousList(orgid)
  5606. if list.ID == 0 {
  5607. service.CreateArterOvernous(arterOvenous)
  5608. }
  5609. if list.ID > 0 {
  5610. service.UpdateArterOvernous(list.ID, content)
  5611. }
  5612. c.ServeSuccessJSON(map[string]interface{}{
  5613. "list": list,
  5614. })
  5615. }
  5616. func (c *PatientApiController) GetArterOverNous() {
  5617. adminInfo := c.GetAdminUserInfo()
  5618. orgid := adminInfo.CurrentOrgId
  5619. list, _ := service.GetArterOvenousList(orgid)
  5620. c.ServeSuccessJSON(map[string]interface{}{
  5621. "list": list,
  5622. })
  5623. }
  5624. func (c *PatientApiController) SaveHighRikInformed() {
  5625. adminInfo := c.GetAdminUserInfo()
  5626. orgid := adminInfo.CurrentOrgId
  5627. dataBody := make(map[string]interface{}, 0)
  5628. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5629. fmt.Println("err", err)
  5630. content := dataBody["content"].(string)
  5631. risk := models.XtHightRisk{
  5632. UserOrgId: orgid,
  5633. Content: content,
  5634. Status: 1,
  5635. Ctime: time.Now().Unix(),
  5636. Mtime: time.Now().Unix(),
  5637. }
  5638. highRik, _ := service.GetHightRikInformed(orgid)
  5639. if highRik.ID == 0 {
  5640. service.CreateHighRik(risk)
  5641. }
  5642. if highRik.ID > 0 {
  5643. service.UpdateHighRik(highRik.ID, content)
  5644. }
  5645. c.ServeSuccessJSON(map[string]interface{}{
  5646. "list": risk,
  5647. })
  5648. }
  5649. func (c *PatientApiController) GetHighRiskInformed() {
  5650. orgId := c.GetAdminUserInfo().CurrentOrgId
  5651. rikInformed, _ := service.GetHightRikInformed(orgId)
  5652. c.ServeSuccessJSON(map[string]interface{}{
  5653. "list": rikInformed,
  5654. })
  5655. }
  5656. func (c *PatientApiController) SaveAnticoagulation() {
  5657. orgId := c.GetAdminUserInfo().CurrentOrgId
  5658. dataBody := make(map[string]interface{}, 0)
  5659. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5660. fmt.Println("err", err)
  5661. content := dataBody["content"].(string)
  5662. auticoagutionPrint := models.XtAuticoagutionPrint{
  5663. Content: content,
  5664. UserOrgId: orgId,
  5665. Status: 1,
  5666. Ctime: time.Now().Unix(),
  5667. Mtime: time.Now().Unix(),
  5668. }
  5669. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5670. if anticoagulation.ID == 0 {
  5671. service.CreateAnticoagulation(auticoagutionPrint)
  5672. }
  5673. if anticoagulation.ID > 0 {
  5674. service.UpdateAnticoagulation(anticoagulation.ID, content)
  5675. }
  5676. c.ServeSuccessJSON(map[string]interface{}{
  5677. "list": auticoagutionPrint,
  5678. })
  5679. }
  5680. func (c *PatientApiController) GetAnticoagulationInformed() {
  5681. orgId := c.GetAdminUserInfo().CurrentOrgId
  5682. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5683. c.ServeSuccessJSON(map[string]interface{}{
  5684. "list": anticoagulation,
  5685. })
  5686. }
  5687. func (c *PatientApiController) SaveCriticalInfomed() {
  5688. orgId := c.GetAdminUserInfo().CurrentOrgId
  5689. dataBody := make(map[string]interface{}, 0)
  5690. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5691. fmt.Println("err", err)
  5692. content := dataBody["content"].(string)
  5693. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  5694. UserOrgId: orgId,
  5695. Content: content,
  5696. Status: 1,
  5697. Ctime: time.Now().Unix(),
  5698. Mtime: time.Now().Unix(),
  5699. }
  5700. infomed, _ := service.GetCriticalInfomed(orgId)
  5701. if infomed.ID == 0 {
  5702. service.CreatedCriticalInfomed(criticalinfomedPrint)
  5703. }
  5704. if infomed.ID > 0 {
  5705. service.UpdateCriticalInfomed(infomed.ID, content)
  5706. }
  5707. c.ServeSuccessJSON(map[string]interface{}{
  5708. "list": criticalinfomedPrint,
  5709. })
  5710. }
  5711. func (c *PatientApiController) GetCriticalInformed() {
  5712. orgId := c.GetAdminUserInfo().CurrentOrgId
  5713. infomed, _ := service.GetCriticalInfomed(orgId)
  5714. c.ServeSuccessJSON(map[string]interface{}{
  5715. "list": infomed,
  5716. })
  5717. }
  5718. func (c *PatientApiController) SaveHemoperfusionInformed() {
  5719. orgId := c.GetAdminUserInfo().CurrentOrgId
  5720. dataBody := make(map[string]interface{}, 0)
  5721. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5722. fmt.Println("err", err)
  5723. content := dataBody["content"].(string)
  5724. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  5725. UserOrgId: orgId,
  5726. Content: content,
  5727. Status: 1,
  5728. Ctime: time.Now().Unix(),
  5729. Mtime: time.Now().Unix(),
  5730. }
  5731. informed, _ := service.GetHemoperfusionInformed(orgId)
  5732. if informed.ID == 0 {
  5733. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  5734. }
  5735. if informed.ID > 0 {
  5736. service.UpdateHemoperfusionInformed(informed.ID, content)
  5737. }
  5738. c.ServeSuccessJSON(map[string]interface{}{
  5739. "list": hemoperfusionmedPrint,
  5740. })
  5741. }
  5742. func (c *PatientApiController) GetHemoperfusionInformed() {
  5743. orgId := c.GetAdminUserInfo().CurrentOrgId
  5744. informed, _ := service.GetHemoperfusionInformed(orgId)
  5745. c.ServeSuccessJSON(map[string]interface{}{
  5746. "list": informed,
  5747. })
  5748. }
  5749. func (c *PatientApiController) SaveBringInformed() {
  5750. orgId := c.GetAdminUserInfo().CurrentOrgId
  5751. dataBody := make(map[string]interface{}, 0)
  5752. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5753. fmt.Println("err", err)
  5754. content := dataBody["content"].(string)
  5755. bringinformedPrint := models.XtBringinformedPrint{
  5756. Content: content,
  5757. UserOrgId: orgId,
  5758. Ctime: time.Now().Unix(),
  5759. Mtime: time.Now().Unix(),
  5760. Status: 1,
  5761. }
  5762. informed, _ := service.GetBringInformed(orgId)
  5763. if informed.ID == 0 {
  5764. service.CreateBringInformed(bringinformedPrint)
  5765. }
  5766. if informed.ID > 0 {
  5767. service.UpdateBringInformed(informed.ID, content)
  5768. }
  5769. c.ServeSuccessJSON(map[string]interface{}{
  5770. "list": bringinformedPrint,
  5771. })
  5772. }
  5773. func (c *PatientApiController) GetInformedContsent() {
  5774. orgId := c.GetAdminUserInfo().CurrentOrgId
  5775. informed, _ := service.GetBringInformed(orgId)
  5776. c.ServeSuccessJSON(map[string]interface{}{
  5777. "list": informed,
  5778. })
  5779. }
  5780. func (c *PatientApiController) SaveCatheterization() {
  5781. orgId := c.GetAdminUserInfo().CurrentOrgId
  5782. dataBody := make(map[string]interface{}, 0)
  5783. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5784. fmt.Println("err", err)
  5785. content := dataBody["content"].(string)
  5786. cathetercationPrint := models.XtCathetercationPrint{
  5787. UserOrgId: orgId,
  5788. Content: content,
  5789. Status: 1,
  5790. Ctime: time.Now().Unix(),
  5791. Mtime: time.Now().Unix(),
  5792. }
  5793. catheterization, _ := service.GetCatheterization(orgId)
  5794. if cathetercationPrint.ID == 0 {
  5795. service.CreateCatheteriztion(cathetercationPrint)
  5796. }
  5797. if cathetercationPrint.ID > 0 {
  5798. service.UpdateCatheterization(catheterization.ID, content)
  5799. }
  5800. c.ServeSuccessJSON(map[string]interface{}{
  5801. "list": catheterization,
  5802. })
  5803. }
  5804. func (c *PatientApiController) GetCatheterization() {
  5805. orgId := c.GetAdminUserInfo().CurrentOrgId
  5806. catheterization, _ := service.GetCatheterization(orgId)
  5807. c.ServeSuccessJSON(map[string]interface{}{
  5808. "list": catheterization,
  5809. })
  5810. }
  5811. func (c *PatientApiController) SaveDialyzerInformed() {
  5812. orgId := c.GetAdminUserInfo().CurrentOrgId
  5813. dataBody := make(map[string]interface{}, 0)
  5814. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5815. fmt.Println("err", err)
  5816. content := dataBody["content"].(string)
  5817. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  5818. UserOrgId: orgId,
  5819. Content: content,
  5820. Status: 1,
  5821. Ctime: time.Now().Unix(),
  5822. Mtime: time.Now().Unix(),
  5823. }
  5824. informed, _ := service.GetDialyzerInformed(orgId)
  5825. if informed.ID == 0 {
  5826. service.CreateDialyzerInformed(dialyszerinformedPrint)
  5827. }
  5828. if informed.ID > 0 {
  5829. service.UpdateDialyszerInformed(informed.ID, content)
  5830. }
  5831. c.ServeSuccessJSON(map[string]interface{}{
  5832. "list": dialyszerinformedPrint,
  5833. })
  5834. }
  5835. func (c *PatientApiController) GetDialyzerInformed() {
  5836. orgId := c.GetAdminUserInfo().CurrentOrgId
  5837. informed, _ := service.GetDialyzerInformed(orgId)
  5838. c.ServeSuccessJSON(map[string]interface{}{
  5839. "list": informed,
  5840. })
  5841. }
  5842. func (c *PatientApiController) SaveTheapyInformed() {
  5843. orgId := c.GetAdminUserInfo().CurrentOrgId
  5844. dataBody := make(map[string]interface{}, 0)
  5845. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5846. fmt.Println("err", err)
  5847. content := dataBody["content"].(string)
  5848. theapyinformedPrint := models.XtTheapyinformedPrint{
  5849. Content: content,
  5850. UserOrgId: orgId,
  5851. Status: 1,
  5852. Ctime: time.Now().Unix(),
  5853. Mtime: time.Now().Unix(),
  5854. }
  5855. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5856. if theapyInformed.ID == 0 {
  5857. service.CreateTheapyInformed(theapyinformedPrint)
  5858. }
  5859. if theapyInformed.ID > 0 {
  5860. service.UpdateTheaphInformed(theapyInformed.ID, content)
  5861. }
  5862. c.ServeSuccessJSON(map[string]interface{}{
  5863. "list": theapyinformedPrint,
  5864. })
  5865. }
  5866. func (c *PatientApiController) GetTherapyInformed() {
  5867. orgId := c.GetAdminUserInfo().CurrentOrgId
  5868. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5869. c.ServeSuccessJSON(map[string]interface{}{
  5870. "list": theapyInformed,
  5871. })
  5872. }
  5873. func (c *PatientApiController) SaveMedicalHistory() {
  5874. orgId := c.GetAdminUserInfo().CurrentOrgId
  5875. dataBody := make(map[string]interface{}, 0)
  5876. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5877. fmt.Println("err", err)
  5878. content := dataBody["content"].(string)
  5879. patient_id := int64(dataBody["patient_id"].(float64))
  5880. medicalHistory := models.XtMedicalHistory{
  5881. UserOrgId: orgId,
  5882. PatientId: patient_id,
  5883. Ctime: time.Now().Unix(),
  5884. Mtime: 0,
  5885. Status: 1,
  5886. Content: content,
  5887. }
  5888. //
  5889. history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
  5890. if history.ID > 0 {
  5891. service.UpdatePatientMedicalHistory(history.ID, content)
  5892. }
  5893. if history.ID == 0 {
  5894. service.CreatePatientMedicalHistory(medicalHistory)
  5895. }
  5896. c.ServeSuccessJSON(map[string]interface{}{
  5897. "medicalHistory": medicalHistory,
  5898. })
  5899. }
  5900. func (c *PatientApiController) SavePatientCritaicalInformed() {
  5901. orgId := c.GetAdminUserInfo().CurrentOrgId
  5902. dataBody := make(map[string]interface{}, 0)
  5903. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5904. fmt.Println("err", err)
  5905. content := dataBody["content"].(string)
  5906. patientCritical := models.XtPatientCritical{
  5907. UserOrgId: orgId,
  5908. Content: content,
  5909. Status: 1,
  5910. Ctime: time.Now().Unix(),
  5911. Mtime: time.Now().Unix(),
  5912. }
  5913. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  5914. if patientCritaicalInformed.ID == 0 {
  5915. service.CreatePatientCritaicalinformed(patientCritical)
  5916. }
  5917. if patientCritaicalInformed.ID > 0 {
  5918. service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
  5919. }
  5920. c.ServeSuccessJSON(map[string]interface{}{
  5921. "patientCritical": patientCritical,
  5922. })
  5923. }
  5924. func (c *PatientApiController) GetPatientCriticalList() {
  5925. orgId := c.GetAdminUserInfo().CurrentOrgId
  5926. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  5927. c.ServeSuccessJSON(map[string]interface{}{
  5928. "patientCritaicalInformed": patientCritaicalInformed,
  5929. })
  5930. }
  5931. func (c *PatientApiController) SavePatientCriticalInformedOne() {
  5932. orgId := c.GetAdminUserInfo().CurrentOrgId
  5933. dataBody := make(map[string]interface{}, 0)
  5934. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5935. fmt.Println("err", err)
  5936. content := dataBody["content"].(string)
  5937. criticalOne := models.XtPatientCriticalOne{
  5938. UserOrgId: orgId,
  5939. Content: content,
  5940. Status: 1,
  5941. Ctime: time.Now().Unix(),
  5942. Mtime: time.Now().Unix(),
  5943. }
  5944. critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
  5945. if critical.ID == 0 {
  5946. service.CreatePatientCritical(criticalOne)
  5947. }
  5948. if critical.ID > 0 {
  5949. service.UpdatePatientCriticalOne(orgId, content)
  5950. }
  5951. c.ServeSuccessJSON(map[string]interface{}{
  5952. "criticalOne": criticalOne,
  5953. })
  5954. }
  5955. func (c *PatientApiController) GetPatientCriticalOneList() {
  5956. orgId := c.GetAdminUserInfo().CurrentOrgId
  5957. list, _ := service.GetPatientCriticalOneList(orgId)
  5958. c.ServeSuccessJSON(map[string]interface{}{
  5959. "list": list,
  5960. })
  5961. }
  5962. func (c *PatientApiController) DeleteSolution() {
  5963. id, _ := c.GetInt64("id")
  5964. solution, _ := service.DeleteSolutionById(id)
  5965. c.ServeSuccessJSON(map[string]interface{}{
  5966. "solution": solution,
  5967. })
  5968. }
  5969. func (c *PatientApiController) SaveTreatmentPlan() {
  5970. orgId := c.GetAdminUserInfo().CurrentOrgId
  5971. dataBody := make(map[string]interface{}, 0)
  5972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5973. fmt.Println("err", err)
  5974. content := dataBody["content"].(string)
  5975. theapyinformedPrint := models.XtTreatmentPlan{
  5976. Content: content,
  5977. UserOrgId: orgId,
  5978. Status: 1,
  5979. Ctime: time.Now().Unix(),
  5980. Mtime: time.Now().Unix(),
  5981. }
  5982. treamentPlan, _ := service.GetTreamentPland(orgId)
  5983. if treamentPlan.ID == 0 {
  5984. service.CreateTreatqmentPland(theapyinformedPrint)
  5985. }
  5986. if treamentPlan.ID > 0 {
  5987. service.UpdateTheatmentPland(treamentPlan.ID, content)
  5988. }
  5989. c.ServeSuccessJSON(map[string]interface{}{
  5990. "list": theapyinformedPrint,
  5991. })
  5992. }
  5993. func (c *PatientApiController) GetTreatMentPlanList() {
  5994. orgId := c.GetAdminUserInfo().CurrentOrgId
  5995. treamentPlan, _ := service.GetTreamentPland(orgId)
  5996. c.ServeSuccessJSON(map[string]interface{}{
  5997. "treamentPlan": treamentPlan,
  5998. })
  5999. }