patient_api_controller.go 225KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792
  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. var total int64
  2382. var prescribing_number_total int64
  2383. //药品保存处方出库
  2384. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2385. if config.IsOpen != 1 {
  2386. //查询默认出库仓库
  2387. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2388. //查询该药品在默认仓库是否有库存
  2389. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2390. //判断单位是否相等
  2391. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2392. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2393. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2394. //转化为最小单位
  2395. total = list.Count*medical.MinNumber + list.StockMinNumber
  2396. prescribing_number_total = count * medical.MinNumber
  2397. }
  2398. if medical.MinUnit == advice.PrescribingNumberUnit {
  2399. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2400. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2401. total = list.Count*medical.MinNumber + list.StockMinNumber
  2402. prescribing_number_total = count
  2403. }
  2404. if medical.IsUse == 1 {
  2405. drugError := models.XtDrugError{
  2406. UserOrgId: item.UserOrgId,
  2407. DrugId: item.DrugId,
  2408. RecordDate: item.AdviceDate,
  2409. PatientId: item.PatientId,
  2410. Remark: "电脑端零用药品",
  2411. Status: 1,
  2412. Ctime: time.Now().Unix(),
  2413. Mtime: 0,
  2414. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2415. Prescribingnumber: item.PrescribingNumber,
  2416. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2417. }
  2418. service.CreateDrugError(drugError)
  2419. c.ServeSuccessJSON(map[string]interface{}{
  2420. "msg": "1",
  2421. "advice": advice,
  2422. })
  2423. return
  2424. }
  2425. if medical.IsUse != 1 {
  2426. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2427. drugError := models.XtDrugError{
  2428. UserOrgId: item.UserOrgId,
  2429. DrugId: item.DrugId,
  2430. RecordDate: item.AdviceDate,
  2431. PatientId: item.PatientId,
  2432. Remark: "电脑端药品库存不足",
  2433. Status: 1,
  2434. Ctime: time.Now().Unix(),
  2435. Mtime: 0,
  2436. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2437. Prescribingnumber: item.PrescribingNumber,
  2438. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2439. }
  2440. service.CreateDrugError(drugError)
  2441. c.ServeSuccessJSON(map[string]interface{}{
  2442. "msg": "3",
  2443. "advice": advice,
  2444. })
  2445. return
  2446. }
  2447. if prescribing_number_total > total {
  2448. drugError := models.XtDrugError{
  2449. UserOrgId: item.UserOrgId,
  2450. DrugId: item.DrugId,
  2451. RecordDate: item.AdviceDate,
  2452. PatientId: item.PatientId,
  2453. Remark: "电脑端出库数量大于总库存",
  2454. Status: 1,
  2455. Ctime: time.Now().Unix(),
  2456. Mtime: 0,
  2457. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2458. Prescribingnumber: item.PrescribingNumber,
  2459. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2460. }
  2461. service.CreateDrugError(drugError)
  2462. c.ServeSuccessJSON(map[string]interface{}{
  2463. "msg": "2",
  2464. "advice": advice,
  2465. })
  2466. return
  2467. }
  2468. }
  2469. if prescribing_number_total <= total {
  2470. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2471. if medical.IsUse == 2 {
  2472. if config.IsOpen != 1 {
  2473. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2474. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2475. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2476. //查询该药品是否有出库记录
  2477. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2478. if len(flowMap) == 0 {
  2479. errs := service.UpdateHisAdviceById(item.ID)
  2480. if errs != nil {
  2481. drugError := models.XtDrugError{
  2482. UserOrgId: item.UserOrgId,
  2483. DrugId: item.DrugId,
  2484. RecordDate: item.AdviceDate,
  2485. PatientId: item.PatientId,
  2486. Remark: "出库记录为空,更新执行人失败",
  2487. Status: 1,
  2488. Ctime: time.Now().Unix(),
  2489. Mtime: 0,
  2490. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2491. Prescribingnumber: item.PrescribingNumber,
  2492. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2493. }
  2494. service.CreateDrugError(drugError)
  2495. }
  2496. c.ServeSuccessJSON(map[string]interface{}{
  2497. "msg": "6",
  2498. "advice": advice,
  2499. })
  2500. return
  2501. }
  2502. }
  2503. }
  2504. //不通过药房发药
  2505. if pharmacyConfig.IsOpen != 1 {
  2506. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2507. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2508. //查询该药品是否有出库记录
  2509. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2510. if len(flowMap) == 0 {
  2511. errs := service.UpdateHisAdviceById(item.ID)
  2512. if errs != nil {
  2513. drugError := models.XtDrugError{
  2514. UserOrgId: item.UserOrgId,
  2515. DrugId: item.DrugId,
  2516. RecordDate: item.AdviceDate,
  2517. PatientId: item.PatientId,
  2518. Remark: "出库记录为空,更新执行人失败",
  2519. Status: 1,
  2520. Ctime: time.Now().Unix(),
  2521. Mtime: 0,
  2522. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2523. Prescribingnumber: item.PrescribingNumber,
  2524. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2525. }
  2526. service.CreateDrugError(drugError)
  2527. }
  2528. c.ServeSuccessJSON(map[string]interface{}{
  2529. "msg": "6",
  2530. "advice": advice,
  2531. })
  2532. return
  2533. }
  2534. }
  2535. }
  2536. //查询默认仓库
  2537. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2538. //查询默认仓库剩余多少库存
  2539. var sum_count int64
  2540. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2541. for _, its := range stockInfo {
  2542. if its.MaxUnit == medical.MaxUnit {
  2543. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2544. }
  2545. sum_count += its.StockMaxNumber + its.StockMinNumber
  2546. }
  2547. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2548. //出库数量累加
  2549. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2550. //剩余库存
  2551. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2552. break
  2553. c.ServeSuccessJSON(map[string]interface{}{
  2554. "msg": "1",
  2555. "advice": advice,
  2556. })
  2557. return
  2558. }
  2559. }
  2560. if medical.IsUse == 1 {
  2561. c.ServeSuccessJSON(map[string]interface{}{
  2562. "msg": "1",
  2563. "advice": advice,
  2564. })
  2565. return
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. c.ServeSuccessJSON(map[string]interface{}{
  2572. "msg": "1",
  2573. "advice": advice,
  2574. })
  2575. return
  2576. }
  2577. }
  2578. func (c *PatientApiController) CheckGroupAdvice() {
  2579. groupno, _ := c.GetInt64("groupno", 0)
  2580. if groupno <= 0 {
  2581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2582. return
  2583. }
  2584. adminUserInfo := c.GetAdminUserInfo()
  2585. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2586. if advice.ID == 0 {
  2587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2588. return
  2589. }
  2590. if advice.CheckState == 1 {
  2591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2592. return
  2593. }
  2594. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2596. return
  2597. }
  2598. checker := adminUserInfo.AdminUser.Id
  2599. theTime := time.Now()
  2600. exceAdvice := models.DoctorAdvice{
  2601. Checker: checker,
  2602. CheckTime: theTime.Unix(),
  2603. UpdatedTime: time.Now().Unix(),
  2604. }
  2605. var err error
  2606. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2607. if err != nil {
  2608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2609. return
  2610. }
  2611. advice.Checker = checker
  2612. advice.CheckTime = theTime.Unix()
  2613. c.ServeSuccessJSON(map[string]interface{}{
  2614. "msg": "ok",
  2615. "advice": advice,
  2616. })
  2617. return
  2618. }
  2619. func (c *PatientApiController) CheckDoctorAdvice() {
  2620. patient, _ := c.GetInt64("patient", 0)
  2621. id, _ := c.GetInt64("id", 0)
  2622. origin, _ := c.GetInt64("origin", 0)
  2623. if origin != 2 {
  2624. // executionTime := c.GetString("execution_time")
  2625. if id <= 0 || patient <= 0 {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2627. return
  2628. }
  2629. adminUserInfo := c.GetAdminUserInfo()
  2630. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2631. if advice.ID == 0 || advice.PatientId != patient {
  2632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2633. return
  2634. }
  2635. if advice.CheckState == 1 {
  2636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2637. return
  2638. }
  2639. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2641. return
  2642. }
  2643. // executionStaff := adminUserInfo.AdminUser.Id
  2644. checker := adminUserInfo.AdminUser.Id
  2645. // timeLayout := "2006-01-02 15:04:05"
  2646. // loc, _ := time.LoadLocation("Local")
  2647. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2648. // if err != nil {
  2649. // utils.ErrorLog(err.Error())
  2650. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2651. // return
  2652. // }
  2653. theTime := time.Now()
  2654. if advice.ExecutionTime > theTime.Unix() {
  2655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2656. return
  2657. }
  2658. exceAdvice := models.DoctorAdvice{
  2659. Checker: checker,
  2660. CheckTime: theTime.Unix(),
  2661. UpdatedTime: time.Now().Unix(),
  2662. }
  2663. var err error
  2664. // 查询信息规挡的设置天数
  2665. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2666. if infor.ID > 0 && infor.WeekDay > 0 {
  2667. var cha_time int64
  2668. timeNowStr := time.Now().Format("2006-01-02")
  2669. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2670. //今日的日期减去设置的日期
  2671. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2672. if cha_time >= advice.AdviceDate {
  2673. //查询审核是否允许
  2674. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2675. //申请状态不允许的情况 拒绝修改
  2676. if infor.ApplicationStatus != 1 {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2678. return
  2679. }
  2680. }
  2681. }
  2682. if advice.ParentId > 0 {
  2683. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2684. //记录日志
  2685. byterequest, _ := json.Marshal(exceAdvice)
  2686. adviceLog := models.XtDoctorAdviceLog{
  2687. UserOrgId: exceAdvice.UserOrgId,
  2688. PatientId: exceAdvice.PatientId,
  2689. AdminUserId: adminUserInfo.AdminUser.Id,
  2690. Module: 3,
  2691. ErrLog: string(byterequest),
  2692. Status: 1,
  2693. Ctime: time.Now().Unix(),
  2694. Mtime: 0,
  2695. Source: "核对医嘱",
  2696. RecordDate: exceAdvice.AdviceDate,
  2697. }
  2698. service.CreateDoctorAdviceLog(adviceLog)
  2699. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2700. redis := service.RedisClient()
  2701. //清空key 值
  2702. redis.Set(key, "", time.Second)
  2703. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2704. redis.Set(keyTwo, "", time.Second)
  2705. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2706. redis.Set(keyThree, "", time.Second)
  2707. recordDate := theTime.Format("2006-01-02")
  2708. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2709. redis.Set(keyFour, "", time.Second)
  2710. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2711. redis.Set(keyFive, "", time.Second)
  2712. } else {
  2713. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2714. //记录日志
  2715. byterequest, _ := json.Marshal(exceAdvice)
  2716. adviceLog := models.XtDoctorAdviceLog{
  2717. UserOrgId: exceAdvice.UserOrgId,
  2718. PatientId: exceAdvice.PatientId,
  2719. AdminUserId: adminUserInfo.AdminUser.Id,
  2720. Module: 3,
  2721. ErrLog: string(byterequest),
  2722. Status: 1,
  2723. Ctime: time.Now().Unix(),
  2724. Mtime: 0,
  2725. Source: "核对医嘱",
  2726. RecordDate: exceAdvice.AdviceDate,
  2727. }
  2728. service.CreateDoctorAdviceLog(adviceLog)
  2729. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2730. redis := service.RedisClient()
  2731. //清空key 值
  2732. redis.Set(key, "", time.Second)
  2733. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2734. redis.Set(keyTwo, "", time.Second)
  2735. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2736. redis.Set(keyThree, "", time.Second)
  2737. recordDate := theTime.Format("2006-01-02")
  2738. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2739. redis.Set(keyFour, "", time.Second)
  2740. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2741. redis.Set(keyFive, "", time.Second)
  2742. }
  2743. if err != nil {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2745. return
  2746. }
  2747. // advice.ExecutionStaff = executionStaff
  2748. // advice.ExecutionTime = theTime.Unix()
  2749. advice.Checker = checker
  2750. advice.CheckTime = theTime.Unix()
  2751. c.ServeSuccessJSON(map[string]interface{}{
  2752. "msg": "ok",
  2753. "advice": advice,
  2754. })
  2755. return
  2756. } else {
  2757. if id <= 0 || patient <= 0 {
  2758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2759. return
  2760. }
  2761. adminUserInfo := c.GetAdminUserInfo()
  2762. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2763. if advice.ID == 0 || advice.PatientId != patient {
  2764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2765. return
  2766. }
  2767. if advice.CheckState == 1 {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2769. return
  2770. }
  2771. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2773. return
  2774. }
  2775. checker := adminUserInfo.AdminUser.Id
  2776. theTime := time.Now()
  2777. if advice.ExecutionTime > theTime.Unix() {
  2778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2779. return
  2780. }
  2781. exceAdvice := models.HisDoctorAdviceInfo{
  2782. Checker: checker,
  2783. CheckTime: theTime.Unix(),
  2784. UpdatedTime: time.Now().Unix(),
  2785. }
  2786. var err error
  2787. if advice.ParentId > 0 {
  2788. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2789. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2790. redis := service.RedisClient()
  2791. //清空key 值
  2792. redis.Set(key, "", time.Second)
  2793. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2794. redis.Set(keyTwo, "", time.Second)
  2795. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2796. redis.Set(keyThree, "", time.Second)
  2797. recordDate := theTime.Format("2006-01-02")
  2798. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2799. redis.Set(keyFour, "", time.Second)
  2800. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2801. redis.Set(keyFive, "", time.Second)
  2802. } else {
  2803. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2804. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2805. redis := service.RedisClient()
  2806. //清空key 值
  2807. redis.Set(key, "", time.Second)
  2808. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2809. redis.Set(keyTwo, "", time.Second)
  2810. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2811. redis.Set(keyThree, "", time.Second)
  2812. recordDate := theTime.Format("2006-01-02")
  2813. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2814. redis.Set(keyFour, "", time.Second)
  2815. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2816. redis.Set(keyFive, "", time.Second)
  2817. }
  2818. if err != nil {
  2819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2820. return
  2821. }
  2822. // advice.ExecutionStaff = executionStaff
  2823. // advice.ExecutionTime = theTime.Unix()
  2824. advice.Checker = checker
  2825. advice.CheckTime = theTime.Unix()
  2826. c.ServeSuccessJSON(map[string]interface{}{
  2827. "msg": "ok",
  2828. "advice": advice,
  2829. })
  2830. return
  2831. }
  2832. }
  2833. func (c *PatientApiController) UpdateDoctorAdvice() {
  2834. patient, _ := c.GetInt64("patient", 0)
  2835. id, _ := c.GetInt64("id", 0)
  2836. if id <= 0 || patient <= 0 {
  2837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2838. return
  2839. }
  2840. adminUserInfo := c.GetAdminUserInfo()
  2841. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2842. if advice.ID == 0 || advice.PatientId != patient {
  2843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2844. return
  2845. }
  2846. //if advice.AdviceType == 1 {
  2847. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2848. // return
  2849. //}
  2850. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  2851. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2853. return
  2854. }
  2855. }
  2856. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2857. //if appRole.UserType == 3 {
  2858. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2859. // if getPermissionErr != nil {
  2860. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2861. // return
  2862. // } else if headNursePermission == nil {
  2863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2864. // return
  2865. // }
  2866. //}
  2867. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2868. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2869. // return
  2870. //}
  2871. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2872. if code > 0 {
  2873. c.ServeFailJSONWithSGJErrorCode(code)
  2874. return
  2875. }
  2876. advice.UpdatedTime = time.Now().Unix()
  2877. advice.Modifier = adminUserInfo.AdminUser.Id
  2878. // 查询信息规挡的设置天数
  2879. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2880. if infor.ID > 0 && infor.WeekDay > 0 {
  2881. var cha_time int64
  2882. timeNowStr := time.Now().Format("2006-01-02")
  2883. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2884. //今日的日期减去设置的日期
  2885. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2886. if cha_time >= advice.AdviceDate {
  2887. //查询审核是否允许
  2888. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2889. //申请状态不允许的情况 拒绝修改
  2890. if infor.ApplicationStatus != 1 {
  2891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2892. return
  2893. }
  2894. }
  2895. }
  2896. err := service.UpdateDoctorAdvice(&advice)
  2897. //记录日志
  2898. byterequest, _ := json.Marshal(advice)
  2899. doctorAdviceLog := models.XtDoctorAdviceLog{
  2900. UserOrgId: advice.UserOrgId,
  2901. PatientId: advice.PatientId,
  2902. AdminUserId: adminUserInfo.AdminUser.Id,
  2903. Module: 1,
  2904. ErrLog: string(byterequest),
  2905. Status: 1,
  2906. Ctime: time.Now().Unix(),
  2907. Mtime: 0,
  2908. Source: "电脑端修改医嘱",
  2909. RecordDate: advice.AdviceDate,
  2910. }
  2911. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2912. redis := service.RedisClient()
  2913. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2914. redis.Set(key, "", time.Second)
  2915. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2916. redis.Set(keyOne, "", time.Second)
  2917. defer redis.Close()
  2918. if err != nil {
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2920. return
  2921. }
  2922. c.ServeSuccessJSON(map[string]interface{}{
  2923. "msg": "ok",
  2924. "advice": advice,
  2925. })
  2926. return
  2927. }
  2928. func (c *PatientApiController) StopGroupAdvice() {
  2929. groupNo, _ := c.GetInt64("groupno", 0)
  2930. if groupNo <= 0 {
  2931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2932. return
  2933. }
  2934. adminUserInfo := c.GetAdminUserInfo()
  2935. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2936. if advice.ID == 0 {
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2938. return
  2939. }
  2940. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2942. return
  2943. }
  2944. dataBody := make(map[string]interface{}, 0)
  2945. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2946. if err != nil {
  2947. utils.ErrorLog(err.Error())
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2949. return
  2950. }
  2951. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2952. utils.ErrorLog("stop_time")
  2953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2954. return
  2955. }
  2956. stopTime, _ := dataBody["stop_time"].(string)
  2957. if len(stopTime) == 0 {
  2958. utils.ErrorLog("len(stop_time) == 0")
  2959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2960. return
  2961. }
  2962. timeLayout := "2006-01-02"
  2963. loc, _ := time.LoadLocation("Local")
  2964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2965. if err != nil {
  2966. utils.ErrorLog(err.Error())
  2967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2968. return
  2969. }
  2970. advice.StopTime = theTime.Unix()
  2971. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2972. stopReason, _ := dataBody["stop_reason"].(string)
  2973. advice.StopReason = stopReason
  2974. }
  2975. advice.UpdatedTime = time.Now().Unix()
  2976. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2977. advice.StopState = 1
  2978. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2979. if err != nil {
  2980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2981. return
  2982. }
  2983. c.ServeSuccessJSON(map[string]interface{}{
  2984. "msg": "ok",
  2985. })
  2986. return
  2987. }
  2988. func (c *PatientApiController) StopDoctorAdvice() {
  2989. id, _ := c.GetInt64("id", 0)
  2990. if id <= 0 {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2992. return
  2993. }
  2994. adminUserInfo := c.GetAdminUserInfo()
  2995. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2996. //
  2997. //if appRole.UserType == 3 {
  2998. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2999. // if getPermissionErr != nil {
  3000. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3001. // return
  3002. // } else if headNursePermission == nil {
  3003. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3004. // return
  3005. // }
  3006. //}
  3007. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3008. if advice.ID == 0 {
  3009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3010. return
  3011. }
  3012. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3014. return
  3015. }
  3016. dataBody := make(map[string]interface{}, 0)
  3017. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3018. if err != nil {
  3019. utils.ErrorLog(err.Error())
  3020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3021. return
  3022. }
  3023. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3024. utils.ErrorLog("stop_time")
  3025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3026. return
  3027. }
  3028. stopTime, _ := dataBody["stop_time"].(string)
  3029. if len(stopTime) == 0 {
  3030. utils.ErrorLog("len(stop_time) == 0")
  3031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3032. return
  3033. }
  3034. timeLayout := "2006-01-02"
  3035. loc, _ := time.LoadLocation("Local")
  3036. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3037. if err != nil {
  3038. utils.ErrorLog(err.Error())
  3039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3040. return
  3041. }
  3042. advice.StopTime = theTime.Unix()
  3043. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3044. stopReason, _ := dataBody["stop_reason"].(string)
  3045. advice.StopReason = stopReason
  3046. }
  3047. advice.UpdatedTime = time.Now().Unix()
  3048. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3049. advice.StopState = 1
  3050. err = service.StopDoctorAdvice(&advice)
  3051. if err != nil {
  3052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3053. return
  3054. }
  3055. c.ServeSuccessJSON(map[string]interface{}{
  3056. "msg": "ok",
  3057. "advice": advice,
  3058. })
  3059. return
  3060. }
  3061. func (c *PatientApiController) DeleteDoctorAdvice() {
  3062. id, _ := c.GetInt64("id", 0)
  3063. if id <= 0 {
  3064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3065. return
  3066. }
  3067. adminUserInfo := c.GetAdminUserInfo()
  3068. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3069. if advice.ID == 0 {
  3070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3071. return
  3072. }
  3073. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3074. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3075. // return
  3076. //}
  3077. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3078. //
  3079. //if appRole.UserType == 3 {
  3080. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3081. // if getPermissionErr != nil {
  3082. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. // return
  3084. // } else if headNursePermission == nil {
  3085. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3086. // return
  3087. // }
  3088. //}
  3089. advice.UpdatedTime = time.Now().Unix()
  3090. advice.Status = 0
  3091. advice.Modifier = adminUserInfo.AdminUser.Id
  3092. // 查询信息规挡的设置天数
  3093. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3094. if infor.ID > 0 && infor.WeekDay > 0 {
  3095. var cha_time int64
  3096. timeNowStr := time.Now().Format("2006-01-02")
  3097. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3098. //今日的日期减去设置的日期
  3099. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3100. if cha_time >= advice.AdviceDate {
  3101. //查询审核是否允许
  3102. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3103. //申请状态不允许的情况 拒绝修改
  3104. if infor.ApplicationStatus != 1 {
  3105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3106. return
  3107. }
  3108. }
  3109. }
  3110. err := service.DeleteDoctorAdvice(&advice)
  3111. //记录日志
  3112. byterequest, _ := json.Marshal(advice)
  3113. doctorAdviceLog := models.XtDoctorAdviceLog{
  3114. UserOrgId: advice.UserOrgId,
  3115. PatientId: advice.PatientId,
  3116. AdminUserId: adminUserInfo.AdminUser.Id,
  3117. Module: 4,
  3118. ErrLog: string(byterequest),
  3119. Status: 1,
  3120. Ctime: time.Now().Unix(),
  3121. Mtime: 0,
  3122. Source: "电脑端删除医嘱",
  3123. RecordDate: advice.RecordDate,
  3124. }
  3125. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3126. redis := service.RedisClient()
  3127. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3128. redis.Set(keyOne, "", time.Second)
  3129. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3130. redis.Set(key, "", time.Second)
  3131. redis.Close()
  3132. if err != nil {
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3134. return
  3135. }
  3136. c.ServeSuccessJSON(map[string]interface{}{
  3137. "msg": "ok",
  3138. })
  3139. return
  3140. }
  3141. func (c *PatientApiController) DeleteGroupAdvice() {
  3142. groupNo, _ := c.GetInt64("groupno", 0)
  3143. if groupNo <= 0 {
  3144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3145. return
  3146. }
  3147. adminUserInfo := c.GetAdminUserInfo()
  3148. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3149. if advice.ID == 0 {
  3150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3151. return
  3152. }
  3153. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3154. //if appRole.UserType == 3 {
  3155. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3156. // if getPermissionErr != nil {
  3157. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3158. // return
  3159. // } else if headNursePermission == nil {
  3160. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3161. // return
  3162. // }
  3163. //}
  3164. // 查询信息规挡的设置天数
  3165. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3166. if infor.ID > 0 && infor.WeekDay > 0 {
  3167. var cha_time int64
  3168. timeNowStr := time.Now().Format("2006-01-02")
  3169. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3170. //今日的日期减去设置的日期
  3171. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3172. if cha_time >= advice.AdviceDate {
  3173. //查询审核是否允许
  3174. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3175. //申请状态不允许的情况 拒绝修改
  3176. if infor.ApplicationStatus != 1 {
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3178. return
  3179. }
  3180. }
  3181. }
  3182. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3183. byterequest, _ := json.Marshal(advice)
  3184. doctorAdviceLog := models.XtDoctorAdviceLog{
  3185. UserOrgId: advice.UserOrgId,
  3186. PatientId: advice.PatientId,
  3187. AdminUserId: adminUserInfo.AdminUser.Id,
  3188. Module: 4,
  3189. ErrLog: string(byterequest),
  3190. Status: 1,
  3191. Ctime: time.Now().Unix(),
  3192. Mtime: 0,
  3193. Source: "电脑端批量删除医嘱",
  3194. RecordDate: advice.RecordDate,
  3195. }
  3196. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3197. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3198. redis := service.RedisClient()
  3199. redis.Set(key, "", time.Second)
  3200. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3201. redis.Set(keyOne, "", time.Second)
  3202. defer redis.Close()
  3203. if err != nil {
  3204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3205. return
  3206. }
  3207. c.ServeSuccessJSON(map[string]interface{}{
  3208. "msg": "ok",
  3209. })
  3210. return
  3211. }
  3212. // GetDoctorAdvices 医嘱列表
  3213. func (c *PatientApiController) GetDoctorAdvices() {
  3214. id, _ := c.GetInt64("id", 0)
  3215. adviceType, _ := c.GetInt64("advice_type", 0)
  3216. stopType, _ := c.GetInt64("stop_state", 0)
  3217. startTime := c.GetString("start_time", "")
  3218. endTime := c.GetString("end_time", "")
  3219. keywords := c.GetString("keywords", "")
  3220. page, _ := c.GetInt64("page")
  3221. fmt.Println("page", page)
  3222. limit, _ := c.GetInt64("limit")
  3223. fmt.Println("limit", limit)
  3224. adminUserInfo := c.GetAdminUserInfo()
  3225. operatorIDs := make([]int64, 0)
  3226. timeLayout := "2006-01-02"
  3227. loc, _ := time.LoadLocation("Local")
  3228. var theStartTIme int64
  3229. if len(startTime) > 0 {
  3230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3231. if err != nil {
  3232. utils.ErrorLog(err.Error())
  3233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3234. return
  3235. }
  3236. theStartTIme = theTime.Unix()
  3237. }
  3238. var theEndtTIme int64
  3239. if len(endTime) > 0 {
  3240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3241. if err != nil {
  3242. utils.ErrorLog(err.Error())
  3243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3244. return
  3245. }
  3246. theEndtTIme = theTime.Unix()
  3247. }
  3248. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3249. if hisconfig.IsOpen == 1 {
  3250. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3251. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3252. if len(advices) > 0 {
  3253. for _, item := range advices {
  3254. if item.AdviceDoctor > 0 {
  3255. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3256. }
  3257. if item.ExecutionStaff > 0 {
  3258. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3259. }
  3260. if item.Checker > 0 {
  3261. operatorIDs = append(operatorIDs, item.Checker)
  3262. }
  3263. if item.StopDoctor > 0 {
  3264. operatorIDs = append(operatorIDs, item.StopDoctor)
  3265. }
  3266. }
  3267. }
  3268. //相关操作对应的操作人
  3269. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3270. //获取长期医嘱
  3271. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3272. c.ServeSuccessJSON(map[string]interface{}{
  3273. "advices": advices,
  3274. "operators": operators,
  3275. "total": total,
  3276. "advicetwo": advicestwo,
  3277. "longAdvice": longAdvice,
  3278. "is_open": hisconfig.IsOpen,
  3279. })
  3280. return
  3281. } else {
  3282. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3283. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3284. if len(advices) > 0 {
  3285. for _, item := range advices {
  3286. if item.AdviceDoctor > 0 {
  3287. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3288. }
  3289. if item.ExecutionStaff > 0 {
  3290. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3291. }
  3292. if item.Checker > 0 {
  3293. operatorIDs = append(operatorIDs, item.Checker)
  3294. }
  3295. if item.StopDoctor > 0 {
  3296. operatorIDs = append(operatorIDs, item.StopDoctor)
  3297. }
  3298. }
  3299. }
  3300. //相关操作对应的操作人
  3301. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "advices": advices,
  3304. "operators": operators,
  3305. "total": total,
  3306. "advicetwo": advicestwo,
  3307. "is_open": hisconfig.IsOpen,
  3308. })
  3309. return
  3310. }
  3311. }
  3312. func (c *PatientApiController) GetPatientSchedules() {
  3313. id, _ := c.GetInt64("id", 0)
  3314. if id <= 0 {
  3315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3316. return
  3317. }
  3318. adminUserInfo := c.GetAdminUserInfo()
  3319. todayTime := time.Now().Format("2006-01-02")
  3320. timeLayout := "2006-01-02 15:04:05"
  3321. loc, _ := time.LoadLocation("Local")
  3322. var theStartTime int64
  3323. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3324. theStartTime = theTime.Unix()
  3325. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3326. if len(schedules) > 0 {
  3327. for index, item := range schedules {
  3328. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3329. schedules[index].Week = int64(week)
  3330. }
  3331. }
  3332. c.ServeSuccessJSON(map[string]interface{}{
  3333. "schedules": schedules,
  3334. })
  3335. return
  3336. }
  3337. func (c *PatientApiController) GetPatientDialysisRecords() {
  3338. patientID, _ := c.GetInt64("patient_id", 0)
  3339. page, _ := c.GetInt64("page", 0)
  3340. limit, _ := c.GetInt64("limit", 0)
  3341. startTime := c.GetString("start_time", "")
  3342. endTime := c.GetString("end_time", "")
  3343. mode_id, _ := c.GetInt64("mode_id", 0)
  3344. if page <= 0 {
  3345. page = 1
  3346. }
  3347. if limit <= 0 {
  3348. limit = 10
  3349. }
  3350. if patientID <= 0 {
  3351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3352. return
  3353. }
  3354. timeLayout := "2006-01-02"
  3355. loc, _ := time.LoadLocation("Local")
  3356. var theStartTIme int64
  3357. if len(startTime) > 0 {
  3358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3359. if err != nil {
  3360. theStartTIme = 0
  3361. }
  3362. theStartTIme = theTime.Unix()
  3363. }
  3364. var theEndtTIme int64
  3365. if len(endTime) > 0 {
  3366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3367. if err != nil {
  3368. theEndtTIme = 0
  3369. }
  3370. theEndtTIme = theTime.Unix()
  3371. }
  3372. adminInfo := c.GetAdminUserInfo()
  3373. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3374. c.ServeSuccessJSON(map[string]interface{}{
  3375. "total": total,
  3376. "records": records,
  3377. })
  3378. return
  3379. }
  3380. func (c *PatientApiController) ProEducation() {
  3381. patientID, _ := c.GetInt64("patient_id", 0)
  3382. page, _ := c.GetInt64("page", 0)
  3383. limit, _ := c.GetInt64("limit", 0)
  3384. startTime := c.GetString("start_time", "")
  3385. endTime := c.GetString("end_time", "")
  3386. if page <= 0 {
  3387. page = 1
  3388. }
  3389. if limit <= 0 {
  3390. limit = 10
  3391. }
  3392. if patientID <= 0 {
  3393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3394. return
  3395. }
  3396. timeLayout := "2006-01-02"
  3397. loc, _ := time.LoadLocation("Local")
  3398. var theStartTIme int64
  3399. if len(startTime) > 0 {
  3400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3401. if err != nil {
  3402. theStartTIme = 0
  3403. }
  3404. theStartTIme = theTime.Unix()
  3405. }
  3406. var theEndtTIme int64
  3407. if len(endTime) > 0 {
  3408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3409. if err != nil {
  3410. theEndtTIme = 0
  3411. }
  3412. theEndtTIme = theTime.Unix()
  3413. }
  3414. adminInfo := c.GetAdminUserInfo()
  3415. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3416. c.ServeSuccessJSON(map[string]interface{}{
  3417. "total": total,
  3418. "edus": edus,
  3419. })
  3420. return
  3421. }
  3422. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3423. dataBody := make(map[string]interface{}, 0)
  3424. err := json.Unmarshal(data, &dataBody)
  3425. if err != nil {
  3426. utils.ErrorLog(err.Error())
  3427. code = enums.ErrorCodeParamWrong
  3428. return
  3429. }
  3430. timeLayout := "2006-01-02"
  3431. loc, _ := time.LoadLocation("Local")
  3432. isChild := false
  3433. if action == "create" {
  3434. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3435. utils.ErrorLog("advice_type")
  3436. code = enums.ErrorCodeParamWrong
  3437. return
  3438. }
  3439. adviceType := int64(dataBody["advice_type"].(float64))
  3440. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3441. utils.ErrorLog("advice_type != 1&&2")
  3442. code = enums.ErrorCodeParamWrong
  3443. return
  3444. }
  3445. advice.AdviceType = adviceType
  3446. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3447. utils.ErrorLog("advice_date")
  3448. code = enums.ErrorCodeParamWrong
  3449. return
  3450. }
  3451. adviceDate, _ := dataBody["advice_date"].(string)
  3452. if len(adviceDate) == 0 {
  3453. utils.ErrorLog("len(adviceDate) == 0")
  3454. code = enums.ErrorCodeParamWrong
  3455. return
  3456. }
  3457. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3458. if err != nil {
  3459. utils.ErrorLog(err.Error())
  3460. code = enums.ErrorCodeParamWrong
  3461. return
  3462. }
  3463. advice.AdviceDate = theTime.Unix()
  3464. advice.RecordDate = theTime.Unix()
  3465. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3466. parentId := int64(dataBody["parent_id"].(float64))
  3467. advice.ParentId = parentId
  3468. if parentId > 0 {
  3469. isChild = true
  3470. }
  3471. }
  3472. }
  3473. if !isChild {
  3474. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3475. utils.ErrorLog("start_time")
  3476. code = enums.ErrorCodeParamWrong
  3477. return
  3478. }
  3479. startTime, _ := dataBody["start_time"].(string)
  3480. if len(startTime) == 0 {
  3481. utils.ErrorLog("len(start_time) == 0")
  3482. code = enums.ErrorCodeParamWrong
  3483. return
  3484. }
  3485. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3486. if err != nil {
  3487. utils.ErrorLog(err.Error())
  3488. code = enums.ErrorCodeParamWrong
  3489. return
  3490. }
  3491. advice.StartTime = theTime.Unix()
  3492. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3493. // utils.ErrorLog("advice_doctor")
  3494. // code = enums.ErrorCodeParamWrong
  3495. // return
  3496. // }
  3497. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3498. // if adviceDoctor <= 0 {
  3499. // utils.ErrorLog("advice_doctor <=0")
  3500. // code = enums.ErrorCodeParamWrong
  3501. // return
  3502. // }
  3503. // advice.AdviceDoctor = adviceDoctor
  3504. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3505. deliveryWay, _ := dataBody["delivery_way"].(string)
  3506. advice.DeliveryWay = deliveryWay
  3507. }
  3508. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3509. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3510. advice.ExecutionFrequency = executionFrequency
  3511. }
  3512. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3513. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3514. frequency_type := int64(dataBody["frequency_type"].(float64))
  3515. advice.FrequencyType = frequency_type
  3516. }
  3517. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3518. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3519. advice.DayCount = day_count
  3520. }
  3521. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3522. week_day, _ := dataBody["week_days"].(string)
  3523. advice.WeekDay = week_day
  3524. }
  3525. }
  3526. }
  3527. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3528. utils.ErrorLog("advice_name")
  3529. code = enums.ErrorCodeParamWrong
  3530. return
  3531. }
  3532. adviceName, _ := dataBody["advice_name"].(string)
  3533. if len(adviceName) == 0 {
  3534. utils.ErrorLog("len(advice_name) == 0")
  3535. code = enums.ErrorCodeParamWrong
  3536. return
  3537. }
  3538. advice.AdviceName = adviceName
  3539. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3540. adviceDsc, _ := dataBody["advice_desc"].(string)
  3541. advice.AdviceDesc = adviceDsc
  3542. }
  3543. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3544. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3545. advice.DialysisOrderId = int64(dialysisOrderId)
  3546. }
  3547. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3548. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3549. advice.SingleDose = singleDose
  3550. }
  3551. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3552. singleDose := dataBody["single_dose"].(float64)
  3553. advice.SingleDose = singleDose
  3554. }
  3555. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3556. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3557. advice.SingleDoseUnit = singleDoseUnit
  3558. }
  3559. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3560. tmp := dataBody["single_dose_unit"].(float64)
  3561. singleDoseUnit := service.TypeConversion(tmp)
  3562. advice.SingleDoseUnit = singleDoseUnit
  3563. }
  3564. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3565. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3566. advice.DrugSpec = drugSpec
  3567. }
  3568. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3569. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3570. advice.DrugSpecUnit = drugSpecUnit
  3571. }
  3572. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3573. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3574. advice.PrescribingNumber = prescribingNumber
  3575. }
  3576. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3577. prescribingNumber := dataBody["prescribing_number"].(float64)
  3578. advice.PrescribingNumber = prescribingNumber
  3579. }
  3580. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3581. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3582. advice.PrescribingNumberUnit = prescribingNumberUnit
  3583. }
  3584. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3585. remark, _ := dataBody["remark"].(string)
  3586. advice.Remark = remark
  3587. }
  3588. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3589. drug_id, _ := dataBody["drug_id"].(string)
  3590. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3591. advice.DrugId = tmpDrugId
  3592. }
  3593. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3594. drug_id, _ := dataBody["drug_id"].(float64)
  3595. advice.DrugId = int64(drug_id)
  3596. }
  3597. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3598. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3599. advice.DrugNameId = int64(drug_name_id)
  3600. }
  3601. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3602. way, _ := dataBody["way"].(float64)
  3603. advice.Way = int64(way)
  3604. }
  3605. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3606. push_start_time, _ := dataBody["push_start_time"].(string)
  3607. var startTime int64
  3608. if len(push_start_time) > 0 {
  3609. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3610. startTime = theTime.Unix()
  3611. }
  3612. advice.PushStartTime = startTime
  3613. }
  3614. return
  3615. }
  3616. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3617. dataBody := make(map[string]interface{}, 0)
  3618. err := json.Unmarshal(data, &dataBody)
  3619. utils.InfoLog(string(data))
  3620. if err != nil {
  3621. utils.ErrorLog(err.Error())
  3622. code = enums.ErrorCodeParamWrong
  3623. return
  3624. }
  3625. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3626. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3627. solution.DialysisDuration = dialysisDuration
  3628. }
  3629. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3630. replacementWay := int64(dataBody["replacement_way"].(float64))
  3631. solution.ReplacementWay = replacementWay
  3632. }
  3633. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3634. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3635. solution.BloodFlowVolume = bloodFlowVolume
  3636. }
  3637. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3638. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3639. solution.HemodialysisMachine = hemodialysisMachine
  3640. }
  3641. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3642. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3643. solution.BloodFilter = bloodFilter
  3644. }
  3645. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3646. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3647. solution.PerfusionApparatus = perfusionApparatus
  3648. }
  3649. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3650. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3651. solution.DialysateFlow = dialysateFlow
  3652. }
  3653. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3654. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3655. solution.Kalium = kalium
  3656. }
  3657. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3658. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3659. solution.Sodium = sodium
  3660. }
  3661. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3662. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3663. solution.Calcium = calcium
  3664. }
  3665. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3666. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3667. solution.Bicarbonate = bicarbonate
  3668. }
  3669. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3670. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3671. solution.Anticoagulant = anticoagulant
  3672. }
  3673. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3674. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3675. solution.AnticoagulantShouji = anticoagulantShouji
  3676. }
  3677. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3678. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3679. solution.AnticoagulantWeichi = anticoagulantWeichi
  3680. }
  3681. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3682. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3683. solution.AnticoagulantZongliang = anticoagulantZongliang
  3684. }
  3685. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3686. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3687. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3688. }
  3689. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3690. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3691. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3692. }
  3693. return
  3694. }
  3695. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3696. dataBody := make(map[string]interface{}, 0)
  3697. err := json.Unmarshal(data, &dataBody)
  3698. utils.InfoLog(string(data))
  3699. if err != nil {
  3700. utils.ErrorLog(err.Error())
  3701. code = enums.ErrorCodeParamWrong
  3702. return
  3703. }
  3704. if method == "create" {
  3705. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3706. utils.ErrorLog("mode")
  3707. code = enums.ErrorCodeParamWrong
  3708. return
  3709. }
  3710. mode := int64(dataBody["mode"].(float64))
  3711. if mode <= 0 {
  3712. utils.ErrorLog("mode <= 0")
  3713. code = enums.ErrorCodeParamWrong
  3714. return
  3715. }
  3716. solution.ModeId = mode
  3717. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3718. utils.ErrorLog("mode_name")
  3719. code = enums.ErrorCodeParamWrong
  3720. return
  3721. }
  3722. modeName, _ := dataBody["mode_name"].(string)
  3723. if len(modeName) == 0 {
  3724. utils.ErrorLog("len(mode_name) == 0")
  3725. code = enums.ErrorCodeParamWrong
  3726. return
  3727. }
  3728. solution.ModeName = modeName
  3729. solution.Name = modeName
  3730. }
  3731. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3732. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3733. solution.DialysisDuration = dialysisDuration
  3734. }
  3735. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3736. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3737. solution.TargetUltrafiltration = targetUltrafiltration
  3738. }
  3739. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3740. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3741. solution.DialysateFormulation = dialysateFormulation
  3742. }
  3743. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3744. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3745. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3746. }
  3747. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3748. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3749. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3750. }
  3751. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3752. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3753. solution.HemodialysisMachine = hemodialysisMachine
  3754. }
  3755. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3756. dialyzer := int64(dataBody["dialyzer"].(float64))
  3757. solution.Dialyzer = dialyzer
  3758. }
  3759. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3760. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3761. solution.PerfusionApparatus = perfusionApparatus
  3762. }
  3763. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3764. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3765. solution.BloodFlowVolume = bloodFlowVolume
  3766. }
  3767. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3768. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3769. solution.Dewater = dewater
  3770. }
  3771. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3772. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3773. solution.DisplaceLiqui = displaceLiqui
  3774. }
  3775. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3776. replacementWay := int64(dataBody["replacement_way"].(float64))
  3777. solution.ReplacementWay = replacementWay
  3778. }
  3779. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3780. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3781. solution.Anticoagulant = anticoagulant
  3782. }
  3783. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3784. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3785. solution.AnticoagulantShouji = anticoagulantShouji
  3786. }
  3787. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3788. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3789. solution.AnticoagulantWeichi = anticoagulantWeichi
  3790. }
  3791. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3792. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3793. solution.AnticoagulantZongliang = anticoagulantZongliang
  3794. }
  3795. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3796. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3797. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3798. }
  3799. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3800. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3801. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3802. }
  3803. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3804. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3805. solution.Kalium = kalium
  3806. }
  3807. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3808. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3809. solution.Sodium = sodium
  3810. }
  3811. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3812. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3813. solution.Calcium = calcium
  3814. }
  3815. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3816. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3817. solution.Bicarbonate = bicarbonate
  3818. }
  3819. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3820. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3821. solution.Glucose = glucose
  3822. }
  3823. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3824. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3825. // solution.DryWeight = dryWeight
  3826. // }
  3827. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3828. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3829. solution.DialysateFlow = dialysateFlow
  3830. }
  3831. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3832. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3833. solution.DialysateTemperature = dialysateTemperature
  3834. }
  3835. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3836. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3837. solution.Conductivity = conductivity
  3838. }
  3839. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3840. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3841. solution.ReplacementTotal = replacementTotal
  3842. }
  3843. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3844. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3845. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3846. }
  3847. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3848. body_fluid := int64(dataBody["body_fluid"].(float64))
  3849. solution.BodyFluid = body_fluid
  3850. }
  3851. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3852. body_fluid_other := dataBody["body_fluid_other"].(string)
  3853. solution.BodyFluidOther = body_fluid_other
  3854. }
  3855. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3856. special_medicine := int64(dataBody["special_medicine"].(float64))
  3857. solution.SpecialMedicine = special_medicine
  3858. }
  3859. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3860. special_medicine_other := dataBody["special_medicine_other"].(string)
  3861. solution.SpecialMedicineOther = special_medicine_other
  3862. }
  3863. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3864. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3865. solution.DisplaceLiquiPart = displace_liqui_part
  3866. }
  3867. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3868. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3869. solution.DisplaceLiquiValue = displace_liqui_value
  3870. }
  3871. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3872. blood_access := int64(dataBody["blood_access"].(float64))
  3873. solution.BloodAccess = blood_access
  3874. }
  3875. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3876. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3877. solution.Ultrafiltration = ultrafiltration
  3878. }
  3879. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3880. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3881. solution.TargetKtv = target_ktv
  3882. }
  3883. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3884. remark := dataBody["remark"].(string)
  3885. solution.Remark = remark
  3886. }
  3887. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3888. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3889. solution.HemodialysisPipelines = hemodialysis_pipelines
  3890. }
  3891. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3892. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3893. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3894. }
  3895. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3896. puncture_needle := dataBody["puncture_needle"].(string)
  3897. solution.PunctureNeedle = puncture_needle
  3898. }
  3899. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3900. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3901. solution.PunctureNeedleCount = puncture_needle_count
  3902. }
  3903. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3904. epo := dataBody["epo"].(string)
  3905. solution.Epo = epo
  3906. }
  3907. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3908. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3909. solution.EpoCount = epo_count
  3910. }
  3911. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3912. created_time := int64(dataBody["created_time"].(float64))
  3913. solution.CreatedTime = created_time
  3914. }
  3915. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3916. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3917. solution.DialysisDialyszers = dialysisDialyszers
  3918. }
  3919. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3920. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3921. solution.DialysisIrrigation = dialysisIrrigation
  3922. }
  3923. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3924. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3925. solution.DialysisStrainer = dialysis_strainer
  3926. }
  3927. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3928. plasmaSeparator := dataBody["plasma_separator"].(string)
  3929. solution.PlasmaSeparator = plasmaSeparator
  3930. }
  3931. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3932. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3933. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3934. }
  3935. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3936. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3937. solution.OxygenUptake = oxygen_uptake
  3938. }
  3939. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3940. oxygen_flow := dataBody["oxygen_flow"].(string)
  3941. solution.OxygenFlow = oxygen_flow
  3942. }
  3943. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3944. oxygen_time := dataBody["oxygen_time"].(string)
  3945. solution.OxygenTime = oxygen_time
  3946. }
  3947. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3948. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3949. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3950. }
  3951. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3952. amylaceum := dataBody["amylaceum"].(string)
  3953. solution.Amylaceum = amylaceum
  3954. }
  3955. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  3956. chaptalization := dataBody["chaptalization"].(string)
  3957. solution.Chaptalization = chaptalization
  3958. }
  3959. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3960. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3961. solution.BloodAccessPartId = blood_access_part_id
  3962. }
  3963. return
  3964. }
  3965. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3966. dataBody := make(map[string]interface{}, 0)
  3967. err := json.Unmarshal(data, &dataBody)
  3968. utils.InfoLog(string(data))
  3969. if err != nil {
  3970. utils.ErrorLog(err.Error())
  3971. code = enums.ErrorCodeParamWrong
  3972. return
  3973. }
  3974. if method == "create" {
  3975. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3976. utils.ErrorLog("parent_id")
  3977. code = enums.ErrorCodeParamWrong
  3978. return
  3979. }
  3980. parentID := int64(dataBody["parent_id"].(float64))
  3981. if parentID <= 0 {
  3982. utils.ErrorLog("parentID <= 0")
  3983. code = enums.ErrorCodeParamWrong
  3984. return
  3985. }
  3986. solution.ParentId = parentID
  3987. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3988. utils.ErrorLog("sub_name")
  3989. code = enums.ErrorCodeParamWrong
  3990. return
  3991. }
  3992. subName, _ := dataBody["sub_name"].(string)
  3993. if len(subName) == 0 {
  3994. utils.ErrorLog("len(sub_name) == 0")
  3995. code = enums.ErrorCodeParamWrong
  3996. return
  3997. }
  3998. solution.SubName = subName
  3999. }
  4000. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4001. utils.ErrorLog("initiate_mode")
  4002. code = enums.ErrorCodeParamWrong
  4003. return
  4004. }
  4005. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4006. if initiateMode != 1 && initiateMode != 2 {
  4007. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4008. code = enums.ErrorCodeParamWrong
  4009. return
  4010. }
  4011. solution.InitiateMode = initiateMode
  4012. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4013. utils.ErrorLog("doctor")
  4014. code = enums.ErrorCodeParamWrong
  4015. return
  4016. }
  4017. doctor := int64(dataBody["doctor"].(float64))
  4018. if doctor <= 0 {
  4019. utils.ErrorLog("doctor <= 0")
  4020. code = enums.ErrorCodeParamWrong
  4021. return
  4022. }
  4023. solution.Doctor = doctor
  4024. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4025. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4026. solution.BloodAccessPartId = blood_access_part_id
  4027. }
  4028. return
  4029. }
  4030. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4031. patientBody := make(map[string]interface{}, 0)
  4032. err := json.Unmarshal(data, &patientBody)
  4033. if err != nil {
  4034. utils.ErrorLog(err.Error())
  4035. code = enums.ErrorCodeParamWrong
  4036. return
  4037. }
  4038. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4039. formItem, _ := patientBody["formItem"].([]interface{})
  4040. if len(formItem) > 0 {
  4041. for _, item := range formItem {
  4042. items := item.(map[string]interface{})
  4043. project_name, _ := items["project_name"].(string)
  4044. fmt.Println(project_name)
  4045. range_type := int64(items["range_type"].(float64))
  4046. fmt.Println(range_type)
  4047. project_id := int64(items["project_id"].(float64))
  4048. fmt.Println(project_id)
  4049. item_id := int64(items["item_id"].(float64))
  4050. fmt.Println(item_id)
  4051. item, _ := items["item"].(string)
  4052. fmt.Println(items["item"].(string))
  4053. item_name, _ := items["item_name"].(string)
  4054. fmt.Println(item_name)
  4055. value, _ := items["value"].(string)
  4056. fmt.Println(items["value"].(string))
  4057. var form models.FormItem
  4058. form.ProjectName = project_name
  4059. form.RangeType = range_type
  4060. form.ProjectId = project_id
  4061. form.ItemId = item_id
  4062. form.Item = item
  4063. form.ItemName = item_name
  4064. form.Value = value
  4065. formItems = append(formItems, &form)
  4066. }
  4067. }
  4068. }
  4069. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4070. utils.ErrorLog("avatar")
  4071. code = enums.ErrorCodeParamWrong
  4072. return
  4073. }
  4074. avatar, _ := patientBody["avatar"].(string)
  4075. if len(avatar) == 0 {
  4076. utils.ErrorLog("len(avatar) == 0")
  4077. code = enums.ErrorCodeParamWrong
  4078. return
  4079. }
  4080. patient.Avatar = avatar
  4081. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4082. utils.ErrorLog("name")
  4083. code = enums.ErrorCodeParamWrong
  4084. return
  4085. }
  4086. name, _ := patientBody["name"].(string)
  4087. if len(name) == 0 {
  4088. utils.ErrorLog("len(name) == 0")
  4089. code = enums.ErrorCodeParamWrong
  4090. return
  4091. }
  4092. patient.Name = name
  4093. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4094. alias := patientBody["alias"].(string)
  4095. patient.Alias = alias
  4096. }
  4097. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4098. nation := patientBody["nation"].(string)
  4099. patient.Nation = nation
  4100. }
  4101. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4102. native_place := patientBody["native_place"].(string)
  4103. patient.NativePlace = native_place
  4104. }
  4105. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4106. utils.ErrorLog("idCardNo")
  4107. code = enums.ErrorCodeParamWrong
  4108. return
  4109. }
  4110. idCardNo, _ := patientBody["idCardNo"].(string)
  4111. if len(idCardNo) == 0 {
  4112. utils.ErrorLog("len(idCardNo) == 0")
  4113. code = enums.ErrorCodeParamWrong
  4114. return
  4115. }
  4116. patient.IdCardNo = idCardNo
  4117. patient.PatientType = 1
  4118. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4119. utils.ErrorLog("dialysisNo")
  4120. code = enums.ErrorCodeParamWrong
  4121. return
  4122. }
  4123. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4124. if len(dialysisNo) == 0 {
  4125. utils.ErrorLog("len(dialysisNo) == 0")
  4126. code = enums.ErrorCodeParamWrong
  4127. return
  4128. }
  4129. patient.DialysisNo = dialysisNo
  4130. // }
  4131. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4132. utils.ErrorLog("lapseto")
  4133. code = enums.ErrorCodeParamWrong
  4134. return
  4135. }
  4136. lapseto := int64(patientBody["lapseto"].(float64))
  4137. if lapseto <= 0 {
  4138. utils.ErrorLog("lapseto == 0")
  4139. code = enums.ErrorCodeParamWrong
  4140. return
  4141. }
  4142. patient.Lapseto = lapseto
  4143. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4144. utils.ErrorLog("gender")
  4145. code = enums.ErrorCodeParamWrong
  4146. return
  4147. }
  4148. gender := int64(patientBody["gender"].(float64))
  4149. if gender <= 0 {
  4150. utils.ErrorLog("gender <= 0")
  4151. code = enums.ErrorCodeParamWrong
  4152. return
  4153. }
  4154. patient.Gender = gender
  4155. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4156. response_result := patientBody["response_result"].(string)
  4157. patient.ResponseResult = response_result
  4158. }
  4159. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4160. utils.ErrorLog("age")
  4161. code = enums.ErrorCodeParamWrong
  4162. return
  4163. }
  4164. age := int64(patientBody["age"].(float64))
  4165. patient.Age = age
  4166. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4167. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4168. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4169. patient.UserSysBeforeCount = count
  4170. }
  4171. timeLayout := "2006-01-02"
  4172. loc, _ := time.LoadLocation("Local")
  4173. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4174. utils.ErrorLog("birth")
  4175. code = enums.ErrorCodeParamWrong
  4176. return
  4177. }
  4178. birth, _ := patientBody["birth"].(string)
  4179. if len(birth) == 0 {
  4180. utils.ErrorLog("len(birth) == 0")
  4181. code = enums.ErrorCodeParamWrong
  4182. return
  4183. }
  4184. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4185. if err != nil {
  4186. utils.ErrorLog("birthTime")
  4187. code = enums.ErrorCodeParamWrong
  4188. return
  4189. }
  4190. patient.Birthday = birthTime.Unix()
  4191. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4192. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4193. patient.Height = height
  4194. }
  4195. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4196. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4197. patient.MaritalStatus = maritalStatus
  4198. }
  4199. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4200. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4201. patient.Children = children
  4202. }
  4203. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4204. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4205. patient.AdmissionNumber = admissionNumber
  4206. }
  4207. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4208. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4209. patient.ReimbursementWayId = reimbursementWayID
  4210. }
  4211. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4212. healthCareNo := patientBody["healthCareNo"].(string)
  4213. patient.HealthCareNo = healthCareNo
  4214. }
  4215. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4216. utils.ErrorLog("phone")
  4217. code = enums.ErrorCodeParamWrong
  4218. return
  4219. }
  4220. phone := patientBody["phone"].(string)
  4221. if len(phone) == 0 {
  4222. utils.ErrorLog("len(phone) == 0")
  4223. code = enums.ErrorCodeParamWrong
  4224. return
  4225. }
  4226. if !utils.CheckMobile(phone) {
  4227. utils.ErrorLog("!phone")
  4228. code = enums.ErrorCodeMobileFormat
  4229. return
  4230. }
  4231. patient.Phone = phone
  4232. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4233. homeTelephone := patientBody["homeTelephone"].(string)
  4234. patient.HomeTelephone = homeTelephone
  4235. }
  4236. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4237. relativePhone := patientBody["relative_phone"].(string)
  4238. patient.RelativePhone = relativePhone
  4239. }
  4240. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4241. relativeRelations := patientBody["relative_relations"].(string)
  4242. patient.RelativeRelations = relativeRelations
  4243. }
  4244. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4245. homeAddress := patientBody["homeAddress"].(string)
  4246. patient.HomeAddress = homeAddress
  4247. }
  4248. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4249. work := patientBody["work"].(string)
  4250. patient.WorkUnit = work
  4251. }
  4252. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4253. unitAddress := patientBody["unit_address"].(string)
  4254. patient.UnitAddress = unitAddress
  4255. }
  4256. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4257. profession := int64(patientBody["profession"].(float64))
  4258. patient.Profession = profession
  4259. }
  4260. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4261. education := int64(patientBody["education"].(float64))
  4262. patient.EducationLevel = education
  4263. }
  4264. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4265. utils.ErrorLog("source")
  4266. code = enums.ErrorCodeParamWrong
  4267. return
  4268. }
  4269. source := int64(patientBody["source"].(float64))
  4270. if source <= 0 {
  4271. utils.ErrorLog("source <= 0")
  4272. code = enums.ErrorCodeParamWrong
  4273. return
  4274. }
  4275. patient.Source = source
  4276. zb_patient_id := patientBody["zb_patient_id"].(string)
  4277. patient.ZbPatientId = zb_patient_id
  4278. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4279. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4280. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4281. }
  4282. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4283. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4284. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4285. if err == nil {
  4286. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4287. }
  4288. }
  4289. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4290. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4291. patient.FirstDialysisHospital = firstDialysisHospital
  4292. }
  4293. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4294. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4295. if len(thePredialysisCondition) > 0 {
  4296. conditions := make([]string, 0)
  4297. for _, item := range thePredialysisCondition {
  4298. if reflect.TypeOf(item).String() != "string" {
  4299. continue
  4300. }
  4301. condition := item.(string)
  4302. if len(condition) > 0 {
  4303. conditions = append(conditions, condition)
  4304. }
  4305. }
  4306. patient.PredialysisCondition = strings.Join(conditions, ",")
  4307. }
  4308. }
  4309. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4310. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4311. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4312. }
  4313. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4314. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4315. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4316. }
  4317. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4318. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4319. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4320. if err == nil {
  4321. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4322. }
  4323. }
  4324. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4325. partition := int64(patientBody["partition"].(float64))
  4326. patient.PartitionId = partition
  4327. }
  4328. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4329. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4330. patient.BedId = bed
  4331. }
  4332. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4333. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4334. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4335. if err == nil {
  4336. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4337. }
  4338. }
  4339. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4340. blood := int64(patientBody["blood"].(float64))
  4341. patient.BloodType = blood
  4342. }
  4343. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4344. rh := int64(patientBody["rh"].(float64))
  4345. patient.Rh = rh
  4346. }
  4347. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4348. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4349. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4350. if err == nil {
  4351. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4352. }
  4353. }
  4354. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4355. receivingDate := patientBody["receivingDate"].(string)
  4356. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4357. if err == nil {
  4358. patient.ReceivingDate = receivingDateTime.Unix()
  4359. }
  4360. }
  4361. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4362. induction := int64(patientBody["induction"].(float64))
  4363. patient.InductionPeriod = induction
  4364. }
  4365. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4366. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4367. patient.InitialDialysis = initial
  4368. }
  4369. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4370. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4371. patient.TotalDialysis = dialysisTotal
  4372. }
  4373. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4374. thisContagions, _ := patientBody["contagions"].([]interface{})
  4375. if len(thisContagions) > 0 {
  4376. for _, item := range thisContagions {
  4377. if reflect.TypeOf(item).String() != "float64" {
  4378. continue
  4379. }
  4380. contagion := int64(item.(float64))
  4381. if contagion > 0 {
  4382. contagions = append(contagions, contagion)
  4383. }
  4384. }
  4385. }
  4386. }
  4387. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4388. doctor := int64(patientBody["doctor"].(float64))
  4389. patient.AttendingDoctorId = doctor
  4390. }
  4391. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4392. nurse := int64(patientBody["nurse"].(float64))
  4393. patient.HeadNurseId = nurse
  4394. }
  4395. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4396. assessment := patientBody["assessment"].(string)
  4397. patient.Evaluate = assessment
  4398. }
  4399. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4400. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4401. if len(thisDiseases) > 0 {
  4402. for _, item := range thisDiseases {
  4403. if reflect.TypeOf(item).String() != "float64" {
  4404. continue
  4405. }
  4406. disease := int64(item.(float64))
  4407. if disease > 0 {
  4408. diseases = append(diseases, disease)
  4409. }
  4410. }
  4411. }
  4412. }
  4413. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4414. diagnose := patientBody["diagnose"].(string)
  4415. patient.Diagnose = diagnose
  4416. }
  4417. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4418. remark := patientBody["remark"].(string)
  4419. patient.Remark = remark
  4420. }
  4421. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4422. sch_remark := patientBody["sch_remark"].(string)
  4423. patient.SchRemark = sch_remark
  4424. }
  4425. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4426. patient_complains := patientBody["patient_complains"].(string)
  4427. patient.PatientComplains = patient_complains
  4428. }
  4429. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4430. present_history := patientBody["present_history"].(string)
  4431. patient.PresentHistory = present_history
  4432. }
  4433. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4434. past_history := patientBody["past_history"].(string)
  4435. patient.PastHistory = past_history
  4436. }
  4437. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4438. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4439. patient.Temperature = temperature
  4440. }
  4441. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4442. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4443. patient.Pulse = pulse
  4444. }
  4445. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4446. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4447. patient.Respiratory = respiratory
  4448. }
  4449. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4450. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4451. patient.SBP = sbp
  4452. }
  4453. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4454. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4455. patient.DBP = dbp
  4456. }
  4457. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4458. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4459. patient.DialysisAge = dialysis_age
  4460. }
  4461. fmt.Println(patient.DialysisAge)
  4462. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4463. first_treatment_date := patientBody["first_treatment_date"].(string)
  4464. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4465. if err == nil {
  4466. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4467. }
  4468. }
  4469. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4470. expense_kind := int64(patientBody["expense_kind"].(float64))
  4471. patient.ExpenseKind = expense_kind
  4472. }
  4473. fmt.Println(patient.ExpenseKind)
  4474. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4475. tell_phone := patientBody["tell_phone"].(string)
  4476. patient.TellPhone = tell_phone
  4477. }
  4478. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4479. contact_name := patientBody["contact_name"].(string)
  4480. patient.ContactName = contact_name
  4481. }
  4482. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4483. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4484. patient.TrobleShoot = troble_shoot
  4485. }
  4486. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4487. treatment_plan := patientBody["treatment_plan"].(string)
  4488. patient.TreatmentPlan = treatment_plan
  4489. }
  4490. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4491. doctor := int64(patientBody["doctor"].(float64))
  4492. patient.Doctor = doctor
  4493. }
  4494. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4495. record_number := patientBody["record_number"].(string)
  4496. patient.RecordNumber = record_number
  4497. }
  4498. patient_source := int64(patientBody["patient_source"].(float64))
  4499. if patient_source <= 0 {
  4500. utils.ErrorLog("patient_source <= 0")
  4501. code = enums.ErrorCodeParamWrong
  4502. return
  4503. }
  4504. patient.PatientSource = patient_source
  4505. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4506. patient_start_time := patientBody["patient_start_time"].(string)
  4507. var startTime int64
  4508. if len(patient_start_time) > 0 {
  4509. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4510. startTime = theTime.Unix()
  4511. }
  4512. patient.PatientStartTime = startTime
  4513. }
  4514. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4515. patient_end_time := patientBody["patient_end_time"].(string)
  4516. var endTime int64
  4517. if len(patient_end_time) > 0 {
  4518. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4519. endTime = theTime.Unix()
  4520. }
  4521. patient.PatientEndTime = endTime
  4522. }
  4523. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4524. record_number := patientBody["infectious_remark"].(string)
  4525. patient.InfectiousRemark = record_number
  4526. }
  4527. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4528. allergic_history := patientBody["allergic_history"].(string)
  4529. patient.AllergicHistory = allergic_history
  4530. }
  4531. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4532. patient_address := patientBody["patient_address"].(string)
  4533. patient.PatientAddress = patient_address
  4534. }
  4535. if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
  4536. print_date := patientBody["print_date"].(string)
  4537. printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
  4538. if err == nil {
  4539. patient.PrintDate = printDateTime.Unix()
  4540. }
  4541. }
  4542. return
  4543. }
  4544. func (c *PatientApiController) GetPatientsByKeyWord() {
  4545. keyWord := c.GetString("keyword")
  4546. adminUserInfo := c.GetAdminUserInfo()
  4547. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4548. if err != nil {
  4549. utils.ErrorLog(err.Error())
  4550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4551. return
  4552. }
  4553. c.ServeSuccessJSON(map[string]interface{}{
  4554. "patient": patient,
  4555. })
  4556. }
  4557. func (c *PatientApiController) QueryPatientById() {
  4558. id, _ := c.GetInt64("id")
  4559. fmt.Println(id)
  4560. patientInfo := service.QueryPatientById(id)
  4561. c.ServeSuccessJSON(map[string]interface{}{
  4562. "patient": patientInfo,
  4563. })
  4564. return
  4565. }
  4566. func (c *PatientApiController) GetRemindPatientList() {
  4567. page, _ := c.GetInt64("page", 1)
  4568. limit, _ := c.GetInt64("limit", 10)
  4569. adminUserInfo := c.GetAdminUserInfo()
  4570. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4571. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4572. if errcode == gorm.ErrRecordNotFound {
  4573. information, err := service.GetAdminUserRoleInformation(0)
  4574. if err != nil {
  4575. utils.ErrorLog(err.Error())
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4577. return
  4578. }
  4579. c.ServeSuccessJSON(map[string]interface{}{
  4580. "total": total,
  4581. "patients": patients,
  4582. "information": information,
  4583. })
  4584. } else if errcode == nil {
  4585. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4586. if err != nil {
  4587. utils.ErrorLog(err.Error())
  4588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4589. return
  4590. }
  4591. c.ServeSuccessJSON(map[string]interface{}{
  4592. "total": total,
  4593. "patients": patients,
  4594. "information": information,
  4595. })
  4596. }
  4597. }
  4598. func (c *PatientApiController) PostIsOpenRemind() {
  4599. patient_id, _ := c.GetInt64("id", 1)
  4600. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4601. adminUserInfo := c.GetAdminUserInfo()
  4602. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4603. if err == nil {
  4604. c.ServeSuccessJSON(map[string]interface{}{
  4605. "msg": "成功",
  4606. "is_open_remind": is_open_remind,
  4607. })
  4608. } else if err != nil {
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4610. }
  4611. }
  4612. func (c *PatientApiController) GetPatientScheduleOne() {
  4613. id, _ := c.GetInt64("id")
  4614. //查询该病人是否当天是排班
  4615. nowDateTime := time.Now()
  4616. nowDate := nowDateTime.Format("2006-01-02")
  4617. nowDate += " 00:00:00"
  4618. timeLayout := "2006-01-02"
  4619. loc, _ := time.LoadLocation("Local")
  4620. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4621. nowdate := theTime.Unix()
  4622. fmt.Println("nowdate", nowdate)
  4623. adminUser := c.GetAdminUserInfo()
  4624. orgId := adminUser.CurrentOrgId
  4625. fmt.Println("orgid", orgId)
  4626. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4627. if err != nil {
  4628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4629. return
  4630. }
  4631. c.ServeSuccessJSON(map[string]interface{}{
  4632. "scheduls": scheduls,
  4633. })
  4634. }
  4635. func (c *PatientApiController) ExportPatients() {
  4636. dataBody := make(map[string]interface{}, 0)
  4637. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4638. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4639. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4640. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4641. if err != nil {
  4642. utils.ErrorLog(err.Error())
  4643. return
  4644. }
  4645. utils.ErrorLog("%v", dataBody)
  4646. export_time := time.Now().Unix()
  4647. var patients []*models.Patients
  4648. var total_patients []interface{}
  4649. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4650. tempPatients := dataBody["patients"].([]interface{})
  4651. total_patients = tempPatients
  4652. for index, patientMap := range tempPatients {
  4653. patientNameM := patientMap.(map[string]interface{})
  4654. var patient models.Patients
  4655. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4656. utils.ErrorLog("name")
  4657. return
  4658. }
  4659. name, _ := patientNameM["name"].(string)
  4660. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4661. err_log := models.ExportErrLog{
  4662. LogType: 1,
  4663. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4664. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4665. Status: 1,
  4666. CreateTime: time.Now().Unix(),
  4667. UpdateTime: time.Now().Unix(),
  4668. ExportTime: export_time,
  4669. }
  4670. service.CreateExportErrLog(&err_log)
  4671. continue
  4672. }
  4673. patient.Name = name
  4674. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4675. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4676. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4677. err_log := models.ExportErrLog{
  4678. LogType: 1,
  4679. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4680. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4681. Status: 1,
  4682. CreateTime: time.Now().Unix(),
  4683. UpdateTime: time.Now().Unix(),
  4684. ExportTime: export_time,
  4685. }
  4686. service.CreateExportErrLog(&err_log)
  4687. continue
  4688. } else {
  4689. patient.Gender = gender
  4690. }
  4691. }
  4692. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4693. phone, _ := patientNameM["phone"].(string)
  4694. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4695. if len(phone) == 0 {
  4696. err_log := models.ExportErrLog{
  4697. LogType: 1,
  4698. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4699. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4700. Status: 1,
  4701. CreateTime: time.Now().Unix(),
  4702. UpdateTime: time.Now().Unix(),
  4703. ExportTime: export_time,
  4704. }
  4705. service.CreateExportErrLog(&err_log)
  4706. continue
  4707. } else {
  4708. err_log := models.ExportErrLog{
  4709. LogType: 1,
  4710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4711. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4712. Status: 1,
  4713. CreateTime: time.Now().Unix(),
  4714. UpdateTime: time.Now().Unix(),
  4715. ExportTime: export_time,
  4716. }
  4717. service.CreateExportErrLog(&err_log)
  4718. continue
  4719. }
  4720. } else {
  4721. //var tempPatient *models.Patients
  4722. //for _, item := range all_patient {
  4723. // if item.Phone == phone {
  4724. // tempPatient = item
  4725. // }
  4726. //}
  4727. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4728. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4729. if count >= 1 {
  4730. err_log := models.ExportErrLog{
  4731. LogType: 1,
  4732. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4733. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4734. Status: 1,
  4735. CreateTime: time.Now().Unix(),
  4736. UpdateTime: time.Now().Unix(),
  4737. ExportTime: export_time,
  4738. }
  4739. service.CreateExportErrLog(&err_log)
  4740. continue
  4741. }
  4742. patient.Phone = phone
  4743. }
  4744. }
  4745. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4746. id_card_no, _ := patientNameM["id_card_no"].(string)
  4747. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4748. if len(id_card_no) == 0 {
  4749. err_log := models.ExportErrLog{
  4750. LogType: 1,
  4751. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4752. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4753. Status: 1,
  4754. CreateTime: time.Now().Unix(),
  4755. UpdateTime: time.Now().Unix(),
  4756. ExportTime: export_time,
  4757. }
  4758. service.CreateExportErrLog(&err_log)
  4759. continue
  4760. } else {
  4761. err_log := models.ExportErrLog{
  4762. LogType: 1,
  4763. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4764. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4765. Status: 1,
  4766. CreateTime: time.Now().Unix(),
  4767. UpdateTime: time.Now().Unix(),
  4768. ExportTime: export_time,
  4769. }
  4770. service.CreateExportErrLog(&err_log)
  4771. continue
  4772. }
  4773. } else {
  4774. //var tempPatient *models.Patients
  4775. //for _, item := range all_patient {
  4776. // if item.IdCardNo == id_card_no {
  4777. // tempPatient = item
  4778. // }
  4779. //}
  4780. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4781. if count >= 1 {
  4782. //if tempPatient != nil && tempPatient.ID > 0 {
  4783. err_log := models.ExportErrLog{
  4784. LogType: 1,
  4785. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4786. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4787. Status: 1,
  4788. CreateTime: time.Now().Unix(),
  4789. UpdateTime: time.Now().Unix(),
  4790. ExportTime: export_time,
  4791. }
  4792. service.CreateExportErrLog(&err_log)
  4793. continue
  4794. }
  4795. //}
  4796. patient.IdCardNo = id_card_no
  4797. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4798. if GetBirthDay(id_card_no) == nil {
  4799. patient.Birthday = 0
  4800. } else {
  4801. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4802. }
  4803. }
  4804. }
  4805. fmt.Println("111112222")
  4806. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4807. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4808. timeLayout := "2006/01/02"
  4809. loc, _ := time.LoadLocation("Local")
  4810. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4811. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4812. if len(first_treatment_date) == 0 {
  4813. err_log := models.ExportErrLog{
  4814. LogType: 1,
  4815. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4816. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4817. Status: 1,
  4818. CreateTime: time.Now().Unix(),
  4819. UpdateTime: time.Now().Unix(),
  4820. ExportTime: export_time,
  4821. }
  4822. service.CreateExportErrLog(&err_log)
  4823. continue
  4824. } else {
  4825. err_log := models.ExportErrLog{
  4826. LogType: 1,
  4827. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4828. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4829. Status: 1,
  4830. CreateTime: time.Now().Unix(),
  4831. UpdateTime: time.Now().Unix(),
  4832. ExportTime: export_time,
  4833. }
  4834. service.CreateExportErrLog(&err_log)
  4835. continue
  4836. }
  4837. } else {
  4838. if len(first_treatment_date) == 0 {
  4839. err_log := models.ExportErrLog{
  4840. LogType: 1,
  4841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4842. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4843. Status: 1,
  4844. CreateTime: time.Now().Unix(),
  4845. UpdateTime: time.Now().Unix(),
  4846. ExportTime: export_time,
  4847. }
  4848. service.CreateExportErrLog(&err_log)
  4849. continue
  4850. } else {
  4851. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4852. err_log := models.ExportErrLog{
  4853. LogType: 1,
  4854. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4855. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4856. Status: 1,
  4857. CreateTime: time.Now().Unix(),
  4858. UpdateTime: time.Now().Unix(),
  4859. ExportTime: export_time,
  4860. }
  4861. service.CreateExportErrLog(&err_log)
  4862. continue
  4863. } else {
  4864. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4865. }
  4866. }
  4867. }
  4868. }
  4869. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4870. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4871. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4872. err_log := models.ExportErrLog{
  4873. LogType: 1,
  4874. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4875. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4876. Status: 1,
  4877. CreateTime: time.Now().Unix(),
  4878. UpdateTime: time.Now().Unix(),
  4879. ExportTime: export_time,
  4880. }
  4881. service.CreateExportErrLog(&err_log)
  4882. continue
  4883. } else if source == 3 {
  4884. err_log := models.ExportErrLog{
  4885. LogType: 1,
  4886. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4887. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4888. Status: 1,
  4889. CreateTime: time.Now().Unix(),
  4890. UpdateTime: time.Now().Unix(),
  4891. ExportTime: export_time,
  4892. }
  4893. service.CreateExportErrLog(&err_log)
  4894. continue
  4895. } else {
  4896. patient.Source = source
  4897. }
  4898. }
  4899. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4900. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4901. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4902. err_log := models.ExportErrLog{
  4903. LogType: 1,
  4904. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4905. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4906. Status: 1,
  4907. CreateTime: time.Now().Unix(),
  4908. UpdateTime: time.Now().Unix(),
  4909. ExportTime: export_time,
  4910. }
  4911. service.CreateExportErrLog(&err_log)
  4912. continue
  4913. } else if lapseto == 3 {
  4914. err_log := models.ExportErrLog{
  4915. LogType: 1,
  4916. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4917. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4918. Status: 1,
  4919. CreateTime: time.Now().Unix(),
  4920. UpdateTime: time.Now().Unix(),
  4921. ExportTime: export_time,
  4922. }
  4923. service.CreateExportErrLog(&err_log)
  4924. continue
  4925. } else {
  4926. patient.Lapseto = lapseto
  4927. }
  4928. }
  4929. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4930. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4931. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4932. err_log := models.ExportErrLog{
  4933. LogType: 1,
  4934. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4935. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4936. Status: 1,
  4937. CreateTime: time.Now().Unix(),
  4938. UpdateTime: time.Now().Unix(),
  4939. ExportTime: export_time,
  4940. }
  4941. service.CreateExportErrLog(&err_log)
  4942. continue
  4943. } else if is_infectious == 3 {
  4944. err_log := models.ExportErrLog{
  4945. LogType: 1,
  4946. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4947. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4948. Status: 1,
  4949. CreateTime: time.Now().Unix(),
  4950. UpdateTime: time.Now().Unix(),
  4951. ExportTime: export_time,
  4952. }
  4953. service.CreateExportErrLog(&err_log)
  4954. continue
  4955. } else {
  4956. patient.IsInfectious = is_infectious
  4957. }
  4958. }
  4959. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4960. var contagions []int64
  4961. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4962. if len(thisContagions) > 0 {
  4963. for _, item := range thisContagions {
  4964. if reflect.TypeOf(item).String() != "float64" {
  4965. continue
  4966. }
  4967. contagion := int64(item.(float64))
  4968. if contagion > 0 {
  4969. contagions = append(contagions, contagion)
  4970. }
  4971. }
  4972. }
  4973. patient.ContagionIds = contagions
  4974. }
  4975. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4976. diagnose, _ := patientNameM["diagnose"].(string)
  4977. patient.Diagnose = diagnose
  4978. }
  4979. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4980. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4981. var tempPatient *models.Patients
  4982. for _, item := range all_patient {
  4983. if item.DialysisNo == dialysis_no {
  4984. tempPatient = item
  4985. }
  4986. }
  4987. if tempPatient != nil && tempPatient.ID > 0 {
  4988. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4989. } else {
  4990. patient.DialysisNo = dialysis_no
  4991. }
  4992. }
  4993. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4994. height, _ := patientNameM["height"].(string)
  4995. heights, _ := strconv.ParseFloat(height, 64)
  4996. patient.Height = int64(heights)
  4997. }
  4998. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4999. home_address, _ := patientNameM["home_address"].(string)
  5000. patient.HomeAddress = home_address
  5001. }
  5002. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5003. dry_weight, _ := patientNameM["dry_weight"].(string)
  5004. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5005. patient.DryWeight = dry_weights
  5006. }
  5007. patient.CreatedTime = time.Now().Unix()
  5008. patient.UpdatedTime = time.Now().Unix()
  5009. patient.Status = 1
  5010. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5011. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5012. patient.IsExcelExport = 1
  5013. patient.PatientType = 1
  5014. patients = append(patients, &patient)
  5015. }
  5016. }
  5017. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5018. if len(patients) > 0 {
  5019. for _, item := range patients {
  5020. hans := item.Name // 要转换的汉字字符串
  5021. // 创建一个拼音转换器
  5022. p := pinyin.NewArgs()
  5023. // 将汉字转为拼音
  5024. pinyinSlice := pinyin.Pinyin(hans, p)
  5025. // 输出拼音
  5026. fmt.Println("Pinyin:", pinyinSlice)
  5027. // 获取首字母
  5028. firstLetter := ""
  5029. for _, py := range pinyinSlice {
  5030. if len(py) > 0 {
  5031. firstLetter += string(py[0][0])
  5032. }
  5033. }
  5034. item.FirstLetter = firstLetter
  5035. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5036. }
  5037. log := models.ExportLog{
  5038. LogType: 1,
  5039. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5040. TotalNum: int64(len(total_patients)),
  5041. FailNum: int64(len(errLogs)),
  5042. SuccessNum: int64(len(patients)),
  5043. CreateTime: time.Now().Unix(),
  5044. UpdateTime: time.Now().Unix(),
  5045. ExportTime: export_time,
  5046. Status: 1,
  5047. }
  5048. service.CreateExportLog(&log)
  5049. c.ServeSuccessJSON(map[string]interface{}{
  5050. "msg": "导入成功",
  5051. "total_num": len(total_patients),
  5052. "success_num": len(patients),
  5053. "fail_num": int64(len(errLogs)),
  5054. })
  5055. } else {
  5056. log := models.ExportLog{
  5057. LogType: 1,
  5058. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5059. TotalNum: int64(len(total_patients)),
  5060. FailNum: int64(len(errLogs)),
  5061. SuccessNum: int64(len(patients)),
  5062. CreateTime: time.Now().Unix(),
  5063. UpdateTime: time.Now().Unix(),
  5064. ExportTime: export_time,
  5065. Status: 1,
  5066. }
  5067. service.CreateExportLog(&log)
  5068. c.ServeSuccessJSON(map[string]interface{}{
  5069. "msg": "导入成功",
  5070. "total_num": len(total_patients),
  5071. "success_num": len(patients),
  5072. "fail_num": int64(len(errLogs)),
  5073. })
  5074. }
  5075. }
  5076. func GetBirthDay(IDCardNo string) *time.Time {
  5077. dayStr := IDCardNo[6:14]
  5078. birthDay, err := time.Parse("20060102", dayStr)
  5079. if err != nil {
  5080. fmt.Println(err)
  5081. return nil
  5082. }
  5083. return &birthDay
  5084. }
  5085. func IsIdCard(id string) (res bool) {
  5086. id = strings.ToUpper(id)
  5087. if len(id) != 15 && len(id) != 18 {
  5088. fmt.Println("1111111")
  5089. return false
  5090. }
  5091. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5092. if !r.MatchString(id) {
  5093. fmt.Println("222222")
  5094. return false
  5095. }
  5096. if len(id) == 15 {
  5097. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5098. if tm2.Unix() == 0 {
  5099. fmt.Println("44444443333")
  5100. return false
  5101. }
  5102. return true
  5103. } else {
  5104. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5105. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5106. fmt.Println(tm2.Unix())
  5107. if tm2.Unix() == 0 {
  5108. fmt.Println("44445555555")
  5109. return false
  5110. }
  5111. //检验18位身份证的校验码是否正确。
  5112. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5113. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5114. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5115. sign := 0
  5116. for k, v := range arr_int {
  5117. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5118. sign += int_temp * v
  5119. }
  5120. n := sign % 11
  5121. val_num := arr_ch[n]
  5122. if val_num != string([]byte(id)[17:18]) {
  5123. fmt.Println("5556666666")
  5124. return false
  5125. }
  5126. return true
  5127. }
  5128. }
  5129. func (c *PatientApiController) SaveEditAdvices() {
  5130. adminInfo := c.GetAdminUserInfo()
  5131. orgid := adminInfo.CurrentOrgId
  5132. startTime := c.GetString("start_time")
  5133. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5134. groupno, _ := c.GetInt64("groupno")
  5135. fmt.Println("组", groupno)
  5136. date, _ := c.GetInt64("date")
  5137. fmt.Println("date", date)
  5138. patient_id, _ := c.GetInt64("patient_id")
  5139. fmt.Println("paitent_id", patient_id)
  5140. advice := models.XtDoctorAdvice{
  5141. StartTime: theTime.Unix(),
  5142. }
  5143. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5144. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5145. redis := service.RedisClient()
  5146. redis.Set(key, "", time.Second)
  5147. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5148. redis.Set(keyOne, "", time.Second)
  5149. scheduleTime := theTime.Format("2006-01-02")
  5150. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5151. fmt.Println("keyFour323223323232323232", keyFour)
  5152. redis.Set(keyFour, "", time.Second)
  5153. defer redis.Close()
  5154. if err != nil {
  5155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5156. return
  5157. }
  5158. c.ServeSuccessJSON(map[string]interface{}{
  5159. "advice": advice,
  5160. })
  5161. }
  5162. func (c *PatientApiController) GetMaxDialysisNo() {
  5163. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5164. c.ServeSuccessJSON(map[string]interface{}{
  5165. "dialysis_no": dialysisNo,
  5166. })
  5167. }
  5168. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5169. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5170. var tempPatient *models.Patients
  5171. for _, item := range patients {
  5172. if item.DialysisNo == dialysisNo2 {
  5173. tempPatient = item
  5174. }
  5175. }
  5176. if tempPatient == nil || tempPatient.ID == 0 {
  5177. return dialysisNo2
  5178. }
  5179. return GenerateDialysisNoTwo(patients)
  5180. }
  5181. func (c *PatientApiController) GetBanner() {
  5182. orgId := c.GetAdminUserInfo().CurrentOrgId
  5183. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5184. if errcodes == gorm.ErrRecordNotFound {
  5185. information, err := service.GetAdminUserRoleInformation(0)
  5186. if err != nil {
  5187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5188. return
  5189. }
  5190. c.ServeSuccessJSON(map[string]interface{}{
  5191. "information": information,
  5192. })
  5193. } else if errcodes == nil {
  5194. information, err := service.GetAdminUserRoleInformation(orgId)
  5195. if err != nil {
  5196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5197. return
  5198. }
  5199. c.ServeSuccessJSON(map[string]interface{}{
  5200. "information": information,
  5201. })
  5202. }
  5203. }
  5204. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5205. patient_id, _ := c.GetInt64("id", 0)
  5206. page, _ := c.GetInt64("page", 0)
  5207. limit, _ := c.GetInt64("limit", 0)
  5208. if patient_id <= 0 {
  5209. c.ServeSuccessJSON(map[string]interface{}{
  5210. "solutions": nil,
  5211. })
  5212. return
  5213. }
  5214. if page <= 0 {
  5215. page = 1
  5216. }
  5217. if limit <= 0 {
  5218. limit = 10
  5219. }
  5220. adminUserInfo := c.GetAdminUserInfo()
  5221. //获取该患者分组的透析模式
  5222. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5223. for _, item := range list {
  5224. //获取该模式最新的1条数据
  5225. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5226. //更新状态值
  5227. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5228. }
  5229. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5230. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5231. if err != nil {
  5232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5233. return
  5234. }
  5235. c.ServeSuccessJSON(map[string]interface{}{
  5236. "solutions": solution,
  5237. "total": total,
  5238. "stockType": stockType,
  5239. })
  5240. }
  5241. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5242. patient_id, _ := c.GetInt64("patient_id")
  5243. mode_id, _ := c.GetInt64("mode_id")
  5244. page, _ := c.GetInt64("page")
  5245. limit, _ := c.GetInt64("limit")
  5246. orgId := c.GetAdminUserInfo().CurrentOrgId
  5247. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5248. if err != nil {
  5249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5250. return
  5251. }
  5252. c.ServeSuccessJSON(map[string]interface{}{
  5253. "list": list,
  5254. "total": total,
  5255. })
  5256. }
  5257. func (c *PatientApiController) SaveFallOutBedPrint() {
  5258. adminInfo := c.GetAdminUserInfo()
  5259. orgid := adminInfo.CurrentOrgId
  5260. dataBody := make(map[string]interface{}, 0)
  5261. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5262. fmt.Println("err", err)
  5263. content := dataBody["content"].(string)
  5264. outPrint := models.XtFallOutPrint{
  5265. UserOrgId: orgid,
  5266. Content: content,
  5267. Status: 1,
  5268. Ctime: time.Now().Unix(),
  5269. Mtime: time.Now().Unix(),
  5270. }
  5271. //查询该机构是否存在
  5272. list, err := service.GetOutPrintList(orgid)
  5273. if list.ID == 0 {
  5274. service.CreateFallOutBedPrint(outPrint)
  5275. }
  5276. if list.ID > 0 {
  5277. service.UpdateFallOutBedPrint(list.ID, content)
  5278. }
  5279. c.ServeSuccessJSON(map[string]interface{}{
  5280. "list": list,
  5281. })
  5282. }
  5283. func (c *PatientApiController) GetFallOutBedPrintList() {
  5284. adminInfo := c.GetAdminUserInfo()
  5285. orgid := adminInfo.CurrentOrgId
  5286. list, _ := service.GetFallOutBedPrintList(orgid)
  5287. c.ServeSuccessJSON(map[string]interface{}{
  5288. "list": list,
  5289. })
  5290. }
  5291. func (c *PatientApiController) SaveFilterInformed() {
  5292. adminInfo := c.GetAdminUserInfo()
  5293. orgid := adminInfo.CurrentOrgId
  5294. dataBody := make(map[string]interface{}, 0)
  5295. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5296. fmt.Println("err", err)
  5297. content := dataBody["content"].(string)
  5298. informed := models.XtFilterInformed{
  5299. UserOrgId: orgid,
  5300. Content: content,
  5301. Status: 1,
  5302. Ctime: time.Now().Unix(),
  5303. Mtime: time.Now().Unix(),
  5304. }
  5305. filterInformed, _ := service.GetFilterInformed(orgid)
  5306. if filterInformed.ID == 0 {
  5307. service.CreateFilterInformed(informed)
  5308. }
  5309. if filterInformed.ID > 0 {
  5310. service.UpdateFilterInformed(filterInformed.ID, content)
  5311. }
  5312. c.ServeSuccessJSON(map[string]interface{}{
  5313. "informed": informed,
  5314. })
  5315. }
  5316. func (c *PatientApiController) GetFilterInformed() {
  5317. adminInfo := c.GetAdminUserInfo()
  5318. orgid := adminInfo.CurrentOrgId
  5319. filterInformed, _ := service.GetFilterInformed(orgid)
  5320. c.ServeSuccessJSON(map[string]interface{}{
  5321. "list": filterInformed,
  5322. })
  5323. }
  5324. func (c *PatientApiController) SaveProfundaInformed() {
  5325. adminInfo := c.GetAdminUserInfo()
  5326. orgid := adminInfo.CurrentOrgId
  5327. dataBody := make(map[string]interface{}, 0)
  5328. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5329. fmt.Println("err", err)
  5330. content := dataBody["content"].(string)
  5331. informed := models.XtProfundaInformed{
  5332. UserOrgId: orgid,
  5333. Content: content,
  5334. Status: 1,
  5335. Ctime: time.Now().Unix(),
  5336. Mtime: time.Now().Unix(),
  5337. }
  5338. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5339. if profundaInformed.ID == 0 {
  5340. service.CreateProfundaInformed(informed)
  5341. }
  5342. if profundaInformed.ID > 0 {
  5343. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5344. }
  5345. c.ServeSuccessJSON(map[string]interface{}{
  5346. "list": profundaInformed,
  5347. })
  5348. }
  5349. func (c *PatientApiController) GetProfundaInformed() {
  5350. adminInfo := c.GetAdminUserInfo()
  5351. orgid := adminInfo.CurrentOrgId
  5352. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5353. c.ServeSuccessJSON(map[string]interface{}{
  5354. "list": profundaInformed,
  5355. })
  5356. }
  5357. func (c *PatientApiController) SaveArterOvenous() {
  5358. adminInfo := c.GetAdminUserInfo()
  5359. orgid := adminInfo.CurrentOrgId
  5360. dataBody := make(map[string]interface{}, 0)
  5361. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5362. fmt.Println("err", err)
  5363. content := dataBody["content"].(string)
  5364. arterOvenous := models.XtArterOvenous{
  5365. UserOrgId: orgid,
  5366. Content: content,
  5367. Status: 1,
  5368. Ctime: time.Now().Unix(),
  5369. Mtime: time.Now().Unix(),
  5370. }
  5371. list, _ := service.GetArterOvenousList(orgid)
  5372. if list.ID == 0 {
  5373. service.CreateArterOvernous(arterOvenous)
  5374. }
  5375. if list.ID > 0 {
  5376. service.UpdateArterOvernous(list.ID, content)
  5377. }
  5378. c.ServeSuccessJSON(map[string]interface{}{
  5379. "list": list,
  5380. })
  5381. }
  5382. func (c *PatientApiController) GetArterOverNous() {
  5383. adminInfo := c.GetAdminUserInfo()
  5384. orgid := adminInfo.CurrentOrgId
  5385. list, _ := service.GetArterOvenousList(orgid)
  5386. c.ServeSuccessJSON(map[string]interface{}{
  5387. "list": list,
  5388. })
  5389. }
  5390. func (c *PatientApiController) SaveHighRikInformed() {
  5391. adminInfo := c.GetAdminUserInfo()
  5392. orgid := adminInfo.CurrentOrgId
  5393. dataBody := make(map[string]interface{}, 0)
  5394. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5395. fmt.Println("err", err)
  5396. content := dataBody["content"].(string)
  5397. risk := models.XtHightRisk{
  5398. UserOrgId: orgid,
  5399. Content: content,
  5400. Status: 1,
  5401. Ctime: time.Now().Unix(),
  5402. Mtime: time.Now().Unix(),
  5403. }
  5404. highRik, _ := service.GetHightRikInformed(orgid)
  5405. if highRik.ID == 0 {
  5406. service.CreateHighRik(risk)
  5407. }
  5408. if highRik.ID > 0 {
  5409. service.UpdateHighRik(highRik.ID, content)
  5410. }
  5411. c.ServeSuccessJSON(map[string]interface{}{
  5412. "list": risk,
  5413. })
  5414. }
  5415. func (c *PatientApiController) GetHighRiskInformed() {
  5416. orgId := c.GetAdminUserInfo().CurrentOrgId
  5417. rikInformed, _ := service.GetHightRikInformed(orgId)
  5418. c.ServeSuccessJSON(map[string]interface{}{
  5419. "list": rikInformed,
  5420. })
  5421. }
  5422. func (c *PatientApiController) SaveAnticoagulation() {
  5423. orgId := c.GetAdminUserInfo().CurrentOrgId
  5424. dataBody := make(map[string]interface{}, 0)
  5425. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5426. fmt.Println("err", err)
  5427. content := dataBody["content"].(string)
  5428. auticoagutionPrint := models.XtAuticoagutionPrint{
  5429. Content: content,
  5430. UserOrgId: orgId,
  5431. Status: 1,
  5432. Ctime: time.Now().Unix(),
  5433. Mtime: time.Now().Unix(),
  5434. }
  5435. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5436. if anticoagulation.ID == 0 {
  5437. service.CreateAnticoagulation(auticoagutionPrint)
  5438. }
  5439. if anticoagulation.ID > 0 {
  5440. service.UpdateAnticoagulation(anticoagulation.ID, content)
  5441. }
  5442. c.ServeSuccessJSON(map[string]interface{}{
  5443. "list": auticoagutionPrint,
  5444. })
  5445. }
  5446. func (c *PatientApiController) GetAnticoagulationInformed() {
  5447. orgId := c.GetAdminUserInfo().CurrentOrgId
  5448. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5449. c.ServeSuccessJSON(map[string]interface{}{
  5450. "list": anticoagulation,
  5451. })
  5452. }
  5453. func (c *PatientApiController) SaveCriticalInfomed() {
  5454. orgId := c.GetAdminUserInfo().CurrentOrgId
  5455. dataBody := make(map[string]interface{}, 0)
  5456. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5457. fmt.Println("err", err)
  5458. content := dataBody["content"].(string)
  5459. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  5460. UserOrgId: orgId,
  5461. Content: content,
  5462. Status: 1,
  5463. Ctime: time.Now().Unix(),
  5464. Mtime: time.Now().Unix(),
  5465. }
  5466. infomed, _ := service.GetCriticalInfomed(orgId)
  5467. if infomed.ID == 0 {
  5468. service.CreatedCriticalInfomed(criticalinfomedPrint)
  5469. }
  5470. if infomed.ID > 0 {
  5471. service.UpdateCriticalInfomed(infomed.ID, content)
  5472. }
  5473. c.ServeSuccessJSON(map[string]interface{}{
  5474. "list": criticalinfomedPrint,
  5475. })
  5476. }
  5477. func (c *PatientApiController) GetCriticalInformed() {
  5478. orgId := c.GetAdminUserInfo().CurrentOrgId
  5479. infomed, _ := service.GetCriticalInfomed(orgId)
  5480. c.ServeSuccessJSON(map[string]interface{}{
  5481. "list": infomed,
  5482. })
  5483. }
  5484. func (c *PatientApiController) SaveHemoperfusionInformed() {
  5485. orgId := c.GetAdminUserInfo().CurrentOrgId
  5486. dataBody := make(map[string]interface{}, 0)
  5487. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5488. fmt.Println("err", err)
  5489. content := dataBody["content"].(string)
  5490. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  5491. UserOrgId: orgId,
  5492. Content: content,
  5493. Status: 1,
  5494. Ctime: time.Now().Unix(),
  5495. Mtime: time.Now().Unix(),
  5496. }
  5497. informed, _ := service.GetHemoperfusionInformed(orgId)
  5498. if informed.ID == 0 {
  5499. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  5500. }
  5501. if informed.ID > 0 {
  5502. service.UpdateHemoperfusionInformed(informed.ID, content)
  5503. }
  5504. c.ServeSuccessJSON(map[string]interface{}{
  5505. "list": hemoperfusionmedPrint,
  5506. })
  5507. }
  5508. func (c *PatientApiController) GetHemoperfusionInformed() {
  5509. orgId := c.GetAdminUserInfo().CurrentOrgId
  5510. informed, _ := service.GetHemoperfusionInformed(orgId)
  5511. c.ServeSuccessJSON(map[string]interface{}{
  5512. "list": informed,
  5513. })
  5514. }
  5515. func (c *PatientApiController) SaveBringInformed() {
  5516. orgId := c.GetAdminUserInfo().CurrentOrgId
  5517. dataBody := make(map[string]interface{}, 0)
  5518. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5519. fmt.Println("err", err)
  5520. content := dataBody["content"].(string)
  5521. bringinformedPrint := models.XtBringinformedPrint{
  5522. Content: content,
  5523. UserOrgId: orgId,
  5524. Ctime: time.Now().Unix(),
  5525. Mtime: time.Now().Unix(),
  5526. Status: 1,
  5527. }
  5528. informed, _ := service.GetBringInformed(orgId)
  5529. if informed.ID == 0 {
  5530. service.CreateBringInformed(bringinformedPrint)
  5531. }
  5532. if informed.ID > 0 {
  5533. service.UpdateBringInformed(informed.ID, content)
  5534. }
  5535. c.ServeSuccessJSON(map[string]interface{}{
  5536. "list": bringinformedPrint,
  5537. })
  5538. }
  5539. func (c *PatientApiController) GetInformedContsent() {
  5540. orgId := c.GetAdminUserInfo().CurrentOrgId
  5541. informed, _ := service.GetBringInformed(orgId)
  5542. c.ServeSuccessJSON(map[string]interface{}{
  5543. "list": informed,
  5544. })
  5545. }
  5546. func (c *PatientApiController) SaveCatheterization() {
  5547. orgId := c.GetAdminUserInfo().CurrentOrgId
  5548. dataBody := make(map[string]interface{}, 0)
  5549. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5550. fmt.Println("err", err)
  5551. content := dataBody["content"].(string)
  5552. cathetercationPrint := models.XtCathetercationPrint{
  5553. UserOrgId: orgId,
  5554. Content: content,
  5555. Status: 1,
  5556. Ctime: time.Now().Unix(),
  5557. Mtime: time.Now().Unix(),
  5558. }
  5559. catheterization, _ := service.GetCatheterization(orgId)
  5560. if cathetercationPrint.ID == 0 {
  5561. service.CreateCatheteriztion(cathetercationPrint)
  5562. }
  5563. if cathetercationPrint.ID > 0 {
  5564. service.UpdateCatheterization(catheterization.ID, content)
  5565. }
  5566. c.ServeSuccessJSON(map[string]interface{}{
  5567. "list": catheterization,
  5568. })
  5569. }
  5570. func (c *PatientApiController) GetCatheterization() {
  5571. orgId := c.GetAdminUserInfo().CurrentOrgId
  5572. catheterization, _ := service.GetCatheterization(orgId)
  5573. c.ServeSuccessJSON(map[string]interface{}{
  5574. "list": catheterization,
  5575. })
  5576. }
  5577. func (c *PatientApiController) SaveDialyzerInformed() {
  5578. orgId := c.GetAdminUserInfo().CurrentOrgId
  5579. dataBody := make(map[string]interface{}, 0)
  5580. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5581. fmt.Println("err", err)
  5582. content := dataBody["content"].(string)
  5583. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  5584. UserOrgId: orgId,
  5585. Content: content,
  5586. Status: 1,
  5587. Ctime: time.Now().Unix(),
  5588. Mtime: time.Now().Unix(),
  5589. }
  5590. informed, _ := service.GetDialyzerInformed(orgId)
  5591. if informed.ID == 0 {
  5592. service.CreateDialyzerInformed(dialyszerinformedPrint)
  5593. }
  5594. if informed.ID > 0 {
  5595. service.UpdateDialyszerInformed(informed.ID, content)
  5596. }
  5597. c.ServeSuccessJSON(map[string]interface{}{
  5598. "list": dialyszerinformedPrint,
  5599. })
  5600. }
  5601. func (c *PatientApiController) GetDialyzerInformed() {
  5602. orgId := c.GetAdminUserInfo().CurrentOrgId
  5603. informed, _ := service.GetDialyzerInformed(orgId)
  5604. c.ServeSuccessJSON(map[string]interface{}{
  5605. "list": informed,
  5606. })
  5607. }
  5608. func (c *PatientApiController) SaveTheapyInformed() {
  5609. orgId := c.GetAdminUserInfo().CurrentOrgId
  5610. dataBody := make(map[string]interface{}, 0)
  5611. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5612. fmt.Println("err", err)
  5613. content := dataBody["content"].(string)
  5614. theapyinformedPrint := models.XtTheapyinformedPrint{
  5615. Content: content,
  5616. UserOrgId: orgId,
  5617. Status: 1,
  5618. Ctime: time.Now().Unix(),
  5619. Mtime: time.Now().Unix(),
  5620. }
  5621. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5622. if theapyInformed.ID == 0 {
  5623. service.CreateTheapyInformed(theapyinformedPrint)
  5624. }
  5625. if theapyInformed.ID > 0 {
  5626. service.UpdateTheaphInformed(theapyInformed.ID, content)
  5627. }
  5628. c.ServeSuccessJSON(map[string]interface{}{
  5629. "list": theapyinformedPrint,
  5630. })
  5631. }
  5632. func (c *PatientApiController) GetTherapyInformed() {
  5633. orgId := c.GetAdminUserInfo().CurrentOrgId
  5634. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5635. c.ServeSuccessJSON(map[string]interface{}{
  5636. "list": theapyInformed,
  5637. })
  5638. }
  5639. func (c *PatientApiController) SaveMedicalHistory() {
  5640. orgId := c.GetAdminUserInfo().CurrentOrgId
  5641. dataBody := make(map[string]interface{}, 0)
  5642. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5643. fmt.Println("err", err)
  5644. content := dataBody["content"].(string)
  5645. patient_id := int64(dataBody["patient_id"].(float64))
  5646. medicalHistory := models.XtMedicalHistory{
  5647. UserOrgId: orgId,
  5648. PatientId: patient_id,
  5649. Ctime: time.Now().Unix(),
  5650. Mtime: 0,
  5651. Status: 1,
  5652. Content: content,
  5653. }
  5654. //
  5655. history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
  5656. if history.ID > 0 {
  5657. service.UpdatePatientMedicalHistory(history.ID, content)
  5658. }
  5659. if history.ID == 0 {
  5660. service.CreatePatientMedicalHistory(medicalHistory)
  5661. }
  5662. c.ServeSuccessJSON(map[string]interface{}{
  5663. "medicalHistory": medicalHistory,
  5664. })
  5665. }
  5666. func (c *PatientApiController) SavePatientCritaicalInformed() {
  5667. orgId := c.GetAdminUserInfo().CurrentOrgId
  5668. dataBody := make(map[string]interface{}, 0)
  5669. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5670. fmt.Println("err", err)
  5671. content := dataBody["content"].(string)
  5672. patientCritical := models.XtPatientCritical{
  5673. UserOrgId: orgId,
  5674. Content: content,
  5675. Status: 1,
  5676. Ctime: time.Now().Unix(),
  5677. Mtime: time.Now().Unix(),
  5678. }
  5679. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  5680. if patientCritaicalInformed.ID == 0 {
  5681. service.CreatePatientCritaicalinformed(patientCritical)
  5682. }
  5683. if patientCritaicalInformed.ID > 0 {
  5684. service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
  5685. }
  5686. c.ServeSuccessJSON(map[string]interface{}{
  5687. "patientCritical": patientCritical,
  5688. })
  5689. }
  5690. func (c *PatientApiController) GetPatientCriticalList() {
  5691. orgId := c.GetAdminUserInfo().CurrentOrgId
  5692. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  5693. c.ServeSuccessJSON(map[string]interface{}{
  5694. "patientCritaicalInformed": patientCritaicalInformed,
  5695. })
  5696. }
  5697. func (c *PatientApiController) SavePatientCriticalInformedOne() {
  5698. orgId := c.GetAdminUserInfo().CurrentOrgId
  5699. dataBody := make(map[string]interface{}, 0)
  5700. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5701. fmt.Println("err", err)
  5702. content := dataBody["content"].(string)
  5703. criticalOne := models.XtPatientCriticalOne{
  5704. UserOrgId: orgId,
  5705. Content: content,
  5706. Status: 1,
  5707. Ctime: time.Now().Unix(),
  5708. Mtime: time.Now().Unix(),
  5709. }
  5710. critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
  5711. if critical.ID == 0 {
  5712. service.CreatePatientCritical(criticalOne)
  5713. }
  5714. if critical.ID > 0 {
  5715. service.UpdatePatientCriticalOne(orgId, content)
  5716. }
  5717. c.ServeSuccessJSON(map[string]interface{}{
  5718. "criticalOne": criticalOne,
  5719. })
  5720. }
  5721. func (c *PatientApiController) GetPatientCriticalOneList() {
  5722. orgId := c.GetAdminUserInfo().CurrentOrgId
  5723. list, _ := service.GetPatientCriticalOneList(orgId)
  5724. c.ServeSuccessJSON(map[string]interface{}{
  5725. "list": list,
  5726. })
  5727. }
  5728. func (c *PatientApiController) DeleteSolution() {
  5729. id, _ := c.GetInt64("id")
  5730. solution, _ := service.DeleteSolutionById(id)
  5731. c.ServeSuccessJSON(map[string]interface{}{
  5732. "solution": solution,
  5733. })
  5734. }