patient_api_controller.go 225KB

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