patient_api_controller.go 226KB

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