patient_api_controller.go 222KB

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