patient_api_controller.go 252KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509
  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. //针对康桥
  1485. if adminUserInfo.CurrentOrgId == 10702 {
  1486. if adviceType == 3 {
  1487. adviceType = 2
  1488. }
  1489. }
  1490. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1491. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1492. advice.ExecutionFrequency = executionFrequency
  1493. }
  1494. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1495. children := adviceNameM["children"].([]interface{})
  1496. if len(children) > 0 {
  1497. for _, childrenMap := range children {
  1498. childMap := childrenMap.(map[string]interface{})
  1499. var child models.GroupAdvice
  1500. child.Remark = Remark
  1501. child.AdviceType = adviceType
  1502. child.StartTime = StartTime
  1503. child.AdviceDate = AdviceDate
  1504. child.RecordDate = RecordDate
  1505. child.Status = 1
  1506. child.CreatedTime = time.Now().Unix()
  1507. child.UpdatedTime = time.Now().Unix()
  1508. child.StopState = 2
  1509. child.ExecutionState = 2
  1510. child.UserOrgId = adminUserInfo.CurrentOrgId
  1511. child.PatientId = patientInfo.ID
  1512. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1513. child.IsSettle = 2
  1514. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1515. utils.ErrorLog("child advice_name")
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1517. return
  1518. }
  1519. childAdviceName, _ := childMap["advice_name"].(string)
  1520. if len(childAdviceName) == 0 {
  1521. utils.ErrorLog("len(child advice_name) == 0")
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. child.AdviceName = childAdviceName
  1526. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1527. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1528. child.AdviceDesc = childAdviceDesc
  1529. }
  1530. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1531. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1532. child.DrugSpec = childDrugSpec
  1533. }
  1534. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1535. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1536. child.DrugSpecUnit = childDrugSpecUnit
  1537. }
  1538. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1539. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1540. child.SingleDose = childSingleDose
  1541. }
  1542. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1543. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1544. child.SingleDoseUnit = childSingleDoseUnit
  1545. }
  1546. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1547. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1548. child.PrescribingNumber = childPrescribingNumber
  1549. }
  1550. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1551. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1552. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1553. }
  1554. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1555. drug_id := int64(childMap["drug_id"].(float64))
  1556. child.DrugId = drug_id
  1557. }
  1558. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1559. way := int64(childMap["way"].(float64))
  1560. child.Way = way
  1561. }
  1562. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1563. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1564. child.DrugNameId = drug_name_id
  1565. }
  1566. child.DeliveryWay = advice.DeliveryWay
  1567. child.ExecutionFrequency = advice.ExecutionFrequency
  1568. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1569. if child.PrescribingNumber == 0 {
  1570. child.PrescribingNumber = 1
  1571. }
  1572. //查询该患者今日有没有双人核对
  1573. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1574. if check.ID > 0 {
  1575. child.Checker = check.Modifier
  1576. child.CheckState = 1
  1577. child.CheckTime = time.Now().Unix()
  1578. }
  1579. }
  1580. advice.Children = append(advice.Children, &child)
  1581. }
  1582. }
  1583. }
  1584. advices = append(advices, &advice)
  1585. }
  1586. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1587. for _, item := range advices {
  1588. //记录日志
  1589. byterequest, _ := json.Marshal(item)
  1590. adviceLog := models.XtDoctorAdviceLog{
  1591. UserOrgId: item.UserOrgId,
  1592. PatientId: item.PatientId,
  1593. AdminUserId: adminUserInfo.AdminUser.Id,
  1594. Module: 1,
  1595. ErrLog: string(byterequest),
  1596. Status: 1,
  1597. Ctime: time.Now().Unix(),
  1598. Mtime: 0,
  1599. Source: "电导端批量插入医嘱",
  1600. RecordDate: item.AdviceDate,
  1601. }
  1602. service.CreateDoctorAdviceLog(adviceLog)
  1603. }
  1604. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1605. redis := service.RedisClient()
  1606. defer redis.Close()
  1607. redis.Set(key, "", time.Second)
  1608. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1609. redis.Set(keyOne, "", time.Second)
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1612. return
  1613. }
  1614. c.ServeSuccessJSON(map[string]interface{}{
  1615. "msg": "ok",
  1616. "advices": list,
  1617. })
  1618. return
  1619. }
  1620. func (c *PatientApiController) CreateDoctorAdvice() {
  1621. patient, _ := c.GetInt64("id", 0)
  1622. if patient <= 0 {
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. adminUserInfo := c.GetAdminUserInfo()
  1627. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1628. if patientInfo.ID == 0 {
  1629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1630. return
  1631. }
  1632. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1633. if appRole.UserType == 3 {
  1634. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1635. if getPermissionErr != nil {
  1636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1637. return
  1638. } else if headNursePermission == nil {
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1640. return
  1641. }
  1642. }
  1643. var advice models.DoctorAdvice
  1644. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1645. if code > 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(code)
  1647. return
  1648. }
  1649. if advice.ParentId > 0 {
  1650. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1651. if old.ID == 0 || old.PatientId != patient {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1653. return
  1654. }
  1655. if old.StopState == 1 || old.ExecutionState == 1 {
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1657. return
  1658. }
  1659. if old.ParentId > 0 {
  1660. advice.ParentId = old.ParentId
  1661. }
  1662. advice.StartTime = old.StartTime
  1663. advice.AdviceDoctor = old.AdviceDoctor
  1664. advice.DeliveryWay = old.DeliveryWay
  1665. advice.ExecutionFrequency = old.ExecutionFrequency
  1666. advice.GroupNo = old.GroupNo
  1667. }
  1668. advice.Status = 1
  1669. advice.CreatedTime = time.Now().Unix()
  1670. advice.UpdatedTime = time.Now().Unix()
  1671. advice.StopState = 2
  1672. advice.ExecutionState = 2
  1673. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1674. advice.PatientId = patient
  1675. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1676. // 查询信息规挡的设置天数
  1677. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1678. if infor.ID > 0 && infor.WeekDay > 0 {
  1679. var cha_time int64
  1680. timeNowStr := time.Now().Format("2006-01-02")
  1681. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1682. //今日的日期减去设置的日期
  1683. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1684. if cha_time >= advice.AdviceDate {
  1685. //查询审核是否允许
  1686. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1687. //申请状态不允许的情况 拒绝修改
  1688. if infor.ApplicationStatus != 1 {
  1689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1690. return
  1691. }
  1692. }
  1693. }
  1694. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1695. if advice.PrescribingNumber == 0 {
  1696. advice.PrescribingNumber = 1
  1697. }
  1698. //查询该患者今日有没有双人核对
  1699. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1700. if check.ID > 0 {
  1701. advice.Checker = check.Modifier
  1702. advice.CheckState = 1
  1703. advice.CheckTime = time.Now().Unix()
  1704. }
  1705. }
  1706. err := service.CreateDoctorAdvice(&advice)
  1707. //记录日志
  1708. byterequest, _ := json.Marshal(advice)
  1709. adviceLog := models.XtDoctorAdviceLog{
  1710. UserOrgId: advice.UserOrgId,
  1711. PatientId: advice.PatientId,
  1712. AdminUserId: adminUserInfo.AdminUser.Id,
  1713. Module: 1,
  1714. ErrLog: string(byterequest),
  1715. Status: 1,
  1716. Ctime: time.Now().Unix(),
  1717. Mtime: 0,
  1718. Source: "电脑新增医嘱",
  1719. RecordDate: advice.RecordDate,
  1720. }
  1721. service.CreateDoctorAdviceLog(adviceLog)
  1722. //创建步骤表
  1723. finish := models.XtDialysisFinish{
  1724. IsFinish: 1,
  1725. UserOrgId: adminUserInfo.CurrentOrgId,
  1726. Status: 1,
  1727. Ctime: time.Now().Unix(),
  1728. Mtime: 0,
  1729. Module: 4,
  1730. RecordDate: advice.AdviceDate,
  1731. Sourse: 1,
  1732. PatientId: patient,
  1733. }
  1734. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1735. if dialysisFinish.ID == 0 {
  1736. service.CreateDialysisFinish(finish)
  1737. }
  1738. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1739. redis := service.RedisClient()
  1740. defer redis.Close()
  1741. redis.Set(key, "", time.Second)
  1742. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1743. redis.Set(keyOne, "", time.Second)
  1744. if err != nil {
  1745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1746. return
  1747. }
  1748. c.ServeSuccessJSON(map[string]interface{}{
  1749. "msg": "ok",
  1750. "advice": advice,
  1751. })
  1752. return
  1753. }
  1754. func (c *PatientApiController) ExecGroupAdvice() {
  1755. groupNo, _ := c.GetInt64("groupno", 0)
  1756. executionTime := c.GetString("execution_time")
  1757. if groupNo <= 0 {
  1758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1759. return
  1760. }
  1761. if len(executionTime) <= 0 {
  1762. utils.ErrorLog("execution_time")
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. adminUserInfo := c.GetAdminUserInfo()
  1767. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1768. if advice.ID == 0 {
  1769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1770. return
  1771. }
  1772. if advice.ExecutionState == 1 {
  1773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1774. return
  1775. }
  1776. executionStaff := adminUserInfo.AdminUser.Id
  1777. // checker := adminUserInfo.AdminUser.Id
  1778. timeLayout := "2006-01-02 15:04:05"
  1779. loc, _ := time.LoadLocation("Local")
  1780. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1781. if err != nil {
  1782. utils.ErrorLog(err.Error())
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. if advice.StartTime > theTime.Unix() {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1788. return
  1789. }
  1790. exceAdvice := models.DoctorAdvice{
  1791. ExecutionStaff: executionStaff,
  1792. ExecutionTime: theTime.Unix(),
  1793. UpdatedTime: time.Now().Unix(),
  1794. }
  1795. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1796. if err != nil {
  1797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1798. return
  1799. }
  1800. //查询自动扣减是否开启
  1801. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1802. //查询已经执行的医嘱
  1803. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1804. if drugStockConfig.IsOpen == 1 {
  1805. for _, item := range advicelist {
  1806. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1807. //查询这个患者这个患者这个药已经出库的所有数量
  1808. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1809. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1810. var total_count int64
  1811. var drug_count int64
  1812. for _, it := range advicelist {
  1813. if it.PrescribingNumberUnit == medical.MaxUnit {
  1814. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1815. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1816. total_count += prenumber * medical.MinNumber
  1817. }
  1818. if it.PrescribingNumberUnit == medical.MinUnit {
  1819. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1820. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1821. total_count += prenumber
  1822. }
  1823. }
  1824. for _, its := range drugoutlist {
  1825. if its.CountUnit == medical.MaxUnit {
  1826. drug_count += its.Count * medical.MinNumber
  1827. }
  1828. if its.CountUnit == medical.MinUnit {
  1829. drug_count += its.Count
  1830. }
  1831. }
  1832. if total_count == drug_count {
  1833. c.ServeSuccessJSON(map[string]interface{}{
  1834. "msg": "1",
  1835. "advice": advice,
  1836. })
  1837. return
  1838. }
  1839. var total int64
  1840. var prescribing_number_total int64
  1841. //查询默认出库仓库
  1842. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1843. //查询该药品在默认仓库是否有库存
  1844. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1845. //判断单位是否相等
  1846. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1847. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1848. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1849. //转化为最小单位
  1850. total = list.Count*medical.MinNumber + list.StockMinNumber
  1851. prescribing_number_total = count * medical.MinNumber
  1852. }
  1853. if medical.MinUnit == advice.PrescribingNumberUnit {
  1854. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1855. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1856. total = list.Count*medical.MinNumber + list.StockMinNumber
  1857. prescribing_number_total = count
  1858. }
  1859. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1860. c.ServeSuccessJSON(map[string]interface{}{
  1861. "msg": "3",
  1862. "advice": advice,
  1863. })
  1864. return
  1865. }
  1866. if prescribing_number_total > total {
  1867. c.ServeSuccessJSON(map[string]interface{}{
  1868. "msg": "2",
  1869. "advice": advice,
  1870. })
  1871. return
  1872. }
  1873. if prescribing_number_total <= total {
  1874. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1875. if medical.IsUse == 2 {
  1876. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  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. if pharmacyConfig.IsOpen != 1 {
  1883. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1884. if drugOutInfo.ID == 0 {
  1885. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1886. }
  1887. }
  1888. //查询默认仓库
  1889. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1890. //查询默认仓库剩余多少库存
  1891. var sum_count int64
  1892. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1893. for _, its := range stockInfo {
  1894. if its.MaxUnit == medical.MaxUnit {
  1895. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1896. }
  1897. sum_count += its.StockMaxNumber + its.StockMinNumber
  1898. }
  1899. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1900. break
  1901. c.ServeSuccessJSON(map[string]interface{}{
  1902. "msg": "1",
  1903. "advice": advice,
  1904. })
  1905. return
  1906. }
  1907. if medical.IsUse == 1 {
  1908. c.ServeSuccessJSON(map[string]interface{}{
  1909. "msg": "1",
  1910. "advice": advice,
  1911. })
  1912. return
  1913. }
  1914. }
  1915. }
  1916. }
  1917. advice.ExecutionStaff = executionStaff
  1918. advice.ExecutionTime = theTime.Unix()
  1919. c.ServeSuccessJSON(map[string]interface{}{
  1920. "msg": "ok",
  1921. "advice": advice,
  1922. })
  1923. return
  1924. }
  1925. func (c *PatientApiController) ExecDoctorAdvice() {
  1926. origin, _ := c.GetInt64("origin", 0)
  1927. patient, _ := c.GetInt64("patient", 0)
  1928. id, _ := c.GetInt64("id", 0)
  1929. executionTime := c.GetString("execution_time")
  1930. if origin != 2 {
  1931. if id <= 0 || patient <= 0 {
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1933. return
  1934. }
  1935. if len(executionTime) <= 0 {
  1936. utils.ErrorLog("execution_time")
  1937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1938. return
  1939. }
  1940. adminUserInfo := c.GetAdminUserInfo()
  1941. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1942. //自备药
  1943. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  1944. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  1945. //查询库存是否
  1946. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  1947. if selfBasedrug.IsSelfDrug == 1 {
  1948. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  1949. var prescribing_number_total_one int64
  1950. //判断单位是否相等
  1951. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1952. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1953. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1954. //转化为最小单位
  1955. prescribing_number_total_one = count * selfBasedrug.MinNumber
  1956. }
  1957. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1958. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1959. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1960. prescribing_number_total_one = count
  1961. }
  1962. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  1963. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1964. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1965. prescribing_number_total_one = count
  1966. }
  1967. //库存不足
  1968. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  1969. c.ServeSuccessJSON(map[string]interface{}{
  1970. "msg": "2",
  1971. "advice": advice,
  1972. })
  1973. return
  1974. }
  1975. }
  1976. }
  1977. if advice.ID == 0 || advice.PatientId != patient {
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1979. return
  1980. }
  1981. //医嘱已执行
  1982. if advice.ExecutionState == 1 {
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1984. return
  1985. }
  1986. executionStaff := adminUserInfo.AdminUser.Id
  1987. timeLayout := "2006-01-02 15:04:05"
  1988. loc, _ := time.LoadLocation("Local")
  1989. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1990. if err != nil {
  1991. utils.ErrorLog(err.Error())
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1993. return
  1994. }
  1995. if advice.StartTime > theTime.Unix() {
  1996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1997. return
  1998. }
  1999. exceAdvice := models.DoctorAdvice{
  2000. ExecutionStaff: executionStaff,
  2001. ExecutionTime: theTime.Unix(),
  2002. UpdatedTime: time.Now().Unix(),
  2003. }
  2004. // 查询信息规挡的设置天数
  2005. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2006. if infor.ID > 0 && infor.WeekDay > 0 {
  2007. var cha_time int64
  2008. timeNowStr := time.Now().Format("2006-01-02")
  2009. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2010. //今日的日期减去设置的日期
  2011. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2012. if cha_time >= advice.AdviceDate {
  2013. //查询审核是否允许
  2014. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2015. //申请状态不允许的情况 拒绝修改
  2016. if infor.ApplicationStatus != 1 {
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2018. return
  2019. }
  2020. }
  2021. }
  2022. if advice.ParentId > 0 {
  2023. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2024. //记录日志
  2025. byterequest, _ := json.Marshal(exceAdvice)
  2026. doctorAdviceLog := models.XtDoctorAdviceLog{
  2027. UserOrgId: exceAdvice.UserOrgId,
  2028. PatientId: exceAdvice.PatientId,
  2029. AdminUserId: adminUserInfo.AdminUser.Id,
  2030. Module: 2,
  2031. ErrLog: string(byterequest),
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Source: "电脑端执行医嘱",
  2036. RecordDate: exceAdvice.RecordDate,
  2037. }
  2038. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2039. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2040. redis := service.RedisClient()
  2041. //清空key 值
  2042. redis.Set(key, "", time.Second)
  2043. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2044. redis.Set(keyTwo, "", time.Second)
  2045. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2046. redis.Set(keyThree, "", time.Second)
  2047. theTimes := theTime.Format("2006-01-02")
  2048. fmt.Println("theTIME", theTime)
  2049. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2050. redis.Set(keyFour, "", time.Second)
  2051. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2052. redis.Set(keyFive, "", time.Second)
  2053. defer redis.Close()
  2054. } else {
  2055. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  2056. //记录日志
  2057. byterequest, _ := json.Marshal(exceAdvice)
  2058. doctorAdviceLog := models.XtDoctorAdviceLog{
  2059. UserOrgId: exceAdvice.UserOrgId,
  2060. PatientId: exceAdvice.PatientId,
  2061. AdminUserId: adminUserInfo.AdminUser.Id,
  2062. Module: 2,
  2063. ErrLog: string(byterequest),
  2064. Status: 1,
  2065. Ctime: time.Now().Unix(),
  2066. Mtime: 0,
  2067. Source: "电脑端执行医嘱",
  2068. RecordDate: exceAdvice.RecordDate,
  2069. }
  2070. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2071. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2072. redis := service.RedisClient()
  2073. //清空key 值
  2074. redis.Set(key, "", time.Second)
  2075. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2076. redis.Set(keyTwo, "", time.Second)
  2077. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2078. redis.Set(keyThree, "", time.Second)
  2079. theTimes := theTime.Format("2006-01-02")
  2080. fmt.Println("theTIME", theTime)
  2081. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2082. redis.Set(keyFour, "", time.Second)
  2083. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2084. redis.Set(keyFive, "", time.Second)
  2085. defer redis.Close()
  2086. }
  2087. if err != nil {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2089. return
  2090. }
  2091. advice.ExecutionStaff = executionStaff
  2092. advice.ExecutionTime = theTime.Unix()
  2093. //处理出库相关逻辑
  2094. //1.判断是否启用药品管理和自备药出库功能
  2095. //药品管理信息
  2096. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2097. //自备药信息
  2098. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2099. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2100. if drugStockConfig.IsOpen == 1 {
  2101. var total int64
  2102. var prescribing_number_total int64
  2103. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2104. for _, item := range advices {
  2105. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2106. //查询该药品是否有库存
  2107. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2108. //查询改药品信息
  2109. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2110. //判断单位是否相等
  2111. if medical.MaxUnit == item.PrescribingNumberUnit {
  2112. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2113. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2114. //转化为最小单位
  2115. total = list.Count*medical.MinNumber + list.StockMinNumber
  2116. prescribing_number_total = count * medical.MinNumber
  2117. }
  2118. if medical.MinUnit == item.PrescribingNumberUnit {
  2119. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2120. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2121. total = list.Count*medical.MinNumber + list.StockMinNumber
  2122. prescribing_number_total = count
  2123. }
  2124. if medical.IsUse != 1 {
  2125. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2126. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2127. advice.ExecutionState = 2
  2128. advice.ExecutionStaff = 0
  2129. advice.ExecutionTime = 0
  2130. c.ServeSuccessJSON(map[string]interface{}{
  2131. "msg": "3",
  2132. "advice": advice,
  2133. })
  2134. return
  2135. }
  2136. if prescribing_number_total > total {
  2137. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2138. advice.ExecutionState = 2
  2139. advice.ExecutionStaff = 0
  2140. advice.ExecutionTime = 0
  2141. c.ServeSuccessJSON(map[string]interface{}{
  2142. "msg": "2",
  2143. "advice": advice,
  2144. })
  2145. return
  2146. }
  2147. }
  2148. if medical.IsUse == 1 {
  2149. c.ServeSuccessJSON(map[string]interface{}{
  2150. "msg": "1",
  2151. "advice": advice,
  2152. })
  2153. return
  2154. }
  2155. if prescribing_number_total <= total {
  2156. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2157. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2158. if adviceSetting.IsAdviceOpen == 1 {
  2159. //查询是否出库按钮开启
  2160. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2161. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2162. if prescriptionConfig.IsOpen == 1 {
  2163. if medical.IsUse == 2 {
  2164. //是通过药房发药
  2165. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2166. //执行出库
  2167. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2168. if drugOutInfo.ID == 0 {
  2169. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2170. }
  2171. }
  2172. //不通过药房发药
  2173. if pharmacyConfig.IsOpen != 1 {
  2174. //执行出库
  2175. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2176. if drugOutInfo.ID == 0 {
  2177. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2178. }
  2179. }
  2180. //查询默认仓库
  2181. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2182. //查询默认仓库剩余多少库存
  2183. var sum_count int64
  2184. //更新字典里面的库存
  2185. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2186. for _, its := range stockInfo {
  2187. if its.MaxUnit == medical.MaxUnit {
  2188. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2189. }
  2190. sum_count += its.StockMaxNumber + its.StockMinNumber
  2191. }
  2192. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2193. //剩余库存
  2194. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2195. break
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "msg": "1",
  2198. "advice": advice,
  2199. })
  2200. return
  2201. }
  2202. if medical.IsUse == 1 {
  2203. c.ServeSuccessJSON(map[string]interface{}{
  2204. "msg": "1",
  2205. "advice": advice,
  2206. })
  2207. return
  2208. }
  2209. } else {
  2210. if medical.IsUse == 1 {
  2211. c.ServeSuccessJSON(map[string]interface{}{
  2212. "msg": "1",
  2213. "advice": advice,
  2214. })
  2215. return
  2216. }
  2217. }
  2218. } else {
  2219. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2220. if medical.IsUse == 2 {
  2221. //是通过药房发药
  2222. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2223. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2224. if drugOutInfo.ID == 0 {
  2225. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2226. }
  2227. }
  2228. //不通过药房发药
  2229. if pharmacyConfig.IsOpen != 1 {
  2230. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2231. if drugOutInfo.ID == 0 {
  2232. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2233. }
  2234. }
  2235. //更新字典里面的库存
  2236. var sum_count int64
  2237. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2238. for _, its := range stockInfo {
  2239. if its.MaxUnit == medical.MaxUnit {
  2240. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2241. }
  2242. sum_count += its.StockMaxNumber + its.StockMinNumber
  2243. }
  2244. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2245. //剩余库存
  2246. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2247. break
  2248. c.ServeSuccessJSON(map[string]interface{}{
  2249. "msg": "1",
  2250. "advice": advice,
  2251. })
  2252. return
  2253. }
  2254. if medical.IsUse == 1 {
  2255. c.ServeSuccessJSON(map[string]interface{}{
  2256. "msg": "1",
  2257. "advice": advice,
  2258. })
  2259. return
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. //自备药
  2266. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  2267. if selfPrescriptionOutOpen.IsOpen == 1 {
  2268. db := service.XTWriteDB()
  2269. tx := db.Begin()
  2270. defer func() {
  2271. if r := recover(); r != nil {
  2272. tx.Rollback()
  2273. } else {
  2274. tx.Commit()
  2275. }
  2276. }()
  2277. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  2278. if selfBasedrug.IsSelfDrug == 1 {
  2279. //查询是否有库存
  2280. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  2281. if len(info) > 0 {
  2282. var total_count int64
  2283. var prescribing_number_total int64
  2284. for _, item := range info {
  2285. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2286. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  2287. }
  2288. total_count += item.StockMaxNumber + item.StockMinNumber
  2289. }
  2290. //判断单位是否相等
  2291. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2292. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2293. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2294. //转化为最小单位
  2295. prescribing_number_total = count * selfBasedrug.MinNumber
  2296. }
  2297. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2298. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2299. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2300. prescribing_number_total = count
  2301. }
  2302. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2303. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2304. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2305. prescribing_number_total = count
  2306. }
  2307. if prescribing_number_total > total_count {
  2308. c.ServeSuccessJSON(map[string]interface{}{
  2309. "msg": "3",
  2310. "advice": advice,
  2311. })
  2312. return
  2313. }
  2314. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2315. //出库
  2316. if prescribing_number_total <= total_count {
  2317. timeStr := time.Now().Format("2006-01-02")
  2318. timeArr := strings.Split(timeStr, "-")
  2319. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  2320. total = total + 1
  2321. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2322. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2323. number = number + total
  2324. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2325. operation_time := time.Now().Unix()
  2326. creater := c.GetAdminUserInfo().AdminUser.Id
  2327. //创建一个出库单
  2328. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2329. WarehouseOutOrderNumber: warehousing_out_order,
  2330. OperationTime: operation_time,
  2331. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2332. Creater: creater,
  2333. Ctime: time.Now().Unix(),
  2334. Status: 1,
  2335. WarehouseOutTime: advice.AdviceDate,
  2336. Type: 0,
  2337. PatientId: advice.PatientId,
  2338. IsCheck: 1,
  2339. IsSys: 1,
  2340. }
  2341. //查询今日是否有出库数据
  2342. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2343. if lastWarehouseOut.ID == 0 {
  2344. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2345. }
  2346. //查询今日是否有出库数据
  2347. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2348. //出库
  2349. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2350. WarehouseOutId: lastWarehouseOutOne.ID,
  2351. WarehouseOutOrderNumber: warehousing_out_order,
  2352. DrugId: advice.DrugId,
  2353. Count: prescribing_number_total,
  2354. Price: 0,
  2355. TotalPrice: 0,
  2356. Status: 1,
  2357. Ctime: advice.AdviceDate,
  2358. Mtime: advice.AdviceDate,
  2359. Remark: "",
  2360. OrgId: advice.UserOrgId,
  2361. Type: 0,
  2362. Manufacturer: selfBasedrug.Manufacturer,
  2363. Dealer: selfBasedrug.Dealer,
  2364. RetailPrice: 0,
  2365. RetailTotalPrice: 0,
  2366. CountUnit: selfBasedrug.MinUnit,
  2367. ExpiryDate: 0,
  2368. ProductDate: 0,
  2369. Number: "",
  2370. BatchNumber: "",
  2371. IsSys: 0,
  2372. WarehouseInfoId: 0,
  2373. AdminUserId: 0,
  2374. StockCount: "",
  2375. IsCheck: 1,
  2376. SysRecordTime: advice.AdviceDate,
  2377. PatientId: advice.PatientId,
  2378. AdviceId: advice.ID,
  2379. ClassType: "",
  2380. }
  2381. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2382. for _, it := range warehousingOutInfo {
  2383. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2384. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2385. //出库逻辑
  2386. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2387. //查询剩余库存
  2388. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2389. var sum_count int64
  2390. for _, its := range stockInfo {
  2391. if its.MaxUnit == medical.MaxUnit {
  2392. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2393. }
  2394. sum_count += its.StockMaxNumber + its.StockMinNumber
  2395. }
  2396. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2397. }
  2398. }
  2399. } else {
  2400. c.ServeSuccessJSON(map[string]interface{}{
  2401. "msg": "3",
  2402. "advice": advice,
  2403. })
  2404. return
  2405. }
  2406. }
  2407. }
  2408. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2409. for _, item := range advices {
  2410. if item.Way == 2 {
  2411. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2412. if item.ExecutionState == 1 {
  2413. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2414. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2415. timeStr := time.Now().Format("2006-01-02")
  2416. timeArr := strings.Split(timeStr, "-")
  2417. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2418. total = total + 1
  2419. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2420. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2421. number = number + total
  2422. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2423. //插入自备药出库单
  2424. outStock := models.XtSelfOutStock{
  2425. DrugName: item.AdviceName,
  2426. DrugNameId: item.DrugId,
  2427. DrugSpec: item.AdviceDesc,
  2428. OutstoreNumber: count,
  2429. AdminUserId: adminUserInfo.AdminUser.Id,
  2430. StorckTime: item.RecordDate,
  2431. UserOrgId: adminUserInfo.CurrentOrgId,
  2432. CreatedTime: time.Now().Unix(),
  2433. Status: 1,
  2434. PatientId: item.PatientId,
  2435. ExitMode: 2,
  2436. MedicId: item.DrugId,
  2437. StockOutNumber: warehousing_out_order,
  2438. }
  2439. service.CreateOutStock(&outStock)
  2440. }
  2441. }
  2442. }
  2443. }
  2444. c.ServeSuccessJSON(map[string]interface{}{
  2445. "msg": "1",
  2446. "advice": advice,
  2447. })
  2448. return
  2449. } else {
  2450. if id <= 0 || patient <= 0 {
  2451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2452. return
  2453. }
  2454. if len(executionTime) <= 0 {
  2455. utils.ErrorLog("execution_time")
  2456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2457. return
  2458. }
  2459. adminUserInfo := c.GetAdminUserInfo()
  2460. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2461. if advice.ID == 0 || advice.PatientId != patient {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2463. return
  2464. }
  2465. //医嘱已执行
  2466. if advice.ExecutionState == 1 {
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2468. return
  2469. }
  2470. executionStaff := adminUserInfo.AdminUser.Id
  2471. timeLayout := "2006-01-02 15:04:05"
  2472. loc, _ := time.LoadLocation("Local")
  2473. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2474. if err != nil {
  2475. utils.ErrorLog(err.Error())
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. if advice.StartTime > theTime.Unix() {
  2480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2481. return
  2482. }
  2483. exceAdvice := models.HisDoctorAdviceInfo{
  2484. ExecutionStaff: executionStaff,
  2485. ExecutionTime: theTime.Unix(),
  2486. UpdatedTime: time.Now().Unix(),
  2487. }
  2488. if advice.ParentId > 0 {
  2489. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2490. //记录日志
  2491. byterequest, _ := json.Marshal(exceAdvice)
  2492. doctorAdviceLog := models.XtDoctorAdviceLog{
  2493. UserOrgId: exceAdvice.UserOrgId,
  2494. PatientId: exceAdvice.PatientId,
  2495. AdminUserId: adminUserInfo.AdminUser.Id,
  2496. Module: 2,
  2497. ErrLog: string(byterequest),
  2498. Status: 1,
  2499. Ctime: time.Now().Unix(),
  2500. Mtime: 0,
  2501. Source: "电脑端执行His医嘱",
  2502. RecordDate: exceAdvice.RecordDate,
  2503. }
  2504. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2505. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2506. redis := service.RedisClient()
  2507. //清空key 值
  2508. redis.Set(key, "", time.Second)
  2509. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2510. redis.Set(keyTwo, "", time.Second)
  2511. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2512. redis.Set(keyThree, "", time.Second)
  2513. theTimes := theTime.Format("2006-01-02")
  2514. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2515. redis.Set(keyFour, "", time.Second)
  2516. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2517. redis.Set(keyFive, "", time.Second)
  2518. defer redis.Close()
  2519. } else {
  2520. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2521. //记录日志
  2522. byterequest, _ := json.Marshal(exceAdvice)
  2523. doctorAdviceLog := models.XtDoctorAdviceLog{
  2524. UserOrgId: exceAdvice.UserOrgId,
  2525. PatientId: exceAdvice.PatientId,
  2526. AdminUserId: adminUserInfo.AdminUser.Id,
  2527. Module: 2,
  2528. ErrLog: string(byterequest),
  2529. Status: 1,
  2530. Ctime: time.Now().Unix(),
  2531. Mtime: 0,
  2532. Source: "电脑端执行His医嘱",
  2533. RecordDate: exceAdvice.RecordDate,
  2534. }
  2535. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2536. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2537. redis := service.RedisClient()
  2538. //清空key 值
  2539. redis.Set(key, "", time.Second)
  2540. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2541. redis.Set(keyTwo, "", time.Second)
  2542. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2543. redis.Set(keyThree, "", time.Second)
  2544. theTimes := theTime.Format("2006-01-02")
  2545. fmt.Println("theTIME", theTime)
  2546. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2547. redis.Set(keyFour, "", time.Second)
  2548. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2549. redis.Set(keyFive, "", time.Second)
  2550. defer redis.Close()
  2551. }
  2552. if err != nil {
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2554. return
  2555. }
  2556. advice.ExecutionStaff = executionStaff
  2557. advice.ExecutionTime = theTime.Unix()
  2558. //处理出库相关逻辑
  2559. //1.判断是否启用药品管理和自备药出库功能
  2560. //药品自动出库开关管理信息
  2561. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2562. if drugStockConfig.IsOpen == 1 {
  2563. //查询已经执行的医嘱
  2564. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2565. for _, item := range advices {
  2566. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2567. var total int64
  2568. var prescribing_number_total int64
  2569. //药品保存处方出库
  2570. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2571. if config.IsOpen != 1 {
  2572. //查询默认出库仓库
  2573. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2574. //查询该药品在默认仓库是否有库存
  2575. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2576. //判断单位是否相等
  2577. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2578. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2579. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2580. //转化为最小单位
  2581. total = list.Count*medical.MinNumber + list.StockMinNumber
  2582. prescribing_number_total = count * medical.MinNumber
  2583. }
  2584. if medical.MinUnit == advice.PrescribingNumberUnit {
  2585. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2586. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2587. total = list.Count*medical.MinNumber + list.StockMinNumber
  2588. prescribing_number_total = count
  2589. }
  2590. if medical.IsUse == 1 {
  2591. drugError := models.XtDrugError{
  2592. UserOrgId: item.UserOrgId,
  2593. DrugId: item.DrugId,
  2594. RecordDate: item.AdviceDate,
  2595. PatientId: item.PatientId,
  2596. Remark: "电脑端零用药品",
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: 0,
  2600. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2601. Prescribingnumber: item.PrescribingNumber,
  2602. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2603. }
  2604. service.CreateDrugError(drugError)
  2605. c.ServeSuccessJSON(map[string]interface{}{
  2606. "msg": "1",
  2607. "advice": advice,
  2608. })
  2609. return
  2610. }
  2611. if medical.IsUse != 1 {
  2612. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2613. drugError := models.XtDrugError{
  2614. UserOrgId: item.UserOrgId,
  2615. DrugId: item.DrugId,
  2616. RecordDate: item.AdviceDate,
  2617. PatientId: item.PatientId,
  2618. Remark: "电脑端药品库存不足",
  2619. Status: 1,
  2620. Ctime: time.Now().Unix(),
  2621. Mtime: 0,
  2622. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2623. Prescribingnumber: item.PrescribingNumber,
  2624. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2625. }
  2626. service.CreateDrugError(drugError)
  2627. c.ServeSuccessJSON(map[string]interface{}{
  2628. "msg": "3",
  2629. "advice": advice,
  2630. })
  2631. return
  2632. }
  2633. if prescribing_number_total > total {
  2634. drugError := models.XtDrugError{
  2635. UserOrgId: item.UserOrgId,
  2636. DrugId: item.DrugId,
  2637. RecordDate: item.AdviceDate,
  2638. PatientId: item.PatientId,
  2639. Remark: "电脑端出库数量大于总库存",
  2640. Status: 1,
  2641. Ctime: time.Now().Unix(),
  2642. Mtime: 0,
  2643. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2644. Prescribingnumber: item.PrescribingNumber,
  2645. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2646. }
  2647. service.CreateDrugError(drugError)
  2648. c.ServeSuccessJSON(map[string]interface{}{
  2649. "msg": "2",
  2650. "advice": advice,
  2651. })
  2652. return
  2653. }
  2654. }
  2655. if prescribing_number_total <= total {
  2656. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2657. if medical.IsUse == 2 {
  2658. if config.IsOpen != 1 {
  2659. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2660. // 开始主事务
  2661. db := service.XTWriteDB()
  2662. tx := db.Begin()
  2663. // 在函数结束时处理事务回滚
  2664. defer func() {
  2665. if r := recover(); r != nil {
  2666. tx.Rollback()
  2667. }
  2668. }()
  2669. creater := c.GetAdminUserInfo().AdminUser.Id
  2670. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2671. var out_count int64
  2672. if len(outListExport) > 0 {
  2673. for _, item := range outListExport {
  2674. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2675. out_count = item.Count * medical.MinNumber
  2676. }
  2677. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2678. out_count = item.Count
  2679. }
  2680. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2681. out_count = item.Count * medical.MinNumber
  2682. }
  2683. }
  2684. }
  2685. newadviceInfo := &models.HisDoctorAdviceInfo{
  2686. ID: item.ID,
  2687. UserOrgId: item.UserOrgId,
  2688. PatientId: item.PatientId,
  2689. HisPatientId: item.HisPatientId,
  2690. AdviceType: item.AdviceType,
  2691. AdviceDate: item.AdviceDate,
  2692. StartTime: item.StartTime,
  2693. AdviceName: item.AdviceName,
  2694. AdviceDesc: item.AdviceDesc,
  2695. ReminderDate: item.ReminderDate,
  2696. SingleDose: item.SingleDose,
  2697. SingleDoseUnit: item.SingleDoseUnit,
  2698. PrescribingNumber: item.PrescribingNumber,
  2699. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2700. DeliveryWay: item.DeliveryWay,
  2701. ExecutionFrequency: item.ExecutionFrequency,
  2702. AdviceDoctor: item.AdviceDoctor,
  2703. Status: item.Status,
  2704. CreatedTime: item.CreatedTime,
  2705. UpdatedTime: item.UpdatedTime,
  2706. AdviceAffirm: item.AdviceAffirm,
  2707. Remark: item.Remark,
  2708. StopTime: item.StopTime,
  2709. StopReason: item.StopReason,
  2710. StopDoctor: item.StopDoctor,
  2711. StopState: item.StopState,
  2712. ParentId: item.ParentId,
  2713. ExecutionTime: item.ExecutionTime,
  2714. ExecutionStaff: item.ExecutionStaff,
  2715. ExecutionState: item.ExecutionState,
  2716. Checker: item.Checker,
  2717. RecordDate: item.RecordDate,
  2718. DialysisOrderId: item.DialysisOrderId,
  2719. CheckTime: item.CheckTime,
  2720. CheckState: item.CheckState,
  2721. DrugSpec: item.DrugSpec,
  2722. DrugSpecUnit: item.DrugSpecUnit,
  2723. Groupno: item.Groupno,
  2724. RemindType: item.RemindType,
  2725. FrequencyType: item.FrequencyType,
  2726. DayCount: item.DayCount,
  2727. WeekDay: item.WeekDay,
  2728. TemplateId: item.TemplateId,
  2729. Modifier: item.Modifier,
  2730. DrugId: item.DrugId,
  2731. Price: item.Price,
  2732. PrescriptionId: item.PrescriptionId,
  2733. MedListCodg: item.MedListCodg,
  2734. FeedetlSn: item.FeedetlSn,
  2735. Day: item.DayCount,
  2736. ChildDoctorAdvice: nil,
  2737. Drug: models.Drug{},
  2738. Diagnosis: item.Diagnosis,
  2739. Way: item.Way,
  2740. HospApprFlag: item.HospApprFlag,
  2741. LmtUsedFlag: item.LmtUsedFlag,
  2742. HisOrderInfo: models.HisOrderInfo{},
  2743. IsMedicine: item.IsMedicine,
  2744. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2745. Child: nil,
  2746. IsSettle: item.IsSettle,
  2747. IsMobile: item.IsMobile,
  2748. IsSelfDrug: item.IsSelfDrug,
  2749. DrugWayCount: item.DrugWayCount,
  2750. }
  2751. //如果当前医嘱数量大于历史出库数据则需要出库
  2752. if prescribing_number_total > out_count {
  2753. //按最小单位出库
  2754. var cha_count = prescribing_number_total - out_count
  2755. item.PrescribingNumber = float64(cha_count)
  2756. item.PrescribingNumberUnit = medical.MinUnit
  2757. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2758. }
  2759. //如果当前医嘱数量小于历史出库数据则需要退库
  2760. if prescribing_number_total < out_count {
  2761. var cha_count = out_count - prescribing_number_total
  2762. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2763. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2764. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2765. }
  2766. if prescribing_number_total == out_count {
  2767. if out_count == 0 {
  2768. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2769. }
  2770. }
  2771. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2772. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2773. //查询该药品是否有出库记录
  2774. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2775. if len(flowMap) == 0 {
  2776. errs := service.UpdateHisAdviceById(item.ID)
  2777. if errs != nil {
  2778. drugError := models.XtDrugError{
  2779. UserOrgId: item.UserOrgId,
  2780. DrugId: item.DrugId,
  2781. RecordDate: item.AdviceDate,
  2782. PatientId: item.PatientId,
  2783. Remark: "出库记录为空,更新执行人失败",
  2784. Status: 1,
  2785. Ctime: time.Now().Unix(),
  2786. Mtime: 0,
  2787. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2788. Prescribingnumber: item.PrescribingNumber,
  2789. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2790. }
  2791. service.CreateDrugError(drugError)
  2792. }
  2793. c.ServeSuccessJSON(map[string]interface{}{
  2794. "msg": "6",
  2795. "advice": advice,
  2796. })
  2797. return
  2798. }
  2799. }
  2800. tx.Commit()
  2801. }
  2802. //不通过药房发药
  2803. if pharmacyConfig.IsOpen != 1 {
  2804. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2805. // 开始主事务
  2806. db := service.XTWriteDB()
  2807. tx := db.Begin()
  2808. // 在函数结束时处理事务回滚
  2809. defer func() {
  2810. if r := recover(); r != nil {
  2811. tx.Rollback()
  2812. }
  2813. }()
  2814. creater := c.GetAdminUserInfo().AdminUser.Id
  2815. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2816. var out_count int64
  2817. if len(outListExport) > 0 {
  2818. for _, item := range outListExport {
  2819. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2820. out_count = item.Count * medical.MinNumber
  2821. }
  2822. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2823. out_count = item.Count
  2824. }
  2825. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2826. out_count = item.Count * medical.MinNumber
  2827. }
  2828. }
  2829. }
  2830. newadviceInfo := &models.HisDoctorAdviceInfo{
  2831. ID: item.ID,
  2832. UserOrgId: item.UserOrgId,
  2833. PatientId: item.PatientId,
  2834. HisPatientId: item.HisPatientId,
  2835. AdviceType: item.AdviceType,
  2836. AdviceDate: item.AdviceDate,
  2837. StartTime: item.StartTime,
  2838. AdviceName: item.AdviceName,
  2839. AdviceDesc: item.AdviceDesc,
  2840. ReminderDate: item.ReminderDate,
  2841. SingleDose: item.SingleDose,
  2842. SingleDoseUnit: item.SingleDoseUnit,
  2843. PrescribingNumber: item.PrescribingNumber,
  2844. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2845. DeliveryWay: item.DeliveryWay,
  2846. ExecutionFrequency: item.ExecutionFrequency,
  2847. AdviceDoctor: item.AdviceDoctor,
  2848. Status: item.Status,
  2849. CreatedTime: item.CreatedTime,
  2850. UpdatedTime: item.UpdatedTime,
  2851. AdviceAffirm: item.AdviceAffirm,
  2852. Remark: item.Remark,
  2853. StopTime: item.StopTime,
  2854. StopReason: item.StopReason,
  2855. StopDoctor: item.StopDoctor,
  2856. StopState: item.StopState,
  2857. ParentId: item.ParentId,
  2858. ExecutionTime: item.ExecutionTime,
  2859. ExecutionStaff: item.ExecutionStaff,
  2860. ExecutionState: item.ExecutionState,
  2861. Checker: item.Checker,
  2862. RecordDate: item.RecordDate,
  2863. DialysisOrderId: item.DialysisOrderId,
  2864. CheckTime: item.CheckTime,
  2865. CheckState: item.CheckState,
  2866. DrugSpec: item.DrugSpec,
  2867. DrugSpecUnit: item.DrugSpecUnit,
  2868. Groupno: item.Groupno,
  2869. RemindType: item.RemindType,
  2870. FrequencyType: item.FrequencyType,
  2871. DayCount: item.DayCount,
  2872. WeekDay: item.WeekDay,
  2873. TemplateId: item.TemplateId,
  2874. Modifier: item.Modifier,
  2875. DrugId: item.DrugId,
  2876. Price: item.Price,
  2877. PrescriptionId: item.PrescriptionId,
  2878. MedListCodg: item.MedListCodg,
  2879. FeedetlSn: item.FeedetlSn,
  2880. Day: item.DayCount,
  2881. ChildDoctorAdvice: nil,
  2882. Drug: models.Drug{},
  2883. Diagnosis: item.Diagnosis,
  2884. Way: item.Way,
  2885. HospApprFlag: item.HospApprFlag,
  2886. LmtUsedFlag: item.LmtUsedFlag,
  2887. HisOrderInfo: models.HisOrderInfo{},
  2888. IsMedicine: item.IsMedicine,
  2889. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2890. Child: nil,
  2891. IsSettle: item.IsSettle,
  2892. IsMobile: item.IsMobile,
  2893. IsSelfDrug: item.IsSelfDrug,
  2894. DrugWayCount: item.DrugWayCount,
  2895. }
  2896. //如果当前医嘱数量大于历史出库数据则需要出库
  2897. if prescribing_number_total > out_count {
  2898. //按最小单位出库
  2899. var cha_count = prescribing_number_total - out_count
  2900. newadviceInfo.PrescribingNumber = float64(cha_count)
  2901. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2902. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2903. }
  2904. //如果当前医嘱数量小于历史出库数据则需要退库
  2905. if prescribing_number_total < out_count {
  2906. var cha_count = out_count - prescribing_number_total
  2907. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2908. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2909. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2910. }
  2911. if prescribing_number_total == out_count {
  2912. if out_count == 0 {
  2913. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2914. }
  2915. }
  2916. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2917. tx.Commit()
  2918. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2919. //查询该药品是否有出库记录
  2920. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2921. if len(flowMap) == 0 {
  2922. errs := service.UpdateHisAdviceById(item.ID)
  2923. if errs != nil {
  2924. drugError := models.XtDrugError{
  2925. UserOrgId: item.UserOrgId,
  2926. DrugId: item.DrugId,
  2927. RecordDate: item.AdviceDate,
  2928. PatientId: item.PatientId,
  2929. Remark: "出库记录为空,更新执行人失败",
  2930. Status: 1,
  2931. Ctime: time.Now().Unix(),
  2932. Mtime: 0,
  2933. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2934. Prescribingnumber: item.PrescribingNumber,
  2935. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2936. }
  2937. service.CreateDrugError(drugError)
  2938. }
  2939. c.ServeSuccessJSON(map[string]interface{}{
  2940. "msg": "6",
  2941. "advice": advice,
  2942. })
  2943. return
  2944. }
  2945. }
  2946. }
  2947. //查询默认仓库
  2948. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2949. //查询默认仓库剩余多少库存
  2950. var sum_count int64
  2951. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2952. for _, its := range stockInfo {
  2953. if its.MaxUnit == medical.MaxUnit {
  2954. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2955. }
  2956. sum_count += its.StockMaxNumber + its.StockMinNumber
  2957. }
  2958. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2959. //出库数量累加
  2960. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2961. //剩余库存
  2962. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2963. break
  2964. c.ServeSuccessJSON(map[string]interface{}{
  2965. "msg": "1",
  2966. "advice": advice,
  2967. })
  2968. return
  2969. }
  2970. }
  2971. if medical.IsUse == 1 {
  2972. c.ServeSuccessJSON(map[string]interface{}{
  2973. "msg": "1",
  2974. "advice": advice,
  2975. })
  2976. return
  2977. }
  2978. }
  2979. }
  2980. }
  2981. }
  2982. //自备药
  2983. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  2984. if selfPrescriptionOutOpen.IsOpen == 1 {
  2985. db := service.XTWriteDB()
  2986. tx := db.Begin()
  2987. defer func() {
  2988. if r := recover(); r != nil {
  2989. tx.Rollback()
  2990. } else {
  2991. tx.Commit()
  2992. }
  2993. }()
  2994. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  2995. if selfBasedrug.IsSelfDrug == 1 {
  2996. //查询是否有库存
  2997. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  2998. if len(info) > 0 {
  2999. var total_count int64
  3000. var prescribing_number_total int64
  3001. for _, item := range info {
  3002. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3003. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  3004. }
  3005. total_count += item.StockMaxNumber + item.StockMinNumber
  3006. }
  3007. //判断单位是否相等
  3008. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3009. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3010. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3011. //转化为最小单位
  3012. prescribing_number_total = count * selfBasedrug.MinNumber
  3013. }
  3014. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3015. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3016. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3017. prescribing_number_total = count
  3018. }
  3019. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  3020. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3021. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3022. prescribing_number_total = count
  3023. }
  3024. if prescribing_number_total > total_count {
  3025. c.ServeSuccessJSON(map[string]interface{}{
  3026. "msg": "3",
  3027. "advice": advice,
  3028. })
  3029. return
  3030. }
  3031. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  3032. //出库
  3033. if prescribing_number_total <= total_count {
  3034. timeStr := time.Now().Format("2006-01-02")
  3035. timeArr := strings.Split(timeStr, "-")
  3036. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  3037. total = total + 1
  3038. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3039. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3040. number = number + total
  3041. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3042. operation_time := time.Now().Unix()
  3043. creater := c.GetAdminUserInfo().AdminUser.Id
  3044. //创建一个出库单
  3045. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  3046. WarehouseOutOrderNumber: warehousing_out_order,
  3047. OperationTime: operation_time,
  3048. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3049. Creater: creater,
  3050. Ctime: time.Now().Unix(),
  3051. Status: 1,
  3052. WarehouseOutTime: advice.AdviceDate,
  3053. Type: 0,
  3054. PatientId: advice.PatientId,
  3055. IsCheck: 1,
  3056. IsSys: 1,
  3057. }
  3058. //查询今日是否有出库数据
  3059. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3060. if lastWarehouseOut.ID == 0 {
  3061. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  3062. }
  3063. //查询今日是否有出库数据
  3064. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3065. //出库
  3066. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  3067. WarehouseOutId: lastWarehouseOutOne.ID,
  3068. WarehouseOutOrderNumber: warehousing_out_order,
  3069. DrugId: advice.DrugId,
  3070. Count: prescribing_number_total,
  3071. Price: 0,
  3072. TotalPrice: 0,
  3073. Status: 1,
  3074. Ctime: advice.AdviceDate,
  3075. Mtime: advice.AdviceDate,
  3076. Remark: "",
  3077. OrgId: advice.UserOrgId,
  3078. Type: 0,
  3079. Manufacturer: selfBasedrug.Manufacturer,
  3080. Dealer: selfBasedrug.Dealer,
  3081. RetailPrice: 0,
  3082. RetailTotalPrice: 0,
  3083. CountUnit: selfBasedrug.MinUnit,
  3084. ExpiryDate: 0,
  3085. ProductDate: 0,
  3086. Number: "",
  3087. BatchNumber: "",
  3088. IsSys: 0,
  3089. WarehouseInfoId: 0,
  3090. AdminUserId: 0,
  3091. StockCount: "",
  3092. IsCheck: 1,
  3093. SysRecordTime: advice.AdviceDate,
  3094. PatientId: advice.PatientId,
  3095. AdviceId: advice.ID,
  3096. ClassType: "",
  3097. }
  3098. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  3099. for _, it := range warehousingOutInfo {
  3100. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  3101. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  3102. //出库逻辑
  3103. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  3104. //查询剩余库存
  3105. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  3106. var sum_count int64
  3107. for _, its := range stockInfo {
  3108. if its.MaxUnit == medical.MaxUnit {
  3109. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3110. }
  3111. sum_count += its.StockMaxNumber + its.StockMinNumber
  3112. }
  3113. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  3114. }
  3115. }
  3116. }
  3117. }
  3118. }
  3119. c.ServeSuccessJSON(map[string]interface{}{
  3120. "msg": "1",
  3121. "advice": advice,
  3122. })
  3123. return
  3124. }
  3125. }
  3126. func (c *PatientApiController) CheckGroupAdvice() {
  3127. groupno, _ := c.GetInt64("groupno", 0)
  3128. if groupno <= 0 {
  3129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3130. return
  3131. }
  3132. adminUserInfo := c.GetAdminUserInfo()
  3133. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  3134. if advice.ID == 0 {
  3135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3136. return
  3137. }
  3138. if advice.CheckState == 1 {
  3139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3140. return
  3141. }
  3142. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3144. return
  3145. }
  3146. checker := adminUserInfo.AdminUser.Id
  3147. theTime := time.Now()
  3148. exceAdvice := models.DoctorAdvice{
  3149. Checker: checker,
  3150. CheckTime: theTime.Unix(),
  3151. UpdatedTime: time.Now().Unix(),
  3152. }
  3153. var err error
  3154. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  3155. if err != nil {
  3156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3157. return
  3158. }
  3159. advice.Checker = checker
  3160. advice.CheckTime = theTime.Unix()
  3161. c.ServeSuccessJSON(map[string]interface{}{
  3162. "msg": "ok",
  3163. "advice": advice,
  3164. })
  3165. return
  3166. }
  3167. func (c *PatientApiController) CheckDoctorAdvice() {
  3168. patient, _ := c.GetInt64("patient", 0)
  3169. id, _ := c.GetInt64("id", 0)
  3170. origin, _ := c.GetInt64("origin", 0)
  3171. if origin != 2 {
  3172. // executionTime := c.GetString("execution_time")
  3173. if id <= 0 || patient <= 0 {
  3174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3175. return
  3176. }
  3177. adminUserInfo := c.GetAdminUserInfo()
  3178. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3179. if advice.ID == 0 || advice.PatientId != patient {
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3181. return
  3182. }
  3183. if advice.CheckState == 1 {
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3185. return
  3186. }
  3187. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3189. return
  3190. }
  3191. // executionStaff := adminUserInfo.AdminUser.Id
  3192. checker := adminUserInfo.AdminUser.Id
  3193. // timeLayout := "2006-01-02 15:04:05"
  3194. // loc, _ := time.LoadLocation("Local")
  3195. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  3196. // if err != nil {
  3197. // utils.ErrorLog(err.Error())
  3198. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3199. // return
  3200. // }
  3201. theTime := time.Now()
  3202. if advice.ExecutionTime > theTime.Unix() {
  3203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3204. return
  3205. }
  3206. exceAdvice := models.DoctorAdvice{
  3207. Checker: checker,
  3208. CheckTime: theTime.Unix(),
  3209. UpdatedTime: time.Now().Unix(),
  3210. }
  3211. var err error
  3212. // 查询信息规挡的设置天数
  3213. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3214. if infor.ID > 0 && infor.WeekDay > 0 {
  3215. var cha_time int64
  3216. timeNowStr := time.Now().Format("2006-01-02")
  3217. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3218. //今日的日期减去设置的日期
  3219. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3220. if cha_time >= advice.AdviceDate {
  3221. //查询审核是否允许
  3222. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3223. //申请状态不允许的情况 拒绝修改
  3224. if infor.ApplicationStatus != 1 {
  3225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3226. return
  3227. }
  3228. }
  3229. }
  3230. if advice.ParentId > 0 {
  3231. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3232. //记录日志
  3233. byterequest, _ := json.Marshal(exceAdvice)
  3234. adviceLog := models.XtDoctorAdviceLog{
  3235. UserOrgId: exceAdvice.UserOrgId,
  3236. PatientId: exceAdvice.PatientId,
  3237. AdminUserId: adminUserInfo.AdminUser.Id,
  3238. Module: 3,
  3239. ErrLog: string(byterequest),
  3240. Status: 1,
  3241. Ctime: time.Now().Unix(),
  3242. Mtime: 0,
  3243. Source: "核对医嘱",
  3244. RecordDate: exceAdvice.AdviceDate,
  3245. }
  3246. service.CreateDoctorAdviceLog(adviceLog)
  3247. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3248. redis := service.RedisClient()
  3249. //清空key 值
  3250. redis.Set(key, "", time.Second)
  3251. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3252. redis.Set(keyTwo, "", time.Second)
  3253. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3254. redis.Set(keyThree, "", time.Second)
  3255. recordDate := theTime.Format("2006-01-02")
  3256. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3257. redis.Set(keyFour, "", time.Second)
  3258. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3259. redis.Set(keyFive, "", time.Second)
  3260. } else {
  3261. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  3262. //记录日志
  3263. byterequest, _ := json.Marshal(exceAdvice)
  3264. adviceLog := models.XtDoctorAdviceLog{
  3265. UserOrgId: exceAdvice.UserOrgId,
  3266. PatientId: exceAdvice.PatientId,
  3267. AdminUserId: adminUserInfo.AdminUser.Id,
  3268. Module: 3,
  3269. ErrLog: string(byterequest),
  3270. Status: 1,
  3271. Ctime: time.Now().Unix(),
  3272. Mtime: 0,
  3273. Source: "核对医嘱",
  3274. RecordDate: exceAdvice.AdviceDate,
  3275. }
  3276. service.CreateDoctorAdviceLog(adviceLog)
  3277. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3278. redis := service.RedisClient()
  3279. //清空key 值
  3280. redis.Set(key, "", time.Second)
  3281. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3282. redis.Set(keyTwo, "", time.Second)
  3283. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3284. redis.Set(keyThree, "", time.Second)
  3285. recordDate := theTime.Format("2006-01-02")
  3286. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3287. redis.Set(keyFour, "", time.Second)
  3288. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3289. redis.Set(keyFive, "", time.Second)
  3290. }
  3291. if err != nil {
  3292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3293. return
  3294. }
  3295. // advice.ExecutionStaff = executionStaff
  3296. // advice.ExecutionTime = theTime.Unix()
  3297. advice.Checker = checker
  3298. advice.CheckTime = theTime.Unix()
  3299. c.ServeSuccessJSON(map[string]interface{}{
  3300. "msg": "ok",
  3301. "advice": advice,
  3302. })
  3303. return
  3304. } else {
  3305. if id <= 0 || patient <= 0 {
  3306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3307. return
  3308. }
  3309. adminUserInfo := c.GetAdminUserInfo()
  3310. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3311. if advice.ID == 0 || advice.PatientId != patient {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3313. return
  3314. }
  3315. if advice.CheckState == 1 {
  3316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3317. return
  3318. }
  3319. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3321. return
  3322. }
  3323. checker := adminUserInfo.AdminUser.Id
  3324. theTime := time.Now()
  3325. if advice.ExecutionTime > theTime.Unix() {
  3326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3327. return
  3328. }
  3329. exceAdvice := models.HisDoctorAdviceInfo{
  3330. Checker: checker,
  3331. CheckTime: theTime.Unix(),
  3332. UpdatedTime: time.Now().Unix(),
  3333. }
  3334. var err error
  3335. if advice.ParentId > 0 {
  3336. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3337. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3338. redis := service.RedisClient()
  3339. //清空key 值
  3340. redis.Set(key, "", time.Second)
  3341. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3342. redis.Set(keyTwo, "", time.Second)
  3343. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3344. redis.Set(keyThree, "", time.Second)
  3345. recordDate := theTime.Format("2006-01-02")
  3346. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3347. redis.Set(keyFour, "", time.Second)
  3348. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3349. redis.Set(keyFive, "", time.Second)
  3350. } else {
  3351. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  3352. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3353. redis := service.RedisClient()
  3354. //清空key 值
  3355. redis.Set(key, "", time.Second)
  3356. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3357. redis.Set(keyTwo, "", time.Second)
  3358. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3359. redis.Set(keyThree, "", time.Second)
  3360. recordDate := theTime.Format("2006-01-02")
  3361. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3362. redis.Set(keyFour, "", time.Second)
  3363. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3364. redis.Set(keyFive, "", time.Second)
  3365. }
  3366. if err != nil {
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3368. return
  3369. }
  3370. // advice.ExecutionStaff = executionStaff
  3371. // advice.ExecutionTime = theTime.Unix()
  3372. advice.Checker = checker
  3373. advice.CheckTime = theTime.Unix()
  3374. c.ServeSuccessJSON(map[string]interface{}{
  3375. "msg": "ok",
  3376. "advice": advice,
  3377. })
  3378. return
  3379. }
  3380. }
  3381. func (c *PatientApiController) UpdateDoctorAdvice() {
  3382. patient, _ := c.GetInt64("patient", 0)
  3383. id, _ := c.GetInt64("id", 0)
  3384. if id <= 0 || patient <= 0 {
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3386. return
  3387. }
  3388. adminUserInfo := c.GetAdminUserInfo()
  3389. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3390. if advice.ID == 0 || advice.PatientId != patient {
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3392. return
  3393. }
  3394. //if advice.AdviceType == 1 {
  3395. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  3396. // return
  3397. //}
  3398. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  3399. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3401. return
  3402. }
  3403. }
  3404. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3405. //if appRole.UserType == 3 {
  3406. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3407. // if getPermissionErr != nil {
  3408. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3409. // return
  3410. // } else if headNursePermission == nil {
  3411. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3412. // return
  3413. // }
  3414. //}
  3415. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  3417. // return
  3418. //}
  3419. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  3420. if code > 0 {
  3421. c.ServeFailJSONWithSGJErrorCode(code)
  3422. return
  3423. }
  3424. advice.UpdatedTime = time.Now().Unix()
  3425. advice.Modifier = adminUserInfo.AdminUser.Id
  3426. // 查询信息规挡的设置天数
  3427. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3428. if infor.ID > 0 && infor.WeekDay > 0 {
  3429. var cha_time int64
  3430. timeNowStr := time.Now().Format("2006-01-02")
  3431. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3432. //今日的日期减去设置的日期
  3433. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3434. if cha_time >= advice.AdviceDate {
  3435. //查询审核是否允许
  3436. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3437. //申请状态不允许的情况 拒绝修改
  3438. if infor.ApplicationStatus != 1 {
  3439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3440. return
  3441. }
  3442. }
  3443. }
  3444. err := service.UpdateDoctorAdvice(&advice)
  3445. //记录日志
  3446. byterequest, _ := json.Marshal(advice)
  3447. doctorAdviceLog := models.XtDoctorAdviceLog{
  3448. UserOrgId: advice.UserOrgId,
  3449. PatientId: advice.PatientId,
  3450. AdminUserId: adminUserInfo.AdminUser.Id,
  3451. Module: 1,
  3452. ErrLog: string(byterequest),
  3453. Status: 1,
  3454. Ctime: time.Now().Unix(),
  3455. Mtime: 0,
  3456. Source: "电脑端修改医嘱",
  3457. RecordDate: advice.AdviceDate,
  3458. }
  3459. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3460. redis := service.RedisClient()
  3461. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3462. redis.Set(key, "", time.Second)
  3463. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3464. redis.Set(keyOne, "", time.Second)
  3465. defer redis.Close()
  3466. if err != nil {
  3467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3468. return
  3469. }
  3470. c.ServeSuccessJSON(map[string]interface{}{
  3471. "msg": "ok",
  3472. "advice": advice,
  3473. })
  3474. return
  3475. }
  3476. func (c *PatientApiController) StopGroupAdvice() {
  3477. groupNo, _ := c.GetInt64("groupno", 0)
  3478. if groupNo <= 0 {
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3480. return
  3481. }
  3482. adminUserInfo := c.GetAdminUserInfo()
  3483. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3484. if advice.ID == 0 {
  3485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3486. return
  3487. }
  3488. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3490. return
  3491. }
  3492. dataBody := make(map[string]interface{}, 0)
  3493. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3494. if err != nil {
  3495. utils.ErrorLog(err.Error())
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3497. return
  3498. }
  3499. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3500. utils.ErrorLog("stop_time")
  3501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3502. return
  3503. }
  3504. stopTime, _ := dataBody["stop_time"].(string)
  3505. if len(stopTime) == 0 {
  3506. utils.ErrorLog("len(stop_time) == 0")
  3507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3508. return
  3509. }
  3510. timeLayout := "2006-01-02"
  3511. loc, _ := time.LoadLocation("Local")
  3512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3513. if err != nil {
  3514. utils.ErrorLog(err.Error())
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3516. return
  3517. }
  3518. advice.StopTime = theTime.Unix()
  3519. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3520. stopReason, _ := dataBody["stop_reason"].(string)
  3521. advice.StopReason = stopReason
  3522. }
  3523. advice.UpdatedTime = time.Now().Unix()
  3524. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3525. advice.StopState = 1
  3526. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  3527. if err != nil {
  3528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3529. return
  3530. }
  3531. c.ServeSuccessJSON(map[string]interface{}{
  3532. "msg": "ok",
  3533. })
  3534. return
  3535. }
  3536. func (c *PatientApiController) StopDoctorAdvice() {
  3537. id, _ := c.GetInt64("id", 0)
  3538. if id <= 0 {
  3539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3540. return
  3541. }
  3542. adminUserInfo := c.GetAdminUserInfo()
  3543. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3544. //
  3545. //if appRole.UserType == 3 {
  3546. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3547. // if getPermissionErr != nil {
  3548. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3549. // return
  3550. // } else if headNursePermission == nil {
  3551. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3552. // return
  3553. // }
  3554. //}
  3555. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3556. if advice.ID == 0 {
  3557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3558. return
  3559. }
  3560. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3562. return
  3563. }
  3564. dataBody := make(map[string]interface{}, 0)
  3565. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3566. if err != nil {
  3567. utils.ErrorLog(err.Error())
  3568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3569. return
  3570. }
  3571. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3572. utils.ErrorLog("stop_time")
  3573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3574. return
  3575. }
  3576. stopTime, _ := dataBody["stop_time"].(string)
  3577. if len(stopTime) == 0 {
  3578. utils.ErrorLog("len(stop_time) == 0")
  3579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3580. return
  3581. }
  3582. timeLayout := "2006-01-02"
  3583. loc, _ := time.LoadLocation("Local")
  3584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3585. if err != nil {
  3586. utils.ErrorLog(err.Error())
  3587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3588. return
  3589. }
  3590. advice.StopTime = theTime.Unix()
  3591. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3592. stopReason, _ := dataBody["stop_reason"].(string)
  3593. advice.StopReason = stopReason
  3594. }
  3595. advice.UpdatedTime = time.Now().Unix()
  3596. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3597. advice.StopState = 1
  3598. err = service.StopDoctorAdvice(&advice)
  3599. if err != nil {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3601. return
  3602. }
  3603. c.ServeSuccessJSON(map[string]interface{}{
  3604. "msg": "ok",
  3605. "advice": advice,
  3606. })
  3607. return
  3608. }
  3609. func (c *PatientApiController) DeleteDoctorAdvice() {
  3610. id, _ := c.GetInt64("id", 0)
  3611. if id <= 0 {
  3612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3613. return
  3614. }
  3615. adminUserInfo := c.GetAdminUserInfo()
  3616. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3617. if advice.ID == 0 {
  3618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3619. return
  3620. }
  3621. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3622. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3623. // return
  3624. //}
  3625. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3626. //
  3627. //if appRole.UserType == 3 {
  3628. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3629. // if getPermissionErr != nil {
  3630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3631. // return
  3632. // } else if headNursePermission == nil {
  3633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3634. // return
  3635. // }
  3636. //}
  3637. advice.UpdatedTime = time.Now().Unix()
  3638. advice.Status = 0
  3639. advice.Modifier = adminUserInfo.AdminUser.Id
  3640. // 查询信息规挡的设置天数
  3641. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3642. if infor.ID > 0 && infor.WeekDay > 0 {
  3643. var cha_time int64
  3644. timeNowStr := time.Now().Format("2006-01-02")
  3645. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3646. //今日的日期减去设置的日期
  3647. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3648. if cha_time >= advice.AdviceDate {
  3649. //查询审核是否允许
  3650. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3651. //申请状态不允许的情况 拒绝修改
  3652. if infor.ApplicationStatus != 1 {
  3653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3654. return
  3655. }
  3656. }
  3657. }
  3658. //自备药
  3659. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3660. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3661. //查询库存是否是自备药
  3662. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3663. if selfBasedrug.IsSelfDrug == 1 {
  3664. creater := adminUserInfo.AdminUser.Id
  3665. //退库
  3666. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3667. }
  3668. }
  3669. err := service.DeleteDoctorAdvice(&advice)
  3670. //记录日志
  3671. byterequest, _ := json.Marshal(advice)
  3672. doctorAdviceLog := models.XtDoctorAdviceLog{
  3673. UserOrgId: advice.UserOrgId,
  3674. PatientId: advice.PatientId,
  3675. AdminUserId: adminUserInfo.AdminUser.Id,
  3676. Module: 4,
  3677. ErrLog: string(byterequest),
  3678. Status: 1,
  3679. Ctime: time.Now().Unix(),
  3680. Mtime: 0,
  3681. Source: "电脑端删除医嘱",
  3682. RecordDate: advice.RecordDate,
  3683. }
  3684. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3685. redis := service.RedisClient()
  3686. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3687. redis.Set(keyOne, "", time.Second)
  3688. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3689. redis.Set(key, "", time.Second)
  3690. redis.Close()
  3691. if err != nil {
  3692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3693. return
  3694. }
  3695. c.ServeSuccessJSON(map[string]interface{}{
  3696. "msg": "ok",
  3697. })
  3698. return
  3699. }
  3700. func (c *PatientApiController) DeleteGroupAdvice() {
  3701. groupNo, _ := c.GetInt64("groupno", 0)
  3702. if groupNo <= 0 {
  3703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3704. return
  3705. }
  3706. adminUserInfo := c.GetAdminUserInfo()
  3707. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3708. if advice.ID == 0 {
  3709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3710. return
  3711. }
  3712. //自备药
  3713. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3714. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3715. //查询库存是否是自备药
  3716. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3717. if selfBasedrug.IsSelfDrug == 1 {
  3718. creater := adminUserInfo.AdminUser.Id
  3719. //退库
  3720. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3721. }
  3722. }
  3723. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3724. //if appRole.UserType == 3 {
  3725. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3726. // if getPermissionErr != nil {
  3727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3728. // return
  3729. // } else if headNursePermission == nil {
  3730. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3731. // return
  3732. // }
  3733. //}
  3734. // 查询信息规挡的设置天数
  3735. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3736. if infor.ID > 0 && infor.WeekDay > 0 {
  3737. var cha_time int64
  3738. timeNowStr := time.Now().Format("2006-01-02")
  3739. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3740. //今日的日期减去设置的日期
  3741. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3742. if cha_time >= advice.AdviceDate {
  3743. //查询审核是否允许
  3744. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3745. //申请状态不允许的情况 拒绝修改
  3746. if infor.ApplicationStatus != 1 {
  3747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3748. return
  3749. }
  3750. }
  3751. }
  3752. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3753. byterequest, _ := json.Marshal(advice)
  3754. doctorAdviceLog := models.XtDoctorAdviceLog{
  3755. UserOrgId: advice.UserOrgId,
  3756. PatientId: advice.PatientId,
  3757. AdminUserId: adminUserInfo.AdminUser.Id,
  3758. Module: 4,
  3759. ErrLog: string(byterequest),
  3760. Status: 1,
  3761. Ctime: time.Now().Unix(),
  3762. Mtime: 0,
  3763. Source: "电脑端批量删除医嘱",
  3764. RecordDate: advice.RecordDate,
  3765. }
  3766. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3767. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3768. redis := service.RedisClient()
  3769. redis.Set(key, "", time.Second)
  3770. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3771. redis.Set(keyOne, "", time.Second)
  3772. defer redis.Close()
  3773. if err != nil {
  3774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3775. return
  3776. }
  3777. c.ServeSuccessJSON(map[string]interface{}{
  3778. "msg": "ok",
  3779. })
  3780. return
  3781. }
  3782. // GetDoctorAdvices 医嘱列表
  3783. func (c *PatientApiController) GetDoctorAdvices() {
  3784. id, _ := c.GetInt64("id", 0)
  3785. adviceType, _ := c.GetInt64("advice_type", 0)
  3786. stopType, _ := c.GetInt64("stop_state", 0)
  3787. startTime := c.GetString("start_time", "")
  3788. endTime := c.GetString("end_time", "")
  3789. keywords := c.GetString("keywords", "")
  3790. page, _ := c.GetInt64("page")
  3791. fmt.Println("page", page)
  3792. limit, _ := c.GetInt64("limit")
  3793. fmt.Println("limit", limit)
  3794. adminUserInfo := c.GetAdminUserInfo()
  3795. operatorIDs := make([]int64, 0)
  3796. timeLayout := "2006-01-02"
  3797. loc, _ := time.LoadLocation("Local")
  3798. var theStartTIme int64
  3799. if len(startTime) > 0 {
  3800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3801. if err != nil {
  3802. utils.ErrorLog(err.Error())
  3803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3804. return
  3805. }
  3806. theStartTIme = theTime.Unix()
  3807. }
  3808. var theEndtTIme int64
  3809. if len(endTime) > 0 {
  3810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3811. if err != nil {
  3812. utils.ErrorLog(err.Error())
  3813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3814. return
  3815. }
  3816. theEndtTIme = theTime.Unix()
  3817. }
  3818. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3819. if hisconfig.IsOpen == 1 {
  3820. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3821. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3822. if len(advices) > 0 {
  3823. for _, item := range advices {
  3824. if item.AdviceDoctor > 0 {
  3825. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3826. }
  3827. if item.ExecutionStaff > 0 {
  3828. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3829. }
  3830. if item.Checker > 0 {
  3831. operatorIDs = append(operatorIDs, item.Checker)
  3832. }
  3833. if item.StopDoctor > 0 {
  3834. operatorIDs = append(operatorIDs, item.StopDoctor)
  3835. }
  3836. }
  3837. }
  3838. //相关操作对应的操作人
  3839. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3840. //获取长期医嘱
  3841. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3842. c.ServeSuccessJSON(map[string]interface{}{
  3843. "advices": advices,
  3844. "operators": operators,
  3845. "total": total,
  3846. "advicetwo": advicestwo,
  3847. "longAdvice": longAdvice,
  3848. "is_open": hisconfig.IsOpen,
  3849. })
  3850. return
  3851. } else {
  3852. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3853. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3854. if len(advices) > 0 {
  3855. for _, item := range advices {
  3856. if item.AdviceDoctor > 0 {
  3857. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3858. }
  3859. if item.ExecutionStaff > 0 {
  3860. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3861. }
  3862. if item.Checker > 0 {
  3863. operatorIDs = append(operatorIDs, item.Checker)
  3864. }
  3865. if item.StopDoctor > 0 {
  3866. operatorIDs = append(operatorIDs, item.StopDoctor)
  3867. }
  3868. }
  3869. }
  3870. //相关操作对应的操作人
  3871. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3872. c.ServeSuccessJSON(map[string]interface{}{
  3873. "advices": advices,
  3874. "operators": operators,
  3875. "total": total,
  3876. "advicetwo": advicestwo,
  3877. "is_open": hisconfig.IsOpen,
  3878. })
  3879. return
  3880. }
  3881. }
  3882. func (c *PatientApiController) GetPatientSchedules() {
  3883. id, _ := c.GetInt64("id", 0)
  3884. if id <= 0 {
  3885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3886. return
  3887. }
  3888. adminUserInfo := c.GetAdminUserInfo()
  3889. todayTime := time.Now().Format("2006-01-02")
  3890. timeLayout := "2006-01-02 15:04:05"
  3891. loc, _ := time.LoadLocation("Local")
  3892. var theStartTime int64
  3893. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3894. theStartTime = theTime.Unix()
  3895. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3896. if len(schedules) > 0 {
  3897. for index, item := range schedules {
  3898. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3899. schedules[index].Week = int64(week)
  3900. }
  3901. }
  3902. c.ServeSuccessJSON(map[string]interface{}{
  3903. "schedules": schedules,
  3904. })
  3905. return
  3906. }
  3907. func (c *PatientApiController) GetPatientDialysisRecords() {
  3908. patientID, _ := c.GetInt64("patient_id", 0)
  3909. page, _ := c.GetInt64("page", 0)
  3910. limit, _ := c.GetInt64("limit", 0)
  3911. startTime := c.GetString("start_time", "")
  3912. endTime := c.GetString("end_time", "")
  3913. mode_id, _ := c.GetInt64("mode_id", 0)
  3914. if page <= 0 {
  3915. page = 1
  3916. }
  3917. if limit <= 0 {
  3918. limit = 10
  3919. }
  3920. if patientID <= 0 {
  3921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3922. return
  3923. }
  3924. timeLayout := "2006-01-02"
  3925. loc, _ := time.LoadLocation("Local")
  3926. var theStartTIme int64
  3927. if len(startTime) > 0 {
  3928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3929. if err != nil {
  3930. theStartTIme = 0
  3931. }
  3932. theStartTIme = theTime.Unix()
  3933. }
  3934. var theEndtTIme int64
  3935. if len(endTime) > 0 {
  3936. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3937. if err != nil {
  3938. theEndtTIme = 0
  3939. }
  3940. theEndtTIme = theTime.Unix()
  3941. }
  3942. adminInfo := c.GetAdminUserInfo()
  3943. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3944. if len(records) == 0 {
  3945. list, _ := service.GetAllDialysisOrder(patientID)
  3946. for _, item := range list {
  3947. schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
  3948. service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
  3949. }
  3950. }
  3951. c.ServeSuccessJSON(map[string]interface{}{
  3952. "total": total,
  3953. "records": records,
  3954. })
  3955. return
  3956. }
  3957. func (c *PatientApiController) ProEducation() {
  3958. patientID, _ := c.GetInt64("patient_id", 0)
  3959. page, _ := c.GetInt64("page", 0)
  3960. limit, _ := c.GetInt64("limit", 0)
  3961. startTime := c.GetString("start_time", "")
  3962. endTime := c.GetString("end_time", "")
  3963. if page <= 0 {
  3964. page = 1
  3965. }
  3966. if limit <= 0 {
  3967. limit = 10
  3968. }
  3969. if patientID <= 0 {
  3970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3971. return
  3972. }
  3973. timeLayout := "2006-01-02"
  3974. loc, _ := time.LoadLocation("Local")
  3975. var theStartTIme int64
  3976. if len(startTime) > 0 {
  3977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3978. if err != nil {
  3979. theStartTIme = 0
  3980. }
  3981. theStartTIme = theTime.Unix()
  3982. }
  3983. var theEndtTIme int64
  3984. if len(endTime) > 0 {
  3985. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3986. if err != nil {
  3987. theEndtTIme = 0
  3988. }
  3989. theEndtTIme = theTime.Unix()
  3990. }
  3991. adminInfo := c.GetAdminUserInfo()
  3992. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3993. c.ServeSuccessJSON(map[string]interface{}{
  3994. "total": total,
  3995. "edus": edus,
  3996. })
  3997. return
  3998. }
  3999. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4000. dataBody := make(map[string]interface{}, 0)
  4001. err := json.Unmarshal(data, &dataBody)
  4002. if err != nil {
  4003. utils.ErrorLog(err.Error())
  4004. code = enums.ErrorCodeParamWrong
  4005. return
  4006. }
  4007. timeLayout := "2006-01-02"
  4008. loc, _ := time.LoadLocation("Local")
  4009. isChild := false
  4010. if action == "create" {
  4011. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4012. utils.ErrorLog("advice_type")
  4013. code = enums.ErrorCodeParamWrong
  4014. return
  4015. }
  4016. adviceType := int64(dataBody["advice_type"].(float64))
  4017. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  4018. utils.ErrorLog("advice_type != 1&&2")
  4019. code = enums.ErrorCodeParamWrong
  4020. return
  4021. }
  4022. advice.AdviceType = adviceType
  4023. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4024. utils.ErrorLog("advice_date")
  4025. code = enums.ErrorCodeParamWrong
  4026. return
  4027. }
  4028. adviceDate, _ := dataBody["advice_date"].(string)
  4029. if len(adviceDate) == 0 {
  4030. utils.ErrorLog("len(adviceDate) == 0")
  4031. code = enums.ErrorCodeParamWrong
  4032. return
  4033. }
  4034. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4035. if err != nil {
  4036. utils.ErrorLog(err.Error())
  4037. code = enums.ErrorCodeParamWrong
  4038. return
  4039. }
  4040. advice.AdviceDate = theTime.Unix()
  4041. advice.RecordDate = theTime.Unix()
  4042. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4043. parentId := int64(dataBody["parent_id"].(float64))
  4044. advice.ParentId = parentId
  4045. if parentId > 0 {
  4046. isChild = true
  4047. }
  4048. }
  4049. }
  4050. if !isChild {
  4051. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4052. utils.ErrorLog("start_time")
  4053. code = enums.ErrorCodeParamWrong
  4054. return
  4055. }
  4056. startTime, _ := dataBody["start_time"].(string)
  4057. if len(startTime) == 0 {
  4058. utils.ErrorLog("len(start_time) == 0")
  4059. code = enums.ErrorCodeParamWrong
  4060. return
  4061. }
  4062. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  4063. if err != nil {
  4064. utils.ErrorLog(err.Error())
  4065. code = enums.ErrorCodeParamWrong
  4066. return
  4067. }
  4068. advice.StartTime = theTime.Unix()
  4069. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  4070. // utils.ErrorLog("advice_doctor")
  4071. // code = enums.ErrorCodeParamWrong
  4072. // return
  4073. // }
  4074. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  4075. // if adviceDoctor <= 0 {
  4076. // utils.ErrorLog("advice_doctor <=0")
  4077. // code = enums.ErrorCodeParamWrong
  4078. // return
  4079. // }
  4080. // advice.AdviceDoctor = adviceDoctor
  4081. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4082. deliveryWay, _ := dataBody["delivery_way"].(string)
  4083. advice.DeliveryWay = deliveryWay
  4084. }
  4085. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4086. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4087. advice.ExecutionFrequency = executionFrequency
  4088. }
  4089. if advice.AdviceType == 1 && advice.ParentId == 0 {
  4090. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  4091. frequency_type := int64(dataBody["frequency_type"].(float64))
  4092. advice.FrequencyType = frequency_type
  4093. }
  4094. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  4095. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  4096. advice.DayCount = day_count
  4097. }
  4098. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  4099. week_day, _ := dataBody["week_days"].(string)
  4100. advice.WeekDay = week_day
  4101. }
  4102. }
  4103. }
  4104. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4105. utils.ErrorLog("advice_name")
  4106. code = enums.ErrorCodeParamWrong
  4107. return
  4108. }
  4109. adviceName, _ := dataBody["advice_name"].(string)
  4110. if len(adviceName) == 0 {
  4111. utils.ErrorLog("len(advice_name) == 0")
  4112. code = enums.ErrorCodeParamWrong
  4113. return
  4114. }
  4115. advice.AdviceName = adviceName
  4116. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4117. adviceDsc, _ := dataBody["advice_desc"].(string)
  4118. advice.AdviceDesc = adviceDsc
  4119. }
  4120. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  4121. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  4122. advice.DialysisOrderId = int64(dialysisOrderId)
  4123. }
  4124. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4125. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4126. advice.SingleDose = singleDose
  4127. }
  4128. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  4129. singleDose := dataBody["single_dose"].(float64)
  4130. advice.SingleDose = singleDose
  4131. }
  4132. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4133. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4134. advice.SingleDoseUnit = singleDoseUnit
  4135. }
  4136. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  4137. tmp := dataBody["single_dose_unit"].(float64)
  4138. singleDoseUnit := service.TypeConversion(tmp)
  4139. advice.SingleDoseUnit = singleDoseUnit
  4140. }
  4141. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4142. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4143. advice.DrugSpec = drugSpec
  4144. }
  4145. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4146. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4147. advice.DrugSpecUnit = drugSpecUnit
  4148. }
  4149. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4150. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4151. advice.PrescribingNumber = prescribingNumber
  4152. }
  4153. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  4154. prescribingNumber := dataBody["prescribing_number"].(float64)
  4155. advice.PrescribingNumber = prescribingNumber
  4156. }
  4157. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4158. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4159. advice.PrescribingNumberUnit = prescribingNumberUnit
  4160. }
  4161. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4162. remark, _ := dataBody["remark"].(string)
  4163. advice.Remark = remark
  4164. }
  4165. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  4166. drug_id, _ := dataBody["drug_id"].(string)
  4167. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  4168. advice.DrugId = tmpDrugId
  4169. }
  4170. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4171. drug_id, _ := dataBody["drug_id"].(float64)
  4172. advice.DrugId = int64(drug_id)
  4173. }
  4174. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4175. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  4176. advice.DrugNameId = int64(drug_name_id)
  4177. }
  4178. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4179. way, _ := dataBody["way"].(float64)
  4180. advice.Way = int64(way)
  4181. }
  4182. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  4183. push_start_time, _ := dataBody["push_start_time"].(string)
  4184. var startTime int64
  4185. if len(push_start_time) > 0 {
  4186. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  4187. startTime = theTime.Unix()
  4188. }
  4189. advice.PushStartTime = startTime
  4190. }
  4191. return
  4192. }
  4193. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  4194. dataBody := make(map[string]interface{}, 0)
  4195. err := json.Unmarshal(data, &dataBody)
  4196. utils.InfoLog(string(data))
  4197. if err != nil {
  4198. utils.ErrorLog(err.Error())
  4199. code = enums.ErrorCodeParamWrong
  4200. return
  4201. }
  4202. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4203. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4204. solution.DialysisDuration = dialysisDuration
  4205. }
  4206. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4207. replacementWay := int64(dataBody["replacement_way"].(float64))
  4208. solution.ReplacementWay = replacementWay
  4209. }
  4210. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4211. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4212. solution.BloodFlowVolume = bloodFlowVolume
  4213. }
  4214. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4215. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4216. solution.HemodialysisMachine = hemodialysisMachine
  4217. }
  4218. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  4219. bloodFilter := int64(dataBody["blood_filter"].(float64))
  4220. solution.BloodFilter = bloodFilter
  4221. }
  4222. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4223. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4224. solution.PerfusionApparatus = perfusionApparatus
  4225. }
  4226. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4227. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4228. solution.DialysateFlow = dialysateFlow
  4229. }
  4230. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4231. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4232. solution.Kalium = kalium
  4233. }
  4234. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4235. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4236. solution.Sodium = sodium
  4237. }
  4238. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4239. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4240. solution.Calcium = calcium
  4241. }
  4242. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4243. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4244. solution.Bicarbonate = bicarbonate
  4245. }
  4246. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4247. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4248. solution.Anticoagulant = anticoagulant
  4249. }
  4250. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4251. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4252. solution.AnticoagulantShouji = anticoagulantShouji
  4253. }
  4254. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4255. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4256. solution.AnticoagulantWeichi = anticoagulantWeichi
  4257. }
  4258. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4259. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4260. solution.AnticoagulantZongliang = anticoagulantZongliang
  4261. }
  4262. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4263. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4264. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4265. }
  4266. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4267. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4268. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4269. }
  4270. return
  4271. }
  4272. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4273. dataBody := make(map[string]interface{}, 0)
  4274. err := json.Unmarshal(data, &dataBody)
  4275. utils.InfoLog(string(data))
  4276. if err != nil {
  4277. utils.ErrorLog(err.Error())
  4278. code = enums.ErrorCodeParamWrong
  4279. return
  4280. }
  4281. if method == "create" {
  4282. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  4283. utils.ErrorLog("mode")
  4284. code = enums.ErrorCodeParamWrong
  4285. return
  4286. }
  4287. mode := int64(dataBody["mode"].(float64))
  4288. if mode <= 0 {
  4289. utils.ErrorLog("mode <= 0")
  4290. code = enums.ErrorCodeParamWrong
  4291. return
  4292. }
  4293. solution.ModeId = mode
  4294. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  4295. utils.ErrorLog("mode_name")
  4296. code = enums.ErrorCodeParamWrong
  4297. return
  4298. }
  4299. modeName, _ := dataBody["mode_name"].(string)
  4300. if len(modeName) == 0 {
  4301. utils.ErrorLog("len(mode_name) == 0")
  4302. code = enums.ErrorCodeParamWrong
  4303. return
  4304. }
  4305. solution.ModeName = modeName
  4306. solution.Name = modeName
  4307. }
  4308. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4309. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4310. solution.DialysisDuration = dialysisDuration
  4311. }
  4312. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4313. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4314. solution.TargetUltrafiltration = targetUltrafiltration
  4315. }
  4316. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4317. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  4318. solution.DialysateFormulation = dialysateFormulation
  4319. }
  4320. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4321. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  4322. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4323. }
  4324. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4325. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  4326. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4327. }
  4328. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4329. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4330. solution.HemodialysisMachine = hemodialysisMachine
  4331. }
  4332. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  4333. dialyzer := int64(dataBody["dialyzer"].(float64))
  4334. solution.Dialyzer = dialyzer
  4335. }
  4336. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4337. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4338. solution.PerfusionApparatus = perfusionApparatus
  4339. }
  4340. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4341. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4342. solution.BloodFlowVolume = bloodFlowVolume
  4343. }
  4344. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  4345. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  4346. solution.Dewater = dewater
  4347. }
  4348. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  4349. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  4350. solution.DisplaceLiqui = displaceLiqui
  4351. }
  4352. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4353. replacementWay := int64(dataBody["replacement_way"].(float64))
  4354. solution.ReplacementWay = replacementWay
  4355. }
  4356. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4357. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4358. solution.Anticoagulant = anticoagulant
  4359. }
  4360. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4361. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4362. solution.AnticoagulantShouji = anticoagulantShouji
  4363. }
  4364. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4365. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4366. solution.AnticoagulantWeichi = anticoagulantWeichi
  4367. }
  4368. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4369. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4370. solution.AnticoagulantZongliang = anticoagulantZongliang
  4371. }
  4372. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4373. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4374. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4375. }
  4376. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4377. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4378. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4379. }
  4380. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4381. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4382. solution.Kalium = kalium
  4383. }
  4384. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4385. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4386. solution.Sodium = sodium
  4387. }
  4388. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4389. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4390. solution.Calcium = calcium
  4391. }
  4392. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4393. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4394. solution.Bicarbonate = bicarbonate
  4395. }
  4396. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4397. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4398. solution.Glucose = glucose
  4399. }
  4400. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4401. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4402. // solution.DryWeight = dryWeight
  4403. // }
  4404. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4405. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4406. solution.DialysateFlow = dialysateFlow
  4407. }
  4408. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4409. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4410. solution.DialysateTemperature = dialysateTemperature
  4411. }
  4412. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4413. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4414. solution.Conductivity = conductivity
  4415. }
  4416. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  4417. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  4418. solution.ReplacementTotal = replacementTotal
  4419. }
  4420. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  4421. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  4422. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  4423. }
  4424. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  4425. body_fluid := int64(dataBody["body_fluid"].(float64))
  4426. solution.BodyFluid = body_fluid
  4427. }
  4428. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  4429. body_fluid_other := dataBody["body_fluid_other"].(string)
  4430. solution.BodyFluidOther = body_fluid_other
  4431. }
  4432. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  4433. special_medicine := int64(dataBody["special_medicine"].(float64))
  4434. solution.SpecialMedicine = special_medicine
  4435. }
  4436. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  4437. special_medicine_other := dataBody["special_medicine_other"].(string)
  4438. solution.SpecialMedicineOther = special_medicine_other
  4439. }
  4440. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  4441. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  4442. solution.DisplaceLiquiPart = displace_liqui_part
  4443. }
  4444. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  4445. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  4446. solution.DisplaceLiquiValue = displace_liqui_value
  4447. }
  4448. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  4449. blood_access := int64(dataBody["blood_access"].(float64))
  4450. solution.BloodAccess = blood_access
  4451. }
  4452. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  4453. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  4454. solution.Ultrafiltration = ultrafiltration
  4455. }
  4456. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  4457. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  4458. solution.TargetKtv = target_ktv
  4459. }
  4460. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4461. remark := dataBody["remark"].(string)
  4462. solution.Remark = remark
  4463. }
  4464. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  4465. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  4466. solution.HemodialysisPipelines = hemodialysis_pipelines
  4467. }
  4468. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  4469. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  4470. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  4471. }
  4472. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4473. puncture_needle := dataBody["puncture_needle"].(string)
  4474. solution.PunctureNeedle = puncture_needle
  4475. }
  4476. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  4477. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  4478. solution.PunctureNeedleCount = puncture_needle_count
  4479. }
  4480. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  4481. epo := dataBody["epo"].(string)
  4482. solution.Epo = epo
  4483. }
  4484. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  4485. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  4486. solution.EpoCount = epo_count
  4487. }
  4488. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  4489. created_time := int64(dataBody["created_time"].(float64))
  4490. solution.CreatedTime = created_time
  4491. }
  4492. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  4493. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  4494. solution.DialysisDialyszers = dialysisDialyszers
  4495. }
  4496. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  4497. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  4498. solution.DialysisIrrigation = dialysisIrrigation
  4499. }
  4500. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  4501. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  4502. solution.DialysisStrainer = dialysis_strainer
  4503. }
  4504. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  4505. plasmaSeparator := dataBody["plasma_separator"].(string)
  4506. solution.PlasmaSeparator = plasmaSeparator
  4507. }
  4508. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  4509. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  4510. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  4511. }
  4512. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  4513. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  4514. solution.OxygenUptake = oxygen_uptake
  4515. }
  4516. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  4517. oxygen_flow := dataBody["oxygen_flow"].(string)
  4518. solution.OxygenFlow = oxygen_flow
  4519. }
  4520. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  4521. oxygen_time := dataBody["oxygen_time"].(string)
  4522. solution.OxygenTime = oxygen_time
  4523. }
  4524. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  4525. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  4526. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  4527. }
  4528. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  4529. amylaceum := dataBody["amylaceum"].(string)
  4530. solution.Amylaceum = amylaceum
  4531. }
  4532. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  4533. chaptalization := dataBody["chaptalization"].(string)
  4534. solution.Chaptalization = chaptalization
  4535. }
  4536. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4537. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4538. solution.BloodAccessPartId = blood_access_part_id
  4539. }
  4540. return
  4541. }
  4542. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4543. dataBody := make(map[string]interface{}, 0)
  4544. err := json.Unmarshal(data, &dataBody)
  4545. utils.InfoLog(string(data))
  4546. if err != nil {
  4547. utils.ErrorLog(err.Error())
  4548. code = enums.ErrorCodeParamWrong
  4549. return
  4550. }
  4551. if method == "create" {
  4552. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  4553. utils.ErrorLog("parent_id")
  4554. code = enums.ErrorCodeParamWrong
  4555. return
  4556. }
  4557. parentID := int64(dataBody["parent_id"].(float64))
  4558. if parentID <= 0 {
  4559. utils.ErrorLog("parentID <= 0")
  4560. code = enums.ErrorCodeParamWrong
  4561. return
  4562. }
  4563. solution.ParentId = parentID
  4564. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  4565. utils.ErrorLog("sub_name")
  4566. code = enums.ErrorCodeParamWrong
  4567. return
  4568. }
  4569. subName, _ := dataBody["sub_name"].(string)
  4570. if len(subName) == 0 {
  4571. utils.ErrorLog("len(sub_name) == 0")
  4572. code = enums.ErrorCodeParamWrong
  4573. return
  4574. }
  4575. solution.SubName = subName
  4576. }
  4577. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4578. utils.ErrorLog("initiate_mode")
  4579. code = enums.ErrorCodeParamWrong
  4580. return
  4581. }
  4582. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4583. if initiateMode != 1 && initiateMode != 2 {
  4584. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4585. code = enums.ErrorCodeParamWrong
  4586. return
  4587. }
  4588. solution.InitiateMode = initiateMode
  4589. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4590. utils.ErrorLog("doctor")
  4591. code = enums.ErrorCodeParamWrong
  4592. return
  4593. }
  4594. doctor := int64(dataBody["doctor"].(float64))
  4595. if doctor <= 0 {
  4596. utils.ErrorLog("doctor <= 0")
  4597. code = enums.ErrorCodeParamWrong
  4598. return
  4599. }
  4600. solution.Doctor = doctor
  4601. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4602. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4603. solution.BloodAccessPartId = blood_access_part_id
  4604. }
  4605. return
  4606. }
  4607. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4608. patientBody := make(map[string]interface{}, 0)
  4609. err := json.Unmarshal(data, &patientBody)
  4610. if err != nil {
  4611. utils.ErrorLog(err.Error())
  4612. code = enums.ErrorCodeParamWrong
  4613. return
  4614. }
  4615. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4616. formItem, _ := patientBody["formItem"].([]interface{})
  4617. if len(formItem) > 0 {
  4618. for _, item := range formItem {
  4619. items := item.(map[string]interface{})
  4620. project_name, _ := items["project_name"].(string)
  4621. fmt.Println(project_name)
  4622. range_type := int64(items["range_type"].(float64))
  4623. fmt.Println(range_type)
  4624. project_id := int64(items["project_id"].(float64))
  4625. fmt.Println(project_id)
  4626. item_id := int64(items["item_id"].(float64))
  4627. fmt.Println(item_id)
  4628. item, _ := items["item"].(string)
  4629. fmt.Println(items["item"].(string))
  4630. item_name, _ := items["item_name"].(string)
  4631. fmt.Println(item_name)
  4632. value, _ := items["value"].(string)
  4633. fmt.Println(items["value"].(string))
  4634. var form models.FormItem
  4635. form.ProjectName = project_name
  4636. form.RangeType = range_type
  4637. form.ProjectId = project_id
  4638. form.ItemId = item_id
  4639. form.Item = item
  4640. form.ItemName = item_name
  4641. form.Value = value
  4642. formItems = append(formItems, &form)
  4643. }
  4644. }
  4645. }
  4646. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4647. utils.ErrorLog("avatar")
  4648. code = enums.ErrorCodeParamWrong
  4649. return
  4650. }
  4651. avatar, _ := patientBody["avatar"].(string)
  4652. if len(avatar) == 0 {
  4653. utils.ErrorLog("len(avatar) == 0")
  4654. code = enums.ErrorCodeParamWrong
  4655. return
  4656. }
  4657. patient.Avatar = avatar
  4658. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4659. utils.ErrorLog("name")
  4660. code = enums.ErrorCodeParamWrong
  4661. return
  4662. }
  4663. name, _ := patientBody["name"].(string)
  4664. if len(name) == 0 {
  4665. utils.ErrorLog("len(name) == 0")
  4666. code = enums.ErrorCodeParamWrong
  4667. return
  4668. }
  4669. patient.Name = name
  4670. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4671. alias := patientBody["alias"].(string)
  4672. patient.Alias = alias
  4673. }
  4674. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4675. nation := patientBody["nation"].(string)
  4676. patient.Nation = nation
  4677. }
  4678. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4679. native_place := patientBody["native_place"].(string)
  4680. patient.NativePlace = native_place
  4681. }
  4682. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4683. utils.ErrorLog("idCardNo")
  4684. code = enums.ErrorCodeParamWrong
  4685. return
  4686. }
  4687. idCardNo, _ := patientBody["idCardNo"].(string)
  4688. if len(idCardNo) == 0 {
  4689. utils.ErrorLog("len(idCardNo) == 0")
  4690. code = enums.ErrorCodeParamWrong
  4691. return
  4692. }
  4693. patient.IdCardNo = idCardNo
  4694. patient.PatientType = 1
  4695. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4696. utils.ErrorLog("dialysisNo")
  4697. code = enums.ErrorCodeParamWrong
  4698. return
  4699. }
  4700. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4701. if len(dialysisNo) == 0 {
  4702. utils.ErrorLog("len(dialysisNo) == 0")
  4703. code = enums.ErrorCodeParamWrong
  4704. return
  4705. }
  4706. patient.DialysisNo = dialysisNo
  4707. // }
  4708. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4709. utils.ErrorLog("lapseto")
  4710. code = enums.ErrorCodeParamWrong
  4711. return
  4712. }
  4713. lapseto := int64(patientBody["lapseto"].(float64))
  4714. if lapseto <= 0 {
  4715. utils.ErrorLog("lapseto == 0")
  4716. code = enums.ErrorCodeParamWrong
  4717. return
  4718. }
  4719. patient.Lapseto = lapseto
  4720. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4721. utils.ErrorLog("gender")
  4722. code = enums.ErrorCodeParamWrong
  4723. return
  4724. }
  4725. gender := int64(patientBody["gender"].(float64))
  4726. if gender <= 0 {
  4727. utils.ErrorLog("gender <= 0")
  4728. code = enums.ErrorCodeParamWrong
  4729. return
  4730. }
  4731. patient.Gender = gender
  4732. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4733. response_result := patientBody["response_result"].(string)
  4734. patient.ResponseResult = response_result
  4735. }
  4736. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4737. utils.ErrorLog("age")
  4738. code = enums.ErrorCodeParamWrong
  4739. return
  4740. }
  4741. age := int64(patientBody["age"].(float64))
  4742. patient.Age = age
  4743. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4744. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4745. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4746. patient.UserSysBeforeCount = count
  4747. }
  4748. timeLayout := "2006-01-02"
  4749. loc, _ := time.LoadLocation("Local")
  4750. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4751. utils.ErrorLog("birth")
  4752. code = enums.ErrorCodeParamWrong
  4753. return
  4754. }
  4755. birth, _ := patientBody["birth"].(string)
  4756. if len(birth) == 0 {
  4757. utils.ErrorLog("len(birth) == 0")
  4758. code = enums.ErrorCodeParamWrong
  4759. return
  4760. }
  4761. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4762. if err != nil {
  4763. utils.ErrorLog("birthTime")
  4764. code = enums.ErrorCodeParamWrong
  4765. return
  4766. }
  4767. patient.Birthday = birthTime.Unix()
  4768. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4769. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4770. patient.Height = height
  4771. }
  4772. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4773. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4774. patient.MaritalStatus = maritalStatus
  4775. }
  4776. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4777. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4778. patient.Children = children
  4779. }
  4780. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4781. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4782. patient.AdmissionNumber = admissionNumber
  4783. }
  4784. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4785. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4786. patient.ReimbursementWayId = reimbursementWayID
  4787. }
  4788. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4789. healthCareNo := patientBody["healthCareNo"].(string)
  4790. patient.HealthCareNo = healthCareNo
  4791. }
  4792. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4793. utils.ErrorLog("phone")
  4794. code = enums.ErrorCodeParamWrong
  4795. return
  4796. }
  4797. phone := patientBody["phone"].(string)
  4798. if len(phone) == 0 {
  4799. utils.ErrorLog("len(phone) == 0")
  4800. code = enums.ErrorCodeParamWrong
  4801. return
  4802. }
  4803. if !utils.CheckMobile(phone) {
  4804. utils.ErrorLog("!phone")
  4805. code = enums.ErrorCodeMobileFormat
  4806. return
  4807. }
  4808. patient.Phone = phone
  4809. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4810. homeTelephone := patientBody["homeTelephone"].(string)
  4811. patient.HomeTelephone = homeTelephone
  4812. }
  4813. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4814. relativePhone := patientBody["relative_phone"].(string)
  4815. patient.RelativePhone = relativePhone
  4816. }
  4817. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4818. relativeRelations := patientBody["relative_relations"].(string)
  4819. patient.RelativeRelations = relativeRelations
  4820. }
  4821. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4822. homeAddress := patientBody["homeAddress"].(string)
  4823. patient.HomeAddress = homeAddress
  4824. }
  4825. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4826. work := patientBody["work"].(string)
  4827. patient.WorkUnit = work
  4828. }
  4829. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4830. unitAddress := patientBody["unit_address"].(string)
  4831. patient.UnitAddress = unitAddress
  4832. }
  4833. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4834. profession := int64(patientBody["profession"].(float64))
  4835. patient.Profession = profession
  4836. }
  4837. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4838. education := int64(patientBody["education"].(float64))
  4839. patient.EducationLevel = education
  4840. }
  4841. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4842. utils.ErrorLog("source")
  4843. code = enums.ErrorCodeParamWrong
  4844. return
  4845. }
  4846. source := int64(patientBody["source"].(float64))
  4847. if source <= 0 {
  4848. utils.ErrorLog("source <= 0")
  4849. code = enums.ErrorCodeParamWrong
  4850. return
  4851. }
  4852. patient.Source = source
  4853. zb_patient_id := patientBody["zb_patient_id"].(string)
  4854. patient.ZbPatientId = zb_patient_id
  4855. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4856. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4857. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4858. }
  4859. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4860. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4861. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4862. if err == nil {
  4863. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4864. }
  4865. }
  4866. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4867. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4868. patient.FirstDialysisHospital = firstDialysisHospital
  4869. }
  4870. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4871. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4872. if len(thePredialysisCondition) > 0 {
  4873. conditions := make([]string, 0)
  4874. for _, item := range thePredialysisCondition {
  4875. if reflect.TypeOf(item).String() != "string" {
  4876. continue
  4877. }
  4878. condition := item.(string)
  4879. if len(condition) > 0 {
  4880. conditions = append(conditions, condition)
  4881. }
  4882. }
  4883. patient.PredialysisCondition = strings.Join(conditions, ",")
  4884. }
  4885. }
  4886. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4887. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4888. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4889. }
  4890. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4891. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4892. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4893. }
  4894. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4895. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4896. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4897. if err == nil {
  4898. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4899. }
  4900. }
  4901. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4902. partition := int64(patientBody["partition"].(float64))
  4903. patient.PartitionId = partition
  4904. }
  4905. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4906. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4907. patient.BedId = bed
  4908. }
  4909. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4910. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4911. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4912. if err == nil {
  4913. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4914. }
  4915. }
  4916. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4917. blood := int64(patientBody["blood"].(float64))
  4918. patient.BloodType = blood
  4919. }
  4920. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4921. rh := int64(patientBody["rh"].(float64))
  4922. patient.Rh = rh
  4923. }
  4924. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4925. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4926. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4927. if err == nil {
  4928. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4929. }
  4930. }
  4931. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4932. receivingDate := patientBody["receivingDate"].(string)
  4933. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4934. if err == nil {
  4935. patient.ReceivingDate = receivingDateTime.Unix()
  4936. }
  4937. }
  4938. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4939. induction := int64(patientBody["induction"].(float64))
  4940. patient.InductionPeriod = induction
  4941. }
  4942. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4943. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4944. patient.InitialDialysis = initial
  4945. }
  4946. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4947. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4948. patient.TotalDialysis = dialysisTotal
  4949. }
  4950. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4951. thisContagions, _ := patientBody["contagions"].([]interface{})
  4952. if len(thisContagions) > 0 {
  4953. for _, item := range thisContagions {
  4954. if reflect.TypeOf(item).String() != "float64" {
  4955. continue
  4956. }
  4957. contagion := int64(item.(float64))
  4958. if contagion > 0 {
  4959. contagions = append(contagions, contagion)
  4960. }
  4961. }
  4962. }
  4963. }
  4964. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4965. doctor := int64(patientBody["doctor"].(float64))
  4966. patient.AttendingDoctorId = doctor
  4967. }
  4968. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4969. nurse := int64(patientBody["nurse"].(float64))
  4970. patient.HeadNurseId = nurse
  4971. }
  4972. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4973. assessment := patientBody["assessment"].(string)
  4974. patient.Evaluate = assessment
  4975. }
  4976. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4977. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4978. if len(thisDiseases) > 0 {
  4979. for _, item := range thisDiseases {
  4980. if reflect.TypeOf(item).String() != "float64" {
  4981. continue
  4982. }
  4983. disease := int64(item.(float64))
  4984. if disease > 0 {
  4985. diseases = append(diseases, disease)
  4986. }
  4987. }
  4988. }
  4989. }
  4990. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4991. diagnose := patientBody["diagnose"].(string)
  4992. patient.Diagnose = diagnose
  4993. }
  4994. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4995. remark := patientBody["remark"].(string)
  4996. patient.Remark = remark
  4997. }
  4998. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4999. sch_remark := patientBody["sch_remark"].(string)
  5000. patient.SchRemark = sch_remark
  5001. }
  5002. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  5003. patient_complains := patientBody["patient_complains"].(string)
  5004. patient.PatientComplains = patient_complains
  5005. }
  5006. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  5007. present_history := patientBody["present_history"].(string)
  5008. patient.PresentHistory = present_history
  5009. }
  5010. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  5011. past_history := patientBody["past_history"].(string)
  5012. patient.PastHistory = past_history
  5013. }
  5014. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  5015. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  5016. patient.Temperature = temperature
  5017. }
  5018. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  5019. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  5020. patient.Pulse = pulse
  5021. }
  5022. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  5023. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  5024. patient.Respiratory = respiratory
  5025. }
  5026. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  5027. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  5028. patient.SBP = sbp
  5029. }
  5030. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  5031. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  5032. patient.DBP = dbp
  5033. }
  5034. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  5035. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  5036. patient.DialysisAge = dialysis_age
  5037. }
  5038. fmt.Println(patient.DialysisAge)
  5039. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  5040. first_treatment_date := patientBody["first_treatment_date"].(string)
  5041. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5042. if err == nil {
  5043. patient.FirstTreatmentDate = first_treatment_time.Unix()
  5044. }
  5045. }
  5046. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  5047. expense_kind := int64(patientBody["expense_kind"].(float64))
  5048. patient.ExpenseKind = expense_kind
  5049. }
  5050. fmt.Println(patient.ExpenseKind)
  5051. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  5052. tell_phone := patientBody["tell_phone"].(string)
  5053. patient.TellPhone = tell_phone
  5054. }
  5055. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  5056. contact_name := patientBody["contact_name"].(string)
  5057. patient.ContactName = contact_name
  5058. }
  5059. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  5060. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  5061. patient.TrobleShoot = troble_shoot
  5062. }
  5063. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  5064. treatment_plan := patientBody["treatment_plan"].(string)
  5065. patient.TreatmentPlan = treatment_plan
  5066. }
  5067. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  5068. doctor := int64(patientBody["doctor"].(float64))
  5069. patient.Doctor = doctor
  5070. }
  5071. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  5072. record_number := patientBody["record_number"].(string)
  5073. patient.RecordNumber = record_number
  5074. }
  5075. patient_source := int64(patientBody["patient_source"].(float64))
  5076. if patient_source <= 0 {
  5077. utils.ErrorLog("patient_source <= 0")
  5078. code = enums.ErrorCodeParamWrong
  5079. return
  5080. }
  5081. patient.PatientSource = patient_source
  5082. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  5083. patient_start_time := patientBody["patient_start_time"].(string)
  5084. var startTime int64
  5085. if len(patient_start_time) > 0 {
  5086. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  5087. startTime = theTime.Unix()
  5088. }
  5089. patient.PatientStartTime = startTime
  5090. }
  5091. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  5092. patient_end_time := patientBody["patient_end_time"].(string)
  5093. var endTime int64
  5094. if len(patient_end_time) > 0 {
  5095. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  5096. endTime = theTime.Unix()
  5097. }
  5098. patient.PatientEndTime = endTime
  5099. }
  5100. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  5101. record_number := patientBody["infectious_remark"].(string)
  5102. patient.InfectiousRemark = record_number
  5103. }
  5104. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  5105. allergic_history := patientBody["allergic_history"].(string)
  5106. patient.AllergicHistory = allergic_history
  5107. }
  5108. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  5109. patient_address := patientBody["patient_address"].(string)
  5110. patient.PatientAddress = patient_address
  5111. }
  5112. if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
  5113. print_date := patientBody["print_date"].(string)
  5114. printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
  5115. if err == nil {
  5116. patient.PrintDate = printDateTime.Unix()
  5117. }
  5118. }
  5119. return
  5120. }
  5121. func (c *PatientApiController) GetPatientsByKeyWord() {
  5122. keyWord := c.GetString("keyword")
  5123. adminUserInfo := c.GetAdminUserInfo()
  5124. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  5125. if err != nil {
  5126. utils.ErrorLog(err.Error())
  5127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5128. return
  5129. }
  5130. c.ServeSuccessJSON(map[string]interface{}{
  5131. "patient": patient,
  5132. })
  5133. }
  5134. func (c *PatientApiController) QueryPatientById() {
  5135. id, _ := c.GetInt64("id")
  5136. fmt.Println(id)
  5137. patientInfo := service.QueryPatientById(id)
  5138. c.ServeSuccessJSON(map[string]interface{}{
  5139. "patient": patientInfo,
  5140. })
  5141. return
  5142. }
  5143. func (c *PatientApiController) GetRemindPatientList() {
  5144. page, _ := c.GetInt64("page", 1)
  5145. limit, _ := c.GetInt64("limit", 10)
  5146. adminUserInfo := c.GetAdminUserInfo()
  5147. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  5148. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  5149. if errcode == gorm.ErrRecordNotFound {
  5150. information, err := service.GetAdminUserRoleInformation(0)
  5151. if err != nil {
  5152. utils.ErrorLog(err.Error())
  5153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5154. return
  5155. }
  5156. c.ServeSuccessJSON(map[string]interface{}{
  5157. "total": total,
  5158. "patients": patients,
  5159. "information": information,
  5160. })
  5161. } else if errcode == nil {
  5162. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  5163. if err != nil {
  5164. utils.ErrorLog(err.Error())
  5165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5166. return
  5167. }
  5168. c.ServeSuccessJSON(map[string]interface{}{
  5169. "total": total,
  5170. "patients": patients,
  5171. "information": information,
  5172. })
  5173. }
  5174. }
  5175. func (c *PatientApiController) PostIsOpenRemind() {
  5176. patient_id, _ := c.GetInt64("id", 1)
  5177. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  5178. adminUserInfo := c.GetAdminUserInfo()
  5179. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  5180. if err == nil {
  5181. c.ServeSuccessJSON(map[string]interface{}{
  5182. "msg": "成功",
  5183. "is_open_remind": is_open_remind,
  5184. })
  5185. } else if err != nil {
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5187. }
  5188. }
  5189. func (c *PatientApiController) GetPatientScheduleOne() {
  5190. id, _ := c.GetInt64("id")
  5191. //查询该病人是否当天是排班
  5192. nowDateTime := time.Now()
  5193. nowDate := nowDateTime.Format("2006-01-02")
  5194. nowDate += " 00:00:00"
  5195. timeLayout := "2006-01-02"
  5196. loc, _ := time.LoadLocation("Local")
  5197. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  5198. nowdate := theTime.Unix()
  5199. fmt.Println("nowdate", nowdate)
  5200. adminUser := c.GetAdminUserInfo()
  5201. orgId := adminUser.CurrentOrgId
  5202. fmt.Println("orgid", orgId)
  5203. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  5204. if err != nil {
  5205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5206. return
  5207. }
  5208. c.ServeSuccessJSON(map[string]interface{}{
  5209. "scheduls": scheduls,
  5210. })
  5211. }
  5212. func (c *PatientApiController) ExportPatients() {
  5213. dataBody := make(map[string]interface{}, 0)
  5214. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  5215. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  5216. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  5217. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5218. if err != nil {
  5219. utils.ErrorLog(err.Error())
  5220. return
  5221. }
  5222. utils.ErrorLog("%v", dataBody)
  5223. export_time := time.Now().Unix()
  5224. var patients []*models.Patients
  5225. var total_patients []interface{}
  5226. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  5227. tempPatients := dataBody["patients"].([]interface{})
  5228. total_patients = tempPatients
  5229. for index, patientMap := range tempPatients {
  5230. patientNameM := patientMap.(map[string]interface{})
  5231. var patient models.Patients
  5232. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  5233. utils.ErrorLog("name")
  5234. return
  5235. }
  5236. name, _ := patientNameM["name"].(string)
  5237. if len(name) == 0 { //名字为空则生成一条导入错误日志
  5238. err_log := models.ExportErrLog{
  5239. LogType: 1,
  5240. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5241. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  5242. Status: 1,
  5243. CreateTime: time.Now().Unix(),
  5244. UpdateTime: time.Now().Unix(),
  5245. ExportTime: export_time,
  5246. }
  5247. service.CreateExportErrLog(&err_log)
  5248. continue
  5249. }
  5250. patient.Name = name
  5251. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  5252. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  5253. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  5254. err_log := models.ExportErrLog{
  5255. LogType: 1,
  5256. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5257. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  5258. Status: 1,
  5259. CreateTime: time.Now().Unix(),
  5260. UpdateTime: time.Now().Unix(),
  5261. ExportTime: export_time,
  5262. }
  5263. service.CreateExportErrLog(&err_log)
  5264. continue
  5265. } else {
  5266. patient.Gender = gender
  5267. }
  5268. }
  5269. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  5270. phone, _ := patientNameM["phone"].(string)
  5271. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  5272. if len(phone) == 0 {
  5273. err_log := models.ExportErrLog{
  5274. LogType: 1,
  5275. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5276. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  5277. Status: 1,
  5278. CreateTime: time.Now().Unix(),
  5279. UpdateTime: time.Now().Unix(),
  5280. ExportTime: export_time,
  5281. }
  5282. service.CreateExportErrLog(&err_log)
  5283. continue
  5284. } else {
  5285. err_log := models.ExportErrLog{
  5286. LogType: 1,
  5287. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5288. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  5289. Status: 1,
  5290. CreateTime: time.Now().Unix(),
  5291. UpdateTime: time.Now().Unix(),
  5292. ExportTime: export_time,
  5293. }
  5294. service.CreateExportErrLog(&err_log)
  5295. continue
  5296. }
  5297. } else {
  5298. //var tempPatient *models.Patients
  5299. //for _, item := range all_patient {
  5300. // if item.Phone == phone {
  5301. // tempPatient = item
  5302. // }
  5303. //}
  5304. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  5305. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  5306. if count >= 1 {
  5307. err_log := models.ExportErrLog{
  5308. LogType: 1,
  5309. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5310. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  5311. Status: 1,
  5312. CreateTime: time.Now().Unix(),
  5313. UpdateTime: time.Now().Unix(),
  5314. ExportTime: export_time,
  5315. }
  5316. service.CreateExportErrLog(&err_log)
  5317. continue
  5318. }
  5319. patient.Phone = phone
  5320. }
  5321. }
  5322. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  5323. id_card_no, _ := patientNameM["id_card_no"].(string)
  5324. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  5325. if len(id_card_no) == 0 {
  5326. err_log := models.ExportErrLog{
  5327. LogType: 1,
  5328. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5329. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  5330. Status: 1,
  5331. CreateTime: time.Now().Unix(),
  5332. UpdateTime: time.Now().Unix(),
  5333. ExportTime: export_time,
  5334. }
  5335. service.CreateExportErrLog(&err_log)
  5336. continue
  5337. } else {
  5338. err_log := models.ExportErrLog{
  5339. LogType: 1,
  5340. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5341. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  5342. Status: 1,
  5343. CreateTime: time.Now().Unix(),
  5344. UpdateTime: time.Now().Unix(),
  5345. ExportTime: export_time,
  5346. }
  5347. service.CreateExportErrLog(&err_log)
  5348. continue
  5349. }
  5350. } else {
  5351. //var tempPatient *models.Patients
  5352. //for _, item := range all_patient {
  5353. // if item.IdCardNo == id_card_no {
  5354. // tempPatient = item
  5355. // }
  5356. //}
  5357. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5358. if count >= 1 {
  5359. //if tempPatient != nil && tempPatient.ID > 0 {
  5360. err_log := models.ExportErrLog{
  5361. LogType: 1,
  5362. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5363. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  5364. Status: 1,
  5365. CreateTime: time.Now().Unix(),
  5366. UpdateTime: time.Now().Unix(),
  5367. ExportTime: export_time,
  5368. }
  5369. service.CreateExportErrLog(&err_log)
  5370. continue
  5371. }
  5372. //}
  5373. patient.IdCardNo = id_card_no
  5374. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  5375. if GetBirthDay(id_card_no) == nil {
  5376. patient.Birthday = 0
  5377. } else {
  5378. patient.Birthday = GetBirthDay(id_card_no).Unix()
  5379. }
  5380. }
  5381. }
  5382. fmt.Println("111112222")
  5383. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  5384. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  5385. timeLayout := "2006/01/02"
  5386. loc, _ := time.LoadLocation("Local")
  5387. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5388. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5389. if len(first_treatment_date) == 0 {
  5390. err_log := models.ExportErrLog{
  5391. LogType: 1,
  5392. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5393. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5394. Status: 1,
  5395. CreateTime: time.Now().Unix(),
  5396. UpdateTime: time.Now().Unix(),
  5397. ExportTime: export_time,
  5398. }
  5399. service.CreateExportErrLog(&err_log)
  5400. continue
  5401. } else {
  5402. err_log := models.ExportErrLog{
  5403. LogType: 1,
  5404. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5405. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5406. Status: 1,
  5407. CreateTime: time.Now().Unix(),
  5408. UpdateTime: time.Now().Unix(),
  5409. ExportTime: export_time,
  5410. }
  5411. service.CreateExportErrLog(&err_log)
  5412. continue
  5413. }
  5414. } else {
  5415. if len(first_treatment_date) == 0 {
  5416. err_log := models.ExportErrLog{
  5417. LogType: 1,
  5418. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5419. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5420. Status: 1,
  5421. CreateTime: time.Now().Unix(),
  5422. UpdateTime: time.Now().Unix(),
  5423. ExportTime: export_time,
  5424. }
  5425. service.CreateExportErrLog(&err_log)
  5426. continue
  5427. } else {
  5428. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5429. err_log := models.ExportErrLog{
  5430. LogType: 1,
  5431. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5432. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5433. Status: 1,
  5434. CreateTime: time.Now().Unix(),
  5435. UpdateTime: time.Now().Unix(),
  5436. ExportTime: export_time,
  5437. }
  5438. service.CreateExportErrLog(&err_log)
  5439. continue
  5440. } else {
  5441. patient.FirstDialysisDate = first_dialysis_date.Unix()
  5442. }
  5443. }
  5444. }
  5445. }
  5446. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  5447. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  5448. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  5449. err_log := models.ExportErrLog{
  5450. LogType: 1,
  5451. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5452. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  5453. Status: 1,
  5454. CreateTime: time.Now().Unix(),
  5455. UpdateTime: time.Now().Unix(),
  5456. ExportTime: export_time,
  5457. }
  5458. service.CreateExportErrLog(&err_log)
  5459. continue
  5460. } else if source == 3 {
  5461. err_log := models.ExportErrLog{
  5462. LogType: 1,
  5463. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5464. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  5465. Status: 1,
  5466. CreateTime: time.Now().Unix(),
  5467. UpdateTime: time.Now().Unix(),
  5468. ExportTime: export_time,
  5469. }
  5470. service.CreateExportErrLog(&err_log)
  5471. continue
  5472. } else {
  5473. patient.Source = source
  5474. }
  5475. }
  5476. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  5477. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  5478. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  5479. err_log := models.ExportErrLog{
  5480. LogType: 1,
  5481. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5482. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  5483. Status: 1,
  5484. CreateTime: time.Now().Unix(),
  5485. UpdateTime: time.Now().Unix(),
  5486. ExportTime: export_time,
  5487. }
  5488. service.CreateExportErrLog(&err_log)
  5489. continue
  5490. } else if lapseto == 3 {
  5491. err_log := models.ExportErrLog{
  5492. LogType: 1,
  5493. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5494. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  5495. Status: 1,
  5496. CreateTime: time.Now().Unix(),
  5497. UpdateTime: time.Now().Unix(),
  5498. ExportTime: export_time,
  5499. }
  5500. service.CreateExportErrLog(&err_log)
  5501. continue
  5502. } else {
  5503. patient.Lapseto = lapseto
  5504. }
  5505. }
  5506. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  5507. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  5508. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  5509. err_log := models.ExportErrLog{
  5510. LogType: 1,
  5511. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5512. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  5513. Status: 1,
  5514. CreateTime: time.Now().Unix(),
  5515. UpdateTime: time.Now().Unix(),
  5516. ExportTime: export_time,
  5517. }
  5518. service.CreateExportErrLog(&err_log)
  5519. continue
  5520. } else if is_infectious == 3 {
  5521. err_log := models.ExportErrLog{
  5522. LogType: 1,
  5523. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5524. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  5525. Status: 1,
  5526. CreateTime: time.Now().Unix(),
  5527. UpdateTime: time.Now().Unix(),
  5528. ExportTime: export_time,
  5529. }
  5530. service.CreateExportErrLog(&err_log)
  5531. continue
  5532. } else {
  5533. patient.IsInfectious = is_infectious
  5534. }
  5535. }
  5536. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  5537. var contagions []int64
  5538. thisContagions, _ := patientNameM["contagions"].([]interface{})
  5539. if len(thisContagions) > 0 {
  5540. for _, item := range thisContagions {
  5541. if reflect.TypeOf(item).String() != "float64" {
  5542. continue
  5543. }
  5544. contagion := int64(item.(float64))
  5545. if contagion > 0 {
  5546. contagions = append(contagions, contagion)
  5547. }
  5548. }
  5549. }
  5550. patient.ContagionIds = contagions
  5551. }
  5552. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  5553. diagnose, _ := patientNameM["diagnose"].(string)
  5554. patient.Diagnose = diagnose
  5555. }
  5556. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  5557. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  5558. var tempPatient *models.Patients
  5559. for _, item := range all_patient {
  5560. if item.DialysisNo == dialysis_no {
  5561. tempPatient = item
  5562. }
  5563. }
  5564. if tempPatient != nil && tempPatient.ID > 0 {
  5565. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  5566. } else {
  5567. patient.DialysisNo = dialysis_no
  5568. }
  5569. }
  5570. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  5571. height, _ := patientNameM["height"].(string)
  5572. heights, _ := strconv.ParseFloat(height, 64)
  5573. patient.Height = int64(heights)
  5574. }
  5575. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  5576. home_address, _ := patientNameM["home_address"].(string)
  5577. patient.HomeAddress = home_address
  5578. }
  5579. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5580. dry_weight, _ := patientNameM["dry_weight"].(string)
  5581. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5582. patient.DryWeight = dry_weights
  5583. }
  5584. patient.CreatedTime = time.Now().Unix()
  5585. patient.UpdatedTime = time.Now().Unix()
  5586. patient.Status = 1
  5587. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5588. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5589. patient.IsExcelExport = 1
  5590. patient.PatientType = 1
  5591. patients = append(patients, &patient)
  5592. }
  5593. }
  5594. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5595. if len(patients) > 0 {
  5596. for _, item := range patients {
  5597. hans := item.Name // 要转换的汉字字符串
  5598. // 创建一个拼音转换器
  5599. p := pinyin.NewArgs()
  5600. // 将汉字转为拼音
  5601. pinyinSlice := pinyin.Pinyin(hans, p)
  5602. // 输出拼音
  5603. fmt.Println("Pinyin:", pinyinSlice)
  5604. // 获取首字母
  5605. firstLetter := ""
  5606. for _, py := range pinyinSlice {
  5607. if len(py) > 0 {
  5608. firstLetter += string(py[0][0])
  5609. }
  5610. }
  5611. item.FirstLetter = firstLetter
  5612. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5613. }
  5614. log := models.ExportLog{
  5615. LogType: 1,
  5616. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5617. TotalNum: int64(len(total_patients)),
  5618. FailNum: int64(len(errLogs)),
  5619. SuccessNum: int64(len(patients)),
  5620. CreateTime: time.Now().Unix(),
  5621. UpdateTime: time.Now().Unix(),
  5622. ExportTime: export_time,
  5623. Status: 1,
  5624. }
  5625. service.CreateExportLog(&log)
  5626. c.ServeSuccessJSON(map[string]interface{}{
  5627. "msg": "导入成功",
  5628. "total_num": len(total_patients),
  5629. "success_num": len(patients),
  5630. "fail_num": int64(len(errLogs)),
  5631. })
  5632. } else {
  5633. log := models.ExportLog{
  5634. LogType: 1,
  5635. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5636. TotalNum: int64(len(total_patients)),
  5637. FailNum: int64(len(errLogs)),
  5638. SuccessNum: int64(len(patients)),
  5639. CreateTime: time.Now().Unix(),
  5640. UpdateTime: time.Now().Unix(),
  5641. ExportTime: export_time,
  5642. Status: 1,
  5643. }
  5644. service.CreateExportLog(&log)
  5645. c.ServeSuccessJSON(map[string]interface{}{
  5646. "msg": "导入成功",
  5647. "total_num": len(total_patients),
  5648. "success_num": len(patients),
  5649. "fail_num": int64(len(errLogs)),
  5650. })
  5651. }
  5652. }
  5653. func GetBirthDay(IDCardNo string) *time.Time {
  5654. dayStr := IDCardNo[6:14]
  5655. birthDay, err := time.Parse("20060102", dayStr)
  5656. if err != nil {
  5657. fmt.Println(err)
  5658. return nil
  5659. }
  5660. return &birthDay
  5661. }
  5662. func IsIdCard(id string) (res bool) {
  5663. id = strings.ToUpper(id)
  5664. if len(id) != 15 && len(id) != 18 {
  5665. fmt.Println("1111111")
  5666. return false
  5667. }
  5668. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5669. if !r.MatchString(id) {
  5670. fmt.Println("222222")
  5671. return false
  5672. }
  5673. if len(id) == 15 {
  5674. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5675. if tm2.Unix() == 0 {
  5676. fmt.Println("44444443333")
  5677. return false
  5678. }
  5679. return true
  5680. } else {
  5681. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5682. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5683. fmt.Println(tm2.Unix())
  5684. if tm2.Unix() == 0 {
  5685. fmt.Println("44445555555")
  5686. return false
  5687. }
  5688. //检验18位身份证的校验码是否正确。
  5689. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5690. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5691. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5692. sign := 0
  5693. for k, v := range arr_int {
  5694. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5695. sign += int_temp * v
  5696. }
  5697. n := sign % 11
  5698. val_num := arr_ch[n]
  5699. if val_num != string([]byte(id)[17:18]) {
  5700. fmt.Println("5556666666")
  5701. return false
  5702. }
  5703. return true
  5704. }
  5705. }
  5706. func (c *PatientApiController) SaveEditAdvices() {
  5707. adminInfo := c.GetAdminUserInfo()
  5708. orgid := adminInfo.CurrentOrgId
  5709. startTime := c.GetString("start_time")
  5710. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5711. groupno, _ := c.GetInt64("groupno")
  5712. fmt.Println("组", groupno)
  5713. date, _ := c.GetInt64("date")
  5714. fmt.Println("date", date)
  5715. patient_id, _ := c.GetInt64("patient_id")
  5716. fmt.Println("paitent_id", patient_id)
  5717. advice := models.XtDoctorAdvice{
  5718. StartTime: theTime.Unix(),
  5719. }
  5720. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5721. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5722. redis := service.RedisClient()
  5723. redis.Set(key, "", time.Second)
  5724. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5725. redis.Set(keyOne, "", time.Second)
  5726. scheduleTime := theTime.Format("2006-01-02")
  5727. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5728. fmt.Println("keyFour323223323232323232", keyFour)
  5729. redis.Set(keyFour, "", time.Second)
  5730. defer redis.Close()
  5731. if err != nil {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5733. return
  5734. }
  5735. c.ServeSuccessJSON(map[string]interface{}{
  5736. "advice": advice,
  5737. })
  5738. }
  5739. func (c *PatientApiController) GetMaxDialysisNo() {
  5740. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5741. c.ServeSuccessJSON(map[string]interface{}{
  5742. "dialysis_no": dialysisNo,
  5743. })
  5744. }
  5745. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5746. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5747. var tempPatient *models.Patients
  5748. for _, item := range patients {
  5749. if item.DialysisNo == dialysisNo2 {
  5750. tempPatient = item
  5751. }
  5752. }
  5753. if tempPatient == nil || tempPatient.ID == 0 {
  5754. return dialysisNo2
  5755. }
  5756. return GenerateDialysisNoTwo(patients)
  5757. }
  5758. func (c *PatientApiController) GetBanner() {
  5759. orgId := c.GetAdminUserInfo().CurrentOrgId
  5760. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5761. if errcodes == gorm.ErrRecordNotFound {
  5762. information, err := service.GetAdminUserRoleInformation(0)
  5763. if err != nil {
  5764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5765. return
  5766. }
  5767. c.ServeSuccessJSON(map[string]interface{}{
  5768. "information": information,
  5769. })
  5770. } else if errcodes == nil {
  5771. information, err := service.GetAdminUserRoleInformation(orgId)
  5772. if err != nil {
  5773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5774. return
  5775. }
  5776. c.ServeSuccessJSON(map[string]interface{}{
  5777. "information": information,
  5778. })
  5779. }
  5780. }
  5781. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5782. patient_id, _ := c.GetInt64("id", 0)
  5783. page, _ := c.GetInt64("page", 0)
  5784. limit, _ := c.GetInt64("limit", 0)
  5785. if patient_id <= 0 {
  5786. c.ServeSuccessJSON(map[string]interface{}{
  5787. "solutions": nil,
  5788. })
  5789. return
  5790. }
  5791. if page <= 0 {
  5792. page = 1
  5793. }
  5794. if limit <= 0 {
  5795. limit = 10
  5796. }
  5797. adminUserInfo := c.GetAdminUserInfo()
  5798. //获取该患者分组的透析模式
  5799. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5800. for _, item := range list {
  5801. //获取该模式最新的1条数据
  5802. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5803. //更新状态值
  5804. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5805. }
  5806. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5807. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5808. if err != nil {
  5809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5810. return
  5811. }
  5812. c.ServeSuccessJSON(map[string]interface{}{
  5813. "solutions": solution,
  5814. "total": total,
  5815. "stockType": stockType,
  5816. })
  5817. }
  5818. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5819. patient_id, _ := c.GetInt64("patient_id")
  5820. mode_id, _ := c.GetInt64("mode_id")
  5821. page, _ := c.GetInt64("page")
  5822. limit, _ := c.GetInt64("limit")
  5823. orgId := c.GetAdminUserInfo().CurrentOrgId
  5824. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5825. if err != nil {
  5826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5827. return
  5828. }
  5829. c.ServeSuccessJSON(map[string]interface{}{
  5830. "list": list,
  5831. "total": total,
  5832. })
  5833. }
  5834. func (c *PatientApiController) SaveFallOutBedPrint() {
  5835. adminInfo := c.GetAdminUserInfo()
  5836. orgid := adminInfo.CurrentOrgId
  5837. dataBody := make(map[string]interface{}, 0)
  5838. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5839. fmt.Println("err", err)
  5840. content := dataBody["content"].(string)
  5841. outPrint := models.XtFallOutPrint{
  5842. UserOrgId: orgid,
  5843. Content: content,
  5844. Status: 1,
  5845. Ctime: time.Now().Unix(),
  5846. Mtime: time.Now().Unix(),
  5847. }
  5848. //查询该机构是否存在
  5849. list, err := service.GetOutPrintList(orgid)
  5850. if list.ID == 0 {
  5851. service.CreateFallOutBedPrint(outPrint)
  5852. }
  5853. if list.ID > 0 {
  5854. service.UpdateFallOutBedPrint(list.ID, content)
  5855. }
  5856. c.ServeSuccessJSON(map[string]interface{}{
  5857. "list": list,
  5858. })
  5859. }
  5860. func (c *PatientApiController) GetFallOutBedPrintList() {
  5861. adminInfo := c.GetAdminUserInfo()
  5862. orgid := adminInfo.CurrentOrgId
  5863. list, _ := service.GetFallOutBedPrintList(orgid)
  5864. c.ServeSuccessJSON(map[string]interface{}{
  5865. "list": list,
  5866. })
  5867. }
  5868. func (c *PatientApiController) SaveFilterInformed() {
  5869. adminInfo := c.GetAdminUserInfo()
  5870. orgid := adminInfo.CurrentOrgId
  5871. dataBody := make(map[string]interface{}, 0)
  5872. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5873. fmt.Println("err", err)
  5874. content := dataBody["content"].(string)
  5875. informed := models.XtFilterInformed{
  5876. UserOrgId: orgid,
  5877. Content: content,
  5878. Status: 1,
  5879. Ctime: time.Now().Unix(),
  5880. Mtime: time.Now().Unix(),
  5881. }
  5882. filterInformed, _ := service.GetFilterInformed(orgid)
  5883. if filterInformed.ID == 0 {
  5884. service.CreateFilterInformed(informed)
  5885. }
  5886. if filterInformed.ID > 0 {
  5887. service.UpdateFilterInformed(filterInformed.ID, content)
  5888. }
  5889. c.ServeSuccessJSON(map[string]interface{}{
  5890. "informed": informed,
  5891. })
  5892. }
  5893. func (c *PatientApiController) GetFilterInformed() {
  5894. adminInfo := c.GetAdminUserInfo()
  5895. orgid := adminInfo.CurrentOrgId
  5896. filterInformed, _ := service.GetFilterInformed(orgid)
  5897. c.ServeSuccessJSON(map[string]interface{}{
  5898. "list": filterInformed,
  5899. })
  5900. }
  5901. func (c *PatientApiController) SaveProfundaInformed() {
  5902. adminInfo := c.GetAdminUserInfo()
  5903. orgid := adminInfo.CurrentOrgId
  5904. dataBody := make(map[string]interface{}, 0)
  5905. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5906. fmt.Println("err", err)
  5907. content := dataBody["content"].(string)
  5908. informed := models.XtProfundaInformed{
  5909. UserOrgId: orgid,
  5910. Content: content,
  5911. Status: 1,
  5912. Ctime: time.Now().Unix(),
  5913. Mtime: time.Now().Unix(),
  5914. }
  5915. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5916. if profundaInformed.ID == 0 {
  5917. service.CreateProfundaInformed(informed)
  5918. }
  5919. if profundaInformed.ID > 0 {
  5920. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5921. }
  5922. c.ServeSuccessJSON(map[string]interface{}{
  5923. "list": profundaInformed,
  5924. })
  5925. }
  5926. func (c *PatientApiController) GetProfundaInformed() {
  5927. adminInfo := c.GetAdminUserInfo()
  5928. orgid := adminInfo.CurrentOrgId
  5929. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5930. c.ServeSuccessJSON(map[string]interface{}{
  5931. "list": profundaInformed,
  5932. })
  5933. }
  5934. func (c *PatientApiController) SaveArterOvenous() {
  5935. adminInfo := c.GetAdminUserInfo()
  5936. orgid := adminInfo.CurrentOrgId
  5937. dataBody := make(map[string]interface{}, 0)
  5938. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5939. fmt.Println("err", err)
  5940. content := dataBody["content"].(string)
  5941. arterOvenous := models.XtArterOvenous{
  5942. UserOrgId: orgid,
  5943. Content: content,
  5944. Status: 1,
  5945. Ctime: time.Now().Unix(),
  5946. Mtime: time.Now().Unix(),
  5947. }
  5948. list, _ := service.GetArterOvenousList(orgid)
  5949. if list.ID == 0 {
  5950. service.CreateArterOvernous(arterOvenous)
  5951. }
  5952. if list.ID > 0 {
  5953. service.UpdateArterOvernous(list.ID, content)
  5954. }
  5955. c.ServeSuccessJSON(map[string]interface{}{
  5956. "list": list,
  5957. })
  5958. }
  5959. func (c *PatientApiController) GetArterOverNous() {
  5960. adminInfo := c.GetAdminUserInfo()
  5961. orgid := adminInfo.CurrentOrgId
  5962. list, _ := service.GetArterOvenousList(orgid)
  5963. c.ServeSuccessJSON(map[string]interface{}{
  5964. "list": list,
  5965. })
  5966. }
  5967. func (c *PatientApiController) SaveHighRikInformed() {
  5968. adminInfo := c.GetAdminUserInfo()
  5969. orgid := adminInfo.CurrentOrgId
  5970. dataBody := make(map[string]interface{}, 0)
  5971. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5972. fmt.Println("err", err)
  5973. content := dataBody["content"].(string)
  5974. risk := models.XtHightRisk{
  5975. UserOrgId: orgid,
  5976. Content: content,
  5977. Status: 1,
  5978. Ctime: time.Now().Unix(),
  5979. Mtime: time.Now().Unix(),
  5980. }
  5981. highRik, _ := service.GetHightRikInformed(orgid)
  5982. if highRik.ID == 0 {
  5983. service.CreateHighRik(risk)
  5984. }
  5985. if highRik.ID > 0 {
  5986. service.UpdateHighRik(highRik.ID, content)
  5987. }
  5988. c.ServeSuccessJSON(map[string]interface{}{
  5989. "list": risk,
  5990. })
  5991. }
  5992. func (c *PatientApiController) GetHighRiskInformed() {
  5993. orgId := c.GetAdminUserInfo().CurrentOrgId
  5994. rikInformed, _ := service.GetHightRikInformed(orgId)
  5995. c.ServeSuccessJSON(map[string]interface{}{
  5996. "list": rikInformed,
  5997. })
  5998. }
  5999. func (c *PatientApiController) SaveAnticoagulation() {
  6000. orgId := c.GetAdminUserInfo().CurrentOrgId
  6001. dataBody := make(map[string]interface{}, 0)
  6002. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6003. fmt.Println("err", err)
  6004. content := dataBody["content"].(string)
  6005. auticoagutionPrint := models.XtAuticoagutionPrint{
  6006. Content: content,
  6007. UserOrgId: orgId,
  6008. Status: 1,
  6009. Ctime: time.Now().Unix(),
  6010. Mtime: time.Now().Unix(),
  6011. }
  6012. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6013. if anticoagulation.ID == 0 {
  6014. service.CreateAnticoagulation(auticoagutionPrint)
  6015. }
  6016. if anticoagulation.ID > 0 {
  6017. service.UpdateAnticoagulation(anticoagulation.ID, content)
  6018. }
  6019. c.ServeSuccessJSON(map[string]interface{}{
  6020. "list": auticoagutionPrint,
  6021. })
  6022. }
  6023. func (c *PatientApiController) GetAnticoagulationInformed() {
  6024. orgId := c.GetAdminUserInfo().CurrentOrgId
  6025. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6026. c.ServeSuccessJSON(map[string]interface{}{
  6027. "list": anticoagulation,
  6028. })
  6029. }
  6030. func (c *PatientApiController) SaveCriticalInfomed() {
  6031. orgId := c.GetAdminUserInfo().CurrentOrgId
  6032. dataBody := make(map[string]interface{}, 0)
  6033. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6034. fmt.Println("err", err)
  6035. content := dataBody["content"].(string)
  6036. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  6037. UserOrgId: orgId,
  6038. Content: content,
  6039. Status: 1,
  6040. Ctime: time.Now().Unix(),
  6041. Mtime: time.Now().Unix(),
  6042. }
  6043. infomed, _ := service.GetCriticalInfomed(orgId)
  6044. if infomed.ID == 0 {
  6045. service.CreatedCriticalInfomed(criticalinfomedPrint)
  6046. }
  6047. if infomed.ID > 0 {
  6048. service.UpdateCriticalInfomed(infomed.ID, content)
  6049. }
  6050. c.ServeSuccessJSON(map[string]interface{}{
  6051. "list": criticalinfomedPrint,
  6052. })
  6053. }
  6054. func (c *PatientApiController) GetCriticalInformed() {
  6055. orgId := c.GetAdminUserInfo().CurrentOrgId
  6056. infomed, _ := service.GetCriticalInfomed(orgId)
  6057. c.ServeSuccessJSON(map[string]interface{}{
  6058. "list": infomed,
  6059. })
  6060. }
  6061. func (c *PatientApiController) SaveHemoperfusionInformed() {
  6062. orgId := c.GetAdminUserInfo().CurrentOrgId
  6063. dataBody := make(map[string]interface{}, 0)
  6064. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6065. fmt.Println("err", err)
  6066. content := dataBody["content"].(string)
  6067. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  6068. UserOrgId: orgId,
  6069. Content: content,
  6070. Status: 1,
  6071. Ctime: time.Now().Unix(),
  6072. Mtime: time.Now().Unix(),
  6073. }
  6074. informed, _ := service.GetHemoperfusionInformed(orgId)
  6075. if informed.ID == 0 {
  6076. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  6077. }
  6078. if informed.ID > 0 {
  6079. service.UpdateHemoperfusionInformed(informed.ID, content)
  6080. }
  6081. c.ServeSuccessJSON(map[string]interface{}{
  6082. "list": hemoperfusionmedPrint,
  6083. })
  6084. }
  6085. func (c *PatientApiController) GetHemoperfusionInformed() {
  6086. orgId := c.GetAdminUserInfo().CurrentOrgId
  6087. informed, _ := service.GetHemoperfusionInformed(orgId)
  6088. c.ServeSuccessJSON(map[string]interface{}{
  6089. "list": informed,
  6090. })
  6091. }
  6092. func (c *PatientApiController) SaveBringInformed() {
  6093. orgId := c.GetAdminUserInfo().CurrentOrgId
  6094. dataBody := make(map[string]interface{}, 0)
  6095. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6096. fmt.Println("err", err)
  6097. content := dataBody["content"].(string)
  6098. bringinformedPrint := models.XtBringinformedPrint{
  6099. Content: content,
  6100. UserOrgId: orgId,
  6101. Ctime: time.Now().Unix(),
  6102. Mtime: time.Now().Unix(),
  6103. Status: 1,
  6104. }
  6105. informed, _ := service.GetBringInformed(orgId)
  6106. if informed.ID == 0 {
  6107. service.CreateBringInformed(bringinformedPrint)
  6108. }
  6109. if informed.ID > 0 {
  6110. service.UpdateBringInformed(informed.ID, content)
  6111. }
  6112. c.ServeSuccessJSON(map[string]interface{}{
  6113. "list": bringinformedPrint,
  6114. })
  6115. }
  6116. func (c *PatientApiController) GetInformedContsent() {
  6117. orgId := c.GetAdminUserInfo().CurrentOrgId
  6118. informed, _ := service.GetBringInformed(orgId)
  6119. c.ServeSuccessJSON(map[string]interface{}{
  6120. "list": informed,
  6121. })
  6122. }
  6123. func (c *PatientApiController) SaveCatheterization() {
  6124. orgId := c.GetAdminUserInfo().CurrentOrgId
  6125. dataBody := make(map[string]interface{}, 0)
  6126. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6127. fmt.Println("err", err)
  6128. content := dataBody["content"].(string)
  6129. cathetercationPrint := models.XtCathetercationPrint{
  6130. UserOrgId: orgId,
  6131. Content: content,
  6132. Status: 1,
  6133. Ctime: time.Now().Unix(),
  6134. Mtime: time.Now().Unix(),
  6135. }
  6136. catheterization, _ := service.GetCatheterization(orgId)
  6137. if cathetercationPrint.ID == 0 {
  6138. service.CreateCatheteriztion(cathetercationPrint)
  6139. }
  6140. if cathetercationPrint.ID > 0 {
  6141. service.UpdateCatheterization(catheterization.ID, content)
  6142. }
  6143. c.ServeSuccessJSON(map[string]interface{}{
  6144. "list": catheterization,
  6145. })
  6146. }
  6147. func (c *PatientApiController) GetCatheterization() {
  6148. orgId := c.GetAdminUserInfo().CurrentOrgId
  6149. catheterization, _ := service.GetCatheterization(orgId)
  6150. c.ServeSuccessJSON(map[string]interface{}{
  6151. "list": catheterization,
  6152. })
  6153. }
  6154. func (c *PatientApiController) SaveDialyzerInformed() {
  6155. orgId := c.GetAdminUserInfo().CurrentOrgId
  6156. dataBody := make(map[string]interface{}, 0)
  6157. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6158. fmt.Println("err", err)
  6159. content := dataBody["content"].(string)
  6160. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  6161. UserOrgId: orgId,
  6162. Content: content,
  6163. Status: 1,
  6164. Ctime: time.Now().Unix(),
  6165. Mtime: time.Now().Unix(),
  6166. }
  6167. informed, _ := service.GetDialyzerInformed(orgId)
  6168. if informed.ID == 0 {
  6169. service.CreateDialyzerInformed(dialyszerinformedPrint)
  6170. }
  6171. if informed.ID > 0 {
  6172. service.UpdateDialyszerInformed(informed.ID, content)
  6173. }
  6174. c.ServeSuccessJSON(map[string]interface{}{
  6175. "list": dialyszerinformedPrint,
  6176. })
  6177. }
  6178. func (c *PatientApiController) GetDialyzerInformed() {
  6179. orgId := c.GetAdminUserInfo().CurrentOrgId
  6180. informed, _ := service.GetDialyzerInformed(orgId)
  6181. c.ServeSuccessJSON(map[string]interface{}{
  6182. "list": informed,
  6183. })
  6184. }
  6185. func (c *PatientApiController) SaveTheapyInformed() {
  6186. orgId := c.GetAdminUserInfo().CurrentOrgId
  6187. dataBody := make(map[string]interface{}, 0)
  6188. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6189. fmt.Println("err", err)
  6190. content := dataBody["content"].(string)
  6191. theapyinformedPrint := models.XtTheapyinformedPrint{
  6192. Content: content,
  6193. UserOrgId: orgId,
  6194. Status: 1,
  6195. Ctime: time.Now().Unix(),
  6196. Mtime: time.Now().Unix(),
  6197. }
  6198. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6199. if theapyInformed.ID == 0 {
  6200. service.CreateTheapyInformed(theapyinformedPrint)
  6201. }
  6202. if theapyInformed.ID > 0 {
  6203. service.UpdateTheaphInformed(theapyInformed.ID, content)
  6204. }
  6205. c.ServeSuccessJSON(map[string]interface{}{
  6206. "list": theapyinformedPrint,
  6207. })
  6208. }
  6209. func (c *PatientApiController) GetTherapyInformed() {
  6210. orgId := c.GetAdminUserInfo().CurrentOrgId
  6211. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6212. c.ServeSuccessJSON(map[string]interface{}{
  6213. "list": theapyInformed,
  6214. })
  6215. }
  6216. func (c *PatientApiController) SaveMedicalHistory() {
  6217. orgId := c.GetAdminUserInfo().CurrentOrgId
  6218. dataBody := make(map[string]interface{}, 0)
  6219. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6220. fmt.Println("err", err)
  6221. content := dataBody["content"].(string)
  6222. patient_id := int64(dataBody["patient_id"].(float64))
  6223. medicalHistory := models.XtMedicalHistory{
  6224. UserOrgId: orgId,
  6225. PatientId: patient_id,
  6226. Ctime: time.Now().Unix(),
  6227. Mtime: 0,
  6228. Status: 1,
  6229. Content: content,
  6230. }
  6231. //
  6232. history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
  6233. if history.ID > 0 {
  6234. service.UpdatePatientMedicalHistory(history.ID, content)
  6235. }
  6236. if history.ID == 0 {
  6237. service.CreatePatientMedicalHistory(medicalHistory)
  6238. }
  6239. c.ServeSuccessJSON(map[string]interface{}{
  6240. "medicalHistory": medicalHistory,
  6241. })
  6242. }
  6243. func (c *PatientApiController) SavePatientCritaicalInformed() {
  6244. orgId := c.GetAdminUserInfo().CurrentOrgId
  6245. dataBody := make(map[string]interface{}, 0)
  6246. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6247. fmt.Println("err", err)
  6248. content := dataBody["content"].(string)
  6249. patientCritical := models.XtPatientCritical{
  6250. UserOrgId: orgId,
  6251. Content: content,
  6252. Status: 1,
  6253. Ctime: time.Now().Unix(),
  6254. Mtime: time.Now().Unix(),
  6255. }
  6256. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6257. if patientCritaicalInformed.ID == 0 {
  6258. service.CreatePatientCritaicalinformed(patientCritical)
  6259. }
  6260. if patientCritaicalInformed.ID > 0 {
  6261. service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
  6262. }
  6263. c.ServeSuccessJSON(map[string]interface{}{
  6264. "patientCritical": patientCritical,
  6265. })
  6266. }
  6267. func (c *PatientApiController) GetPatientCriticalList() {
  6268. orgId := c.GetAdminUserInfo().CurrentOrgId
  6269. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6270. c.ServeSuccessJSON(map[string]interface{}{
  6271. "patientCritaicalInformed": patientCritaicalInformed,
  6272. })
  6273. }
  6274. func (c *PatientApiController) SavePatientCriticalInformedOne() {
  6275. orgId := c.GetAdminUserInfo().CurrentOrgId
  6276. dataBody := make(map[string]interface{}, 0)
  6277. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6278. fmt.Println("err", err)
  6279. content := dataBody["content"].(string)
  6280. criticalOne := models.XtPatientCriticalOne{
  6281. UserOrgId: orgId,
  6282. Content: content,
  6283. Status: 1,
  6284. Ctime: time.Now().Unix(),
  6285. Mtime: time.Now().Unix(),
  6286. }
  6287. critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
  6288. if critical.ID == 0 {
  6289. service.CreatePatientCritical(criticalOne)
  6290. }
  6291. if critical.ID > 0 {
  6292. service.UpdatePatientCriticalOne(orgId, content)
  6293. }
  6294. c.ServeSuccessJSON(map[string]interface{}{
  6295. "criticalOne": criticalOne,
  6296. })
  6297. }
  6298. func (c *PatientApiController) GetPatientCriticalOneList() {
  6299. orgId := c.GetAdminUserInfo().CurrentOrgId
  6300. list, _ := service.GetPatientCriticalOneList(orgId)
  6301. c.ServeSuccessJSON(map[string]interface{}{
  6302. "list": list,
  6303. })
  6304. }
  6305. func (c *PatientApiController) DeleteSolution() {
  6306. id, _ := c.GetInt64("id")
  6307. solution, _ := service.DeleteSolutionById(id)
  6308. c.ServeSuccessJSON(map[string]interface{}{
  6309. "solution": solution,
  6310. })
  6311. }
  6312. func (c *PatientApiController) SaveTreatmentPlan() {
  6313. orgId := c.GetAdminUserInfo().CurrentOrgId
  6314. dataBody := make(map[string]interface{}, 0)
  6315. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6316. fmt.Println("err", err)
  6317. content := dataBody["content"].(string)
  6318. theapyinformedPrint := models.XtTreatmentPlan{
  6319. Content: content,
  6320. UserOrgId: orgId,
  6321. Status: 1,
  6322. Ctime: time.Now().Unix(),
  6323. Mtime: time.Now().Unix(),
  6324. }
  6325. treamentPlan, _ := service.GetTreamentPland(orgId)
  6326. if treamentPlan.ID == 0 {
  6327. service.CreateTreatqmentPland(theapyinformedPrint)
  6328. }
  6329. if treamentPlan.ID > 0 {
  6330. service.UpdateTheatmentPland(treamentPlan.ID, content)
  6331. }
  6332. c.ServeSuccessJSON(map[string]interface{}{
  6333. "list": theapyinformedPrint,
  6334. })
  6335. }
  6336. func (c *PatientApiController) GetTreatMentPlanList() {
  6337. orgId := c.GetAdminUserInfo().CurrentOrgId
  6338. treamentPlan, _ := service.GetTreamentPland(orgId)
  6339. c.ServeSuccessJSON(map[string]interface{}{
  6340. "treamentPlan": treamentPlan,
  6341. })
  6342. }