patient_api_controller.go 224KB

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