patient_api_controller.go 283KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649
  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/savetreamentplan", &PatientApiController{}, "Post:SaveTreatmentPlan")
  91. beego.Router("api/patient/gettherapyinformed", &PatientApiController{}, "Get:GetTherapyInformed")
  92. beego.Router("/api/patient/savemedicalhistory", &PatientApiController{}, "Post:SaveMedicalHistory")
  93. beego.Router("/api/patient/savepatientcritaicalinformed", &PatientApiController{}, "Post:SavePatientCritaicalInformed")
  94. beego.Router("/api/patient/getPatientCriticalList", &PatientApiController{}, "Get:GetPatientCriticalList")
  95. beego.Router("/api/patient/savepatientcriticalcalinformedone", &PatientApiController{}, "Post:SavePatientCriticalInformedOne")
  96. beego.Router("/api/patient/getpatientcriticalonelist", &PatientApiController{}, "Get:GetPatientCriticalOneList")
  97. beego.Router("/api/patient/deletesolution", &PatientApiController{}, "Get:DeleteSolution")
  98. beego.Router("/api/patient/gettreamentplan", &PatientApiController{}, "Get:GetTreatMentPlanList")
  99. beego.Router("/api/patient/getpatientbypatientid", &PatientApiController{}, "Get:GetPatientByPatientId")
  100. beego.Router("/api/patient/savepatientlapse", &PatientApiController{}, "Post:SavePatientLapse")
  101. beego.Router("/api/patient/getpatientlapsorecord", &PatientApiController{}, "Get:GetPatientLapsorecord")
  102. beego.Router("/api/patient/getpatientlapserecord", &DialysisApiController{}, "Get:GetPatientLapseRecord")
  103. beego.Router("/api/patient/updatepatientlapserecord", &DialysisApiController{}, "Post:UpdatePatientLapseRecord")
  104. beego.Router("/api/patient/deletepatientlapsorecord", &DialysisApiController{}, "Get:DeletePatientLapseRecord")
  105. beego.Router("/api/patient/getpatientlapeso", &DialysisApiController{}, "Get:GetPatientLapseList")
  106. beego.Router("/api/patient/adddeathsummary", &DialysisApiController{}, "Post:AddDeathSummary")
  107. beego.Router("/api/patient/getpatientdeathsummary", &DialysisApiController{}, "Get:GetPatientDeathSummary")
  108. beego.Router("/api/patient/deletepatientdeathsummary", &DialysisApiController{}, "Get:DeletePatientDeathSummary")
  109. beego.Router("/api/patient/createnewsickhistoryrecord", &PatientApiController{}, "Post:CreateNewSickHistoryRecord")
  110. beego.Router("/api/patient/getnewsickhistory", &PatientApiController{}, "Get:GetNewSickHistory")
  111. beego.Router("/api/patient/deletenewsickhistory", &PatientApiController{}, "Get:DeleteNewSickHistory")
  112. beego.Router("/api/patient/savesickhistorytemplate", &PatientApiController{}, "Post:SaveSickHistoryTemplate")
  113. beego.Router("/api/patient/getsickhistorytemplate", &PatientApiController{}, "Get:GetSickHistoryTemplate")
  114. beego.Router("/api/patient/modifysickhistorytemplate", &PatientApiController{}, "Post:ModifySickHistoryTemplate")
  115. beego.Router("/api/patient/deletesickhistorytemplate", &PatientApiController{}, "Get:DeleteSickHistoryTemplate")
  116. beego.Router("/api/patient/createnewcourseofdiseaserecord", &PatientApiController{}, "Post:CreateNewCourseOfDiaseaseRecord")
  117. beego.Router("/api/patient/getpatientcourseofdiseaseslist", &PatientApiController{}, "Get:GetPatientCoureseOfDiseasesList")
  118. beego.Router("/api/patient/deletenewcourseofdisease", &PatientApiController{}, "Get:DeleteNewCourseOfDisease")
  119. beego.Router("/api/patient/createnewcouresetemplate", &PatientApiController{}, "Post:CreateNewCourseTemplate")
  120. beego.Router("/api/patient/savepatientdeathrecord", &PatientApiController{}, "Post:SavePatientDeathRecord")
  121. beego.Router("/api/patient/getpatientdeathrecord", &PatientApiController{}, "Get:GetPatientDeathRecordOne")
  122. beego.Router("/api/patient/savecouresetemplatetitle", &PatientApiController{}, "Post:SaveCoureseTemplateTitle")
  123. beego.Router("/api/patient/getpatientcourseoftemplate", &PatientApiController{}, "Get:GetPatientCourseOfTemplate")
  124. beego.Router("/api/patient/savecourseofnewtemplate", &PatientApiController{}, "Post:SaveCourseOfNewTemplate")
  125. beego.Router("/api/patient/deletecourestempalte", &PatientApiController{}, "Get:DeleteCouseTemplate")
  126. beego.Router("/api/patient/getautopatientcontent", &PatientApiController{}, "Get:GetAutoPatientContent")
  127. beego.Router("/api/patient/getpatientrescuerecord", &PatientApiController{}, "Get:GetPatientRescueRecord")
  128. beego.Router("/api/patient/modifycourseprint", &PatientApiController{}, "Post:ModifyCoursePrint")
  129. beego.Router("/api/patient/getpatientrescuerecordlist", &PatientApiController{}, "Get:GetPatientRescureRecordList")
  130. }
  131. func (c *PatientApiController) GetExportList() {
  132. startTime := c.GetString("start_time")
  133. endTime := c.GetString("end_time")
  134. schedulType, _ := c.GetInt64("schedul_type", 0)
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. adminUserInfo := c.GetAdminUserInfo()
  138. var theStartTIme int64
  139. if len(startTime) > 0 {
  140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  141. if err != nil {
  142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  143. return
  144. }
  145. theStartTIme = theTime.Unix()
  146. }
  147. var theEndtTIme int64
  148. if len(endTime) > 0 {
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  150. if err != nil {
  151. utils.ErrorLog(err.Error())
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. theEndtTIme = theTime.Unix()
  156. }
  157. timeNowStr := time.Now().Format("2006-01-02")
  158. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  159. schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
  160. fmt.Println("schedule23333333333333333", schedule)
  161. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "schedule": schedule,
  164. "patientsList": patientsList,
  165. })
  166. return
  167. }
  168. // GetPatientsList 取患者列表
  169. func (c *PatientApiController) GetPatientsList() {
  170. var err error
  171. defer func() {
  172. if rec := recover(); rec != nil {
  173. err = fmt.Errorf("程序异常:%v", rec)
  174. }
  175. if err != nil {
  176. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  177. }
  178. }()
  179. page, _ := c.GetInt64("page", 1)
  180. limit, _ := c.GetInt64("limit", 10)
  181. schedulType, _ := c.GetInt64("schedul_type", 0)
  182. bindingState, _ := c.GetInt64("binding_state", 0)
  183. lapseto, _ := c.GetInt64("lapseto", 0)
  184. source, _ := c.GetInt64("source", 0)
  185. startTime := c.GetString("start_time", "")
  186. endTime := c.GetString("end_time", "")
  187. keywords := c.GetString("keywords", "")
  188. contagion, _ := c.GetInt64("contagion", 0)
  189. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  190. isscheduling, _ := c.GetInt64("isscheduling", 0)
  191. isprescription, _ := c.GetInt64("isprescription", 0)
  192. patientSoureType, _ := c.GetInt64("patientSoureType")
  193. patient_type, _ := c.GetInt64("patient_type")
  194. nurse, _ := c.GetInt64("nurse")
  195. if page <= 0 {
  196. page = 1
  197. }
  198. if limit <= 0 {
  199. limit = 10
  200. }
  201. adminUserInfo := c.GetAdminUserInfo()
  202. timeLayout := "2006-01-02"
  203. loc, _ := time.LoadLocation("Local")
  204. var isStartTime bool
  205. var theStartTIme int64
  206. if len(startTime) > 0 {
  207. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  208. if err != nil {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. isStartTime = true
  213. theStartTIme = theTime.Unix()
  214. }
  215. var isEndTime bool
  216. var theEndtTIme int64
  217. if len(endTime) > 0 {
  218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  219. if err != nil {
  220. utils.ErrorLog(err.Error())
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. isEndTime = true
  225. theEndtTIme = theTime.Unix()
  226. }
  227. var patients []*models.Patients
  228. var total int64
  229. 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, patient_type)
  230. c.ServeSuccessJSON(map[string]interface{}{
  231. "patients": patients,
  232. "total": total,
  233. })
  234. return
  235. }
  236. // GetPatientTotal
  237. func (c *PatientApiController) GetPatientTotal() {
  238. adminUserInfo := c.GetAdminUserInfo()
  239. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "total": total,
  242. })
  243. return
  244. }
  245. func (c *PatientApiController) GetPatientsAllList() {
  246. adminUserInfo := c.GetAdminUserInfo()
  247. if adminUserInfo.CurrentOrgId != 10702 {
  248. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "patients": patients,
  251. "patientsOne": patients,
  252. "total": total,
  253. })
  254. return
  255. } else {
  256. patients, total, _ := service.GetAllPatientListOne(adminUserInfo.CurrentOrgId)
  257. patientsOne, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  258. c.ServeSuccessJSON(map[string]interface{}{
  259. "patients": patients,
  260. "patientsOne": patientsOne,
  261. "total": total,
  262. })
  263. return
  264. }
  265. }
  266. // GenerateDialysisNo 生成透析号
  267. func (c *PatientApiController) GenerateDialysisNo() {
  268. adminUserInfo := c.GetAdminUserInfo()
  269. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  270. if dialysisNo == 0 {
  271. dialysisNo = 1
  272. } else {
  273. dialysisNo++
  274. }
  275. no := strconv.FormatInt(dialysisNo, 10)
  276. rep := 3 - len(no)
  277. if rep > 0 {
  278. no = strings.Repeat("0", rep) + no
  279. }
  280. c.ServeSuccessJSON(map[string]interface{}{
  281. "no": no,
  282. })
  283. return
  284. }
  285. // CreatePatient 创建患者
  286. func (c *PatientApiController) CreatePatient() {
  287. record_date := c.GetString("record_date")
  288. is_infectious, _ := c.GetInt64("is_infectious")
  289. remind_cycle, _ := c.GetInt64("remind_cycle")
  290. adminUserInfo := c.GetAdminUserInfo()
  291. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  292. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  293. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  295. // return
  296. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  297. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  298. // return
  299. //}
  300. var patient models.Patients
  301. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  302. if code > 0 {
  303. c.ServeFailJSONWithSGJErrorCode(code)
  304. return
  305. }
  306. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  307. if thisPatient.ID > 0 {
  308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  309. return
  310. }
  311. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  312. if thisPatient.ID > 0 {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  314. return
  315. }
  316. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  317. if thisPatient.ID > 0 {
  318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  319. return
  320. }
  321. patient.RemindCycle = remind_cycle
  322. patient.IsInfectious = is_infectious
  323. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  324. patient.Status = 1
  325. patient.CreatedTime = time.Now().Unix()
  326. patient.UserOrgId = adminUserInfo.CurrentOrgId
  327. patient.UpdatedTime = time.Now().Unix()
  328. patient.BindingState = 2
  329. // patient.Lapseto = 1
  330. hans := patient.Name // 要转换的汉字字符串
  331. // 创建一个拼音转换器
  332. p := pinyin.NewArgs()
  333. // 将汉字转为拼音
  334. pinyinSlice := pinyin.Pinyin(hans, p)
  335. // 获取首字母
  336. firstLetter := ""
  337. for _, py := range pinyinSlice {
  338. if len(py) > 0 {
  339. firstLetter += string(py[0][0])
  340. }
  341. }
  342. patient.FirstLetter = firstLetter
  343. err := service.CreatePatient(&patient, contagions, diseases)
  344. fmt.Println("创建病人失败err")
  345. if err != nil {
  346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  347. return
  348. }
  349. //获取老表的最后一条数据
  350. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  351. creater := adminUserInfo.AdminUser.Id
  352. record := models.XtPatientLaspseRecord{
  353. PatientId: patients.ID,
  354. RecordDate: time.Now().Unix(),
  355. LapseDate: time.Now().Unix(),
  356. LapseType: 1,
  357. LapseClass: 0,
  358. LapseReason: "",
  359. AdminUserId: creater,
  360. Remark: "",
  361. UserOrgId: adminUserInfo.CurrentOrgId,
  362. Ctime: time.Now().Unix(),
  363. Mtime: time.Now().Unix(),
  364. Status: 1,
  365. LapseTypeName: "转入",
  366. HisType: 0,
  367. HisZone: "",
  368. HisBed: "",
  369. }
  370. service.CreatePatientRecord(record)
  371. patientsNew := models.XtPatientsNew{
  372. UserOrgId: adminUserInfo.CurrentOrgId,
  373. UserId: 0,
  374. Avatar: patients.Avatar,
  375. PatientType: patients.PatientType,
  376. DialysisNo: patients.DialysisNo,
  377. AdmissionNumber: patients.AdmissionNumber,
  378. Source: patients.Source,
  379. Lapseto: patients.Lapseto,
  380. PartitionId: patients.PartitionId,
  381. BedId: patients.BedId,
  382. Name: patients.Name,
  383. Alias: patients.Alias,
  384. Gender: patients.Gender,
  385. MaritalStatus: patients.MaritalStatus,
  386. IdCardNo: patients.IdCardNo,
  387. Birthday: patients.Birthday,
  388. ReimbursementWayId: patients.ReimbursementWayId,
  389. HealthCareType: patients.HealthCareType,
  390. HealthCareNo: patients.HealthCareNo,
  391. HealthCareDueDate: patients.HealthCareDueDate,
  392. Height: patients.Height,
  393. BloodType: patients.BloodType,
  394. Rh: patients.Rh,
  395. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  396. EducationLevel: patients.EducationLevel,
  397. Profession: patients.Profession,
  398. Phone: patients.Phone,
  399. HomeTelephone: patients.HomeTelephone,
  400. RelativePhone: patients.RelativePhone,
  401. RelativeRelations: patients.RelativeRelations,
  402. HomeAddress: patients.HomeAddress,
  403. WorkUnit: patients.WorkUnit,
  404. UnitAddress: patients.UnitAddress,
  405. Children: patients.Children,
  406. ReceivingDate: patients.ReceivingDate,
  407. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  408. FirstDialysisDate: patients.FirstDialysisDate,
  409. FirstDialysisHospital: patients.FirstDialysisHospital,
  410. PredialysisCondition: patients.PredialysisCondition,
  411. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  412. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  413. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  414. InductionPeriod: patients.InductionPeriod,
  415. InitialDialysis: patients.InitialDialysis,
  416. TotalDialysis: patients.TotalDialysis,
  417. AttendingDoctorId: patients.AttendingDoctorId,
  418. HeadNurseId: patients.HeadNurseId,
  419. Evaluate: patients.Evaluate,
  420. Diagnose: patients.Diagnose,
  421. Remark: patients.Remark,
  422. RegistrarsId: patients.RegistrarsId,
  423. Registrars: patients.Registrars,
  424. QrCode: patients.QrCode,
  425. BindingState: patients.BindingState,
  426. PatientComplains: patients.PatientComplains,
  427. PresentHistory: patients.PresentHistory,
  428. PastHistory: patients.PresentHistory,
  429. Temperature: patients.Temperature,
  430. Pulse: patients.Pulse,
  431. Respiratory: patients.Respiratory,
  432. Sbp: patients.SBP,
  433. Dbp: patients.DBP,
  434. Status: patients.Status,
  435. CreatedTime: patients.CreatedTime,
  436. UpdatedTime: patients.UpdatedTime,
  437. Nation: patients.Nation,
  438. NativePlace: patients.NativePlace,
  439. Age: patients.Age,
  440. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  441. IsInfectious: patients.IsInfectious,
  442. RemindCycle: patients.RemindCycle,
  443. ResponseResult: patients.ResponseResult,
  444. IsOpenRemind: patients.IsOpenRemind,
  445. FirstTreatmentDate: patients.FirstTreatmentDate,
  446. DialysisAge: patients.DialysisAge,
  447. ExpenseKind: patients.ExpenseKind,
  448. TellPhone: patients.TellPhone,
  449. ContactName: patients.ContactName,
  450. BloodPatients: 1,
  451. SlowPatients: 0,
  452. MemberPatients: 0,
  453. EcommerPatients: "",
  454. BloodId: patients.ID,
  455. SlowId: 0,
  456. MemberId: 0,
  457. MemberFistdate: 0,
  458. MemberPatienttype: 0,
  459. MemberTreatement: 0,
  460. EquitmentId: "",
  461. UserSysBeforeCount: patient.UserSysBeforeCount,
  462. TrobleShoot: patient.TrobleShoot,
  463. TreatmentPlan: patient.TreatmentPlan,
  464. Doctor: patient.Doctor,
  465. RecordNumber: patient.RecordNumber,
  466. PatientSource: patient.PatientSource,
  467. PatientEndTime: patient.PatientEndTime,
  468. PatientStartTime: patient.PatientStartTime,
  469. InfectiousRemark: patient.InfectiousRemark,
  470. AllergicHistory: patient.AllergicHistory,
  471. PatientAddress: patient.PatientAddress,
  472. PrintDate: patient.PrintDate,
  473. FamalityRecord: patient.FamalityRecord,
  474. }
  475. patientsNew.FirstLetter = firstLetter
  476. err = service.CreatePatientsNew(&patientsNew)
  477. fmt.Print("创建失败", err)
  478. allergic := models.XtPatientAllergic{
  479. UserOrgId: adminUserInfo.CurrentOrgId,
  480. PatientId: patient.ID,
  481. StartTime: patient.PatientStartTime,
  482. EndTime: patient.PatientEndTime,
  483. PatientSource: patient.PatientSource,
  484. PatientAddress: patient.PatientAddress,
  485. Remake: patient.Remark,
  486. Status: 1,
  487. Ctime: time.Now().Unix(),
  488. }
  489. if len(patient.PatientAddress) > 0 {
  490. service.CreateAllergic(allergic)
  491. }
  492. if len(record_date) > 0 {
  493. var recordTime int64
  494. timeLayout := "2006-01-02"
  495. loc, _ := time.LoadLocation("Local")
  496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  497. if err != nil {
  498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  499. return
  500. }
  501. recordTime = theTime.Unix()
  502. inspections := make([]models.Inspection, 0)
  503. for _, item := range formItems {
  504. var inspection models.Inspection
  505. inspection.OrgId = adminUserInfo.CurrentOrgId
  506. inspection.PatientId = patient.ID
  507. inspection.ProjectId = item.ProjectId
  508. inspection.ItemId = item.ItemId
  509. inspection.ItemName = item.ItemName
  510. inspection.ProjectName = item.ProjectName
  511. inspection.InspectType = item.RangeType
  512. inspection.InspectValue = item.Value
  513. inspection.InspectDate = recordTime
  514. inspection.Status = 1
  515. inspection.CreatedTime = time.Now().Unix()
  516. inspection.UpdatedTime = time.Now().Unix()
  517. inspections = append(inspections, inspection)
  518. }
  519. err = service.CreatePatientInspection(inspections)
  520. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  521. var record_time int64
  522. switch remind_cycle {
  523. case 1: //1个月
  524. ts := time.Unix(infectiousRecord.InspectDate, 0)
  525. record_time = ts.AddDate(0, 1, 0).Unix()
  526. break
  527. case 2: //2个月
  528. ts := time.Unix(infectiousRecord.InspectDate, 0)
  529. record_time = ts.AddDate(0, 2, 0).Unix()
  530. break
  531. case 3: //3个月
  532. ts := time.Unix(infectiousRecord.InspectDate, 0)
  533. record_time = ts.AddDate(0, 3, 0).Unix()
  534. break
  535. case 4: //6个月
  536. ts := time.Unix(infectiousRecord.InspectDate, 0)
  537. record_time = ts.AddDate(0, 6, 0).Unix()
  538. break
  539. case 5: //12个月
  540. ts := time.Unix(infectiousRecord.InspectDate, 0)
  541. record_time = ts.AddDate(0, 12, 0).Unix()
  542. break
  543. }
  544. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  545. if errs != nil {
  546. utils.ErrorLog("更新日期出错:%v", errs)
  547. }
  548. }
  549. redis := service.RedisClient()
  550. defer redis.Close()
  551. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  552. c.ServeSuccessJSON(map[string]interface{}{
  553. "msg": "ok",
  554. })
  555. return
  556. }
  557. // EditPatient 修改
  558. func (c *PatientApiController) EditPatient() {
  559. id, _ := c.GetInt64("id", 0)
  560. record_date := c.GetString("record_date")
  561. is_infectious, _ := c.GetInt64("is_infectious")
  562. remind_cycle, _ := c.GetInt64("remind_cycle")
  563. if id <= 0 {
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. adminUserInfo := c.GetAdminUserInfo()
  568. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  569. if patient.ID == 0 {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  571. return
  572. }
  573. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  574. if code > 0 {
  575. c.ServeFailJSONWithSGJErrorCode(code)
  576. return
  577. }
  578. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  579. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  581. return
  582. }
  583. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  584. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  586. return
  587. }
  588. patient.UpdatedTime = time.Now().Unix()
  589. patient.IsInfectious = is_infectious
  590. patient.RemindCycle = remind_cycle
  591. err := service.UpdatePatient(&patient, contagions, diseases)
  592. if err != nil {
  593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  594. return
  595. }
  596. ////更新转归状态
  597. //lapseto := models.PatientLapseto{
  598. // LapsetoType: patient.Lapseto,
  599. // LapsetoTime: time.Now().Unix(),
  600. // UpdatedTime: time.Now().Unix(),
  601. //}
  602. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  603. //fmt.Println("更新转归失败", err)
  604. if err != nil {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  606. return
  607. }
  608. patientsNew := models.XtPatientsNew{
  609. UserOrgId: patient.UserOrgId,
  610. UserId: patient.UserId,
  611. Avatar: patient.Avatar,
  612. PatientType: patient.PatientType,
  613. DialysisNo: patient.DialysisNo,
  614. AdmissionNumber: patient.AdmissionNumber,
  615. Source: patient.Source,
  616. PartitionId: patient.PartitionId,
  617. BedId: patient.BedId,
  618. Name: patient.Name,
  619. Alias: patient.Alias,
  620. Gender: patient.Gender,
  621. MaritalStatus: patient.MaritalStatus,
  622. IdCardNo: patient.IdCardNo,
  623. Birthday: patient.Birthday,
  624. ReimbursementWayId: patient.ReimbursementWayId,
  625. HealthCareType: patient.HealthCareType,
  626. HealthCareNo: patient.HealthCareNo,
  627. HealthCareDueDate: patient.HealthCareDueDate,
  628. Height: patient.Height,
  629. BloodType: patient.BloodType,
  630. Rh: patient.Rh,
  631. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  632. EducationLevel: patient.EducationLevel,
  633. Profession: patient.Profession,
  634. Phone: patient.Phone,
  635. HomeTelephone: patient.HomeTelephone,
  636. RelativePhone: patient.RelativePhone,
  637. RelativeRelations: patient.RelativeRelations,
  638. HomeAddress: patient.HomeAddress,
  639. WorkUnit: patient.WorkUnit,
  640. UnitAddress: patient.UnitAddress,
  641. Children: patient.Children,
  642. ReceivingDate: patient.ReceivingDate,
  643. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  644. FirstDialysisDate: patient.FirstDialysisDate,
  645. FirstDialysisHospital: patient.FirstDialysisHospital,
  646. PredialysisCondition: patient.PredialysisCondition,
  647. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  648. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  649. InductionPeriod: patient.InductionPeriod,
  650. InitialDialysis: patient.InitialDialysis,
  651. TotalDialysis: patient.TotalDialysis,
  652. AttendingDoctorId: patient.AttendingDoctorId,
  653. HeadNurseId: patient.HeadNurseId,
  654. Evaluate: patient.Evaluate,
  655. Diagnose: patient.Diagnose,
  656. Remark: patient.Remark,
  657. RegistrarsId: patient.RegistrarsId,
  658. Registrars: patient.Registrars,
  659. QrCode: patient.QrCode,
  660. BindingState: patient.BindingState,
  661. PatientComplains: patient.PatientComplains,
  662. PresentHistory: patient.PresentHistory,
  663. PastHistory: patient.PastHistory,
  664. Temperature: patient.Temperature,
  665. Pulse: patient.Pulse,
  666. Respiratory: patient.Respiratory,
  667. Sbp: patient.SBP,
  668. Dbp: patient.DBP,
  669. Nation: patient.Nation,
  670. NativePlace: patient.NativePlace,
  671. Age: patient.Age,
  672. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  673. IsInfectious: patient.IsInfectious,
  674. RemindCycle: patient.RemindCycle,
  675. ResponseResult: patient.ResponseResult,
  676. IsOpenRemind: patient.IsOpenRemind,
  677. FirstTreatmentDate: patient.FirstTreatmentDate,
  678. DialysisAge: patient.DialysisAge,
  679. ExpenseKind: patient.ExpenseKind,
  680. TellPhone: patient.TellPhone,
  681. ContactName: patient.ContactName,
  682. UpdatedTime: time.Now().Unix(),
  683. BloodPatients: 1,
  684. Lapseto: patient.Lapseto,
  685. TrobleShoot: patient.TrobleShoot,
  686. SchRemark: patient.SchRemark,
  687. TreatmentPlan: patient.TreatmentPlan,
  688. RecordNumber: patient.RecordNumber,
  689. PatientSource: patient.PatientSource,
  690. PatientStartTime: patient.PatientStartTime,
  691. PatientEndTime: patient.PatientEndTime,
  692. InfectiousRemark: patient.InfectiousRemark,
  693. AllergicHistory: patient.AllergicHistory,
  694. PatientAddress: patient.PatientAddress,
  695. PrintDate: patient.PrintDate,
  696. FamalityRecord: patient.FamalityRecord,
  697. }
  698. // //更新病人ID获取新表病人ID
  699. err = service.UpdatepatientTwo(&patientsNew, id)
  700. allergic := models.XtPatientAllergic{
  701. PatientId: patient.ID,
  702. UserOrgId: adminUserInfo.CurrentOrgId,
  703. StartTime: patient.PatientStartTime,
  704. EndTime: patient.PatientEndTime,
  705. PatientSource: patient.PatientSource,
  706. Status: 1,
  707. Ctime: time.Now().Unix(),
  708. Mtime: time.Now().Unix(),
  709. Remake: patient.Remark,
  710. PatientAddress: patient.PatientAddress,
  711. }
  712. if len(patient.PatientAddress) > 0 {
  713. service.CreateAllergic(allergic)
  714. }
  715. nowTimeUinx := time.Now()
  716. today := nowTimeUinx.Format("2006-01-02")
  717. redis := service.RedisClient()
  718. defer redis.Close()
  719. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  720. redis.Set(key, "", time.Second*60*60*18)
  721. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  722. redis.Set(keyOne, "", time.Second*60*60*18)
  723. if len(record_date) > 0 {
  724. var recordTime int64
  725. timeLayout := "2006-01-02"
  726. loc, _ := time.LoadLocation("Local")
  727. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  728. if err != nil {
  729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. recordTime = theTime.Unix()
  733. inspections := make([]models.Inspection, 0)
  734. for _, item := range formItems {
  735. var inspection models.Inspection
  736. inspection.OrgId = adminUserInfo.CurrentOrgId
  737. inspection.PatientId = patient.ID
  738. inspection.ProjectId = item.ProjectId
  739. inspection.ItemId = item.ItemId
  740. inspection.ItemName = item.ItemName
  741. inspection.ProjectName = item.ProjectName
  742. inspection.InspectType = item.RangeType
  743. inspection.InspectValue = item.Value
  744. inspection.InspectDate = recordTime
  745. inspection.Status = 1
  746. inspection.CreatedTime = time.Now().Unix()
  747. inspection.UpdatedTime = time.Now().Unix()
  748. inspections = append(inspections, inspection)
  749. }
  750. err = service.CreatePatientInspection(inspections)
  751. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  752. var record_time int64
  753. switch remind_cycle {
  754. case 1: //1个月
  755. ts := time.Unix(infectiousRecord.InspectDate, 0)
  756. record_time = ts.AddDate(0, 1, 0).Unix()
  757. break
  758. case 2: //2个月
  759. ts := time.Unix(infectiousRecord.InspectDate, 0)
  760. record_time = ts.AddDate(0, 2, 0).Unix()
  761. break
  762. case 3: //3个月
  763. ts := time.Unix(infectiousRecord.InspectDate, 0)
  764. record_time = ts.AddDate(0, 3, 0).Unix()
  765. break
  766. case 4: //6个月
  767. ts := time.Unix(infectiousRecord.InspectDate, 0)
  768. record_time = ts.AddDate(0, 6, 0).Unix()
  769. break
  770. case 5: //12个月
  771. ts := time.Unix(infectiousRecord.InspectDate, 0)
  772. record_time = ts.AddDate(0, 12, 0).Unix()
  773. break
  774. }
  775. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  776. if errs != nil {
  777. utils.ErrorLog("更新日期出错:%v", errs)
  778. }
  779. }
  780. c.ServeSuccessJSON(map[string]interface{}{
  781. "msg": "ok",
  782. })
  783. return
  784. }
  785. func (c *PatientApiController) EditLapseto() {
  786. id, _ := c.GetInt64("id", 0)
  787. if id <= 0 {
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  789. return
  790. }
  791. start_time := c.GetString("start_time")
  792. end_time := c.GetString("end_time")
  793. timeLayout := "2006-01-02"
  794. loc, _ := time.LoadLocation("Local")
  795. var startTime int64
  796. if len(start_time) > 0 {
  797. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  798. if err != nil {
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  800. return
  801. }
  802. startTime = theTime.Unix()
  803. }
  804. var endTime int64
  805. if len(end_time) > 0 {
  806. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  807. if err != nil {
  808. utils.ErrorLog(err.Error())
  809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  810. return
  811. }
  812. endTime = theTime.Unix()
  813. }
  814. patient_address := c.GetString("patient_address")
  815. adminUserInfo := c.GetAdminUserInfo()
  816. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  817. if patient.ID == 0 {
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  819. return
  820. }
  821. patientBody := make(map[string]interface{}, 0)
  822. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  823. if err != nil {
  824. utils.ErrorLog(err.Error())
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  826. return
  827. }
  828. var lapseto models.PatientLapseto
  829. lapseto.PatientId = patient.ID
  830. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  831. utils.ErrorLog("lapseto_type")
  832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  833. return
  834. }
  835. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  836. lapseto.LapsetoType = lapsetoType
  837. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  838. utils.ErrorLog("lapseto_time")
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  840. return
  841. }
  842. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  843. //if len(lapsetoTime) == 0 {
  844. // utils.ErrorLog("len(lapsetoTime) == 0")
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  846. // return
  847. //}
  848. out_reason, _ := patientBody["out_reason"].(string)
  849. //if len(out_reason) == 0 {
  850. // utils.ErrorLog("len(out_reason) == 0")
  851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  852. // return
  853. //}
  854. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  855. //if err != nil {
  856. // utils.ErrorLog("lapsetoTimeUnix")
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  858. // return
  859. //}
  860. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  861. lapseto.UpdatedTime = time.Now().Unix()
  862. lapseto.CreatedTime = time.Now().Unix()
  863. lapseto.Status = 1
  864. patient.Lapseto = lapseto.LapsetoType
  865. patient.OutReason = out_reason
  866. patient.DeathTime = lapsetoTimeUnix.Unix()
  867. patient.PatientStartTime = startTime
  868. patient.PatientEndTime = endTime
  869. patient.PatientAddress = patient_address
  870. //if patient.Lapseto == 1 {
  871. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  872. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  873. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  874. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  875. // return
  876. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  877. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  878. // return
  879. // }
  880. //}
  881. err = service.EditPatientLapseto(&patient, &lapseto)
  882. if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  883. fmt.Println("lapsetoTimeUnix.Unix()", lapsetoTimeUnix.Unix())
  884. if adminUserInfo.CurrentOrgId == 10340 {
  885. service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
  886. service.UpdateScheduleItemByPatientId(id)
  887. } else {
  888. timeStr := time.Now().Format("2006-01-02")
  889. timeLayout := "2006-01-02 15:04:05"
  890. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  891. timenow := timeStringToTime.Unix()
  892. service.UpdateScheduleByDeathTime(id, timenow)
  893. service.UpdateScheduleItemByPatientId(id)
  894. }
  895. }
  896. allergic := models.XtPatientAllergic{
  897. UserOrgId: adminUserInfo.CurrentOrgId,
  898. PatientId: patient.ID,
  899. StartTime: patient.PatientStartTime,
  900. EndTime: patient.PatientEndTime,
  901. PatientSource: patient.Lapseto,
  902. PatientAddress: patient.PatientAddress,
  903. Remake: patient.Remark,
  904. Status: 1,
  905. Ctime: time.Now().Unix(),
  906. }
  907. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  908. allergic.StartTime = lapseto.LapsetoTime
  909. allergic.EndTime = lapseto.LapsetoTime
  910. }
  911. service.CreateAllergic(allergic)
  912. if err != nil {
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  914. return
  915. }
  916. c.ServeSuccessJSON(map[string]interface{}{
  917. "msg": "ok",
  918. })
  919. return
  920. }
  921. func (c *PatientApiController) GetPatient() {
  922. id, _ := c.GetInt64("id", 0)
  923. if id <= 0 {
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. adminUserInfo := c.GetAdminUserInfo()
  928. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  929. if patient.ID == 0 {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  931. return
  932. }
  933. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  934. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  935. diseases := service.GetPatientDiseases(patient.ID)
  936. contagions := service.GetPatientContagions(patient.ID)
  937. patientVascularAccessOne, _ := service.GetPatientVascularAccessOne(patient.ID)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "patient": patient,
  940. "diseases": diseases,
  941. "contagions": contagions,
  942. "infections": infections,
  943. "patientVascularAccessOne": patientVascularAccessOne,
  944. })
  945. return
  946. }
  947. func (c *PatientApiController) CreateDialysisSolution() {
  948. id, _ := c.GetInt64("patient", 0)
  949. if id <= 0 {
  950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  951. return
  952. }
  953. adminUserInfo := c.GetAdminUserInfo()
  954. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  955. if patient.ID == 0 {
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  957. return
  958. }
  959. var solution models.DialysisSolution
  960. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  961. if code > 0 {
  962. c.ServeFailJSONWithSGJErrorCode(code)
  963. return
  964. }
  965. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  966. //if thisSolution.ID > 0 {
  967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  968. // return
  969. //}
  970. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  971. solution.Doctor = adminUserInfo.AdminUser.Id
  972. solution.Status = 1
  973. solution.PatientId = id
  974. solution.CreatedTime = time.Now().Unix()
  975. solution.UserOrgId = adminUserInfo.CurrentOrgId
  976. solution.UpdatedTime = time.Now().Unix()
  977. solution.SubName = ""
  978. solution.ParentId = 0
  979. solution.SolutionStatus = 1
  980. //records, _ := service.GetAllSchedules()
  981. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  982. for _, sch := range schs {
  983. var DialysisMachineName string
  984. if len(solution.DialysisDialyszers) > 0 {
  985. DialysisMachineName = solution.DialysisDialyszers
  986. }
  987. if len(solution.DialyzerPerfusionApparatus) > 0 {
  988. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  989. }
  990. if len(solution.DialysisIrrigation) > 0 {
  991. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  992. }
  993. if len(solution.DialysisStrainer) > 0 {
  994. DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
  995. }
  996. sch.DialysisMachineName = DialysisMachineName
  997. service.UpdateSch(sch)
  998. }
  999. err := service.CreatePatientDialysisSolution(&solution)
  1000. //获取最新1条
  1001. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  1002. //更新状态
  1003. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1004. if err != nil {
  1005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  1006. return
  1007. }
  1008. c.ServeSuccessJSON(map[string]interface{}{
  1009. "msg": "ok",
  1010. "solution": solution,
  1011. })
  1012. return
  1013. }
  1014. func (c *PatientApiController) UpdateDialysisSolution() {
  1015. patient, _ := c.GetInt64("patient", 0)
  1016. id, _ := c.GetInt64("id", 0)
  1017. if id <= 0 || patient <= 0 {
  1018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1019. return
  1020. }
  1021. adminUserInfo := c.GetAdminUserInfo()
  1022. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1023. if solution.ID == 0 || solution.PatientId != patient {
  1024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1025. return
  1026. }
  1027. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  1028. if code > 0 {
  1029. c.ServeFailJSONWithSGJErrorCode(code)
  1030. return
  1031. }
  1032. solution.UpdatedTime = time.Now().Unix()
  1033. err := service.UpdatePatientDialysisSolution(&solution)
  1034. nowTimeUinx := time.Now()
  1035. today := nowTimeUinx.Format("2006-01-02")
  1036. timeLayout := "2006-01-02"
  1037. loc, _ := time.LoadLocation("Local")
  1038. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  1039. if adminUserInfo.CurrentOrgId == 9538 || adminUserInfo.CurrentOrgId == 10164 {
  1040. prescription := models.DialysisPrescription{
  1041. Dialyzer: solution.Dialyzer,
  1042. Anticoagulant: solution.Anticoagulant,
  1043. AnticoagulantShouji: solution.AnticoagulantShouji,
  1044. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  1045. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  1046. ModeId: solution.ModeId,
  1047. DialysisDurationHour: solution.DialysisDurationHour,
  1048. Kalium: solution.Kalium,
  1049. Sodium: solution.Sodium,
  1050. Calcium: solution.Calcium,
  1051. TargetUltrafiltration: solution.TargetUltrafiltration,
  1052. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  1053. BloodAccess: solution.BloodAccess,
  1054. DialysateFlow: solution.DialysateFlow,
  1055. DialysateTemperature: solution.DialysateTemperature,
  1056. DialysisIrrigation: solution.DialysisIrrigation,
  1057. DialysisDialyszers: solution.DialysisDialyszers,
  1058. PlasmaSeparator: solution.PlasmaSeparator,
  1059. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  1060. OxygenUptake: solution.OxygenUptake,
  1061. OxygenFlow: solution.OxygenFlow,
  1062. OxygenTime: solution.OxygenTime,
  1063. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  1064. Amylaceum: solution.Amylaceum,
  1065. DialysisStrainer: solution.DialysisStrainer,
  1066. Chaptalization: solution.Chaptalization,
  1067. BloodAccessPartId: solution.BloodAccessPartId,
  1068. }
  1069. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  1070. }
  1071. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  1072. for _, sch := range schs {
  1073. var DialysisMachineName string
  1074. if len(solution.DialysisDialyszers) > 0 {
  1075. DialysisMachineName = solution.DialysisDialyszers
  1076. }
  1077. if len(solution.DialyzerPerfusionApparatus) > 0 {
  1078. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  1079. }
  1080. if len(solution.DialysisIrrigation) > 0 {
  1081. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  1082. }
  1083. if len(solution.DialysisStrainer) > 0 {
  1084. DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
  1085. }
  1086. sch.DialysisMachineName = DialysisMachineName
  1087. service.UpdateSch(sch)
  1088. }
  1089. if err != nil {
  1090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  1091. return
  1092. }
  1093. c.ServeSuccessJSON(map[string]interface{}{
  1094. "msg": "ok",
  1095. "solution": solution,
  1096. })
  1097. return
  1098. }
  1099. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  1100. patient, _ := c.GetInt64("patient", 0)
  1101. id, _ := c.GetInt64("id", 0)
  1102. if id <= 0 || patient <= 0 {
  1103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1104. return
  1105. }
  1106. adminUserInfo := c.GetAdminUserInfo()
  1107. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1108. if solution.ID == 0 || solution.PatientId != patient {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1110. return
  1111. }
  1112. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  1113. if code > 0 {
  1114. c.ServeFailJSONWithSGJErrorCode(code)
  1115. return
  1116. }
  1117. solution.UpdatedTime = time.Now().Unix()
  1118. solution.AffirmState = 1
  1119. err := service.UpdatePatientDialysisSolution(&solution)
  1120. if err != nil {
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  1122. return
  1123. }
  1124. c.ServeSuccessJSON(map[string]interface{}{
  1125. "msg": "ok",
  1126. "solution": solution,
  1127. })
  1128. return
  1129. }
  1130. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1131. id, _ := c.GetInt64("id", 0)
  1132. page, _ := c.GetInt64("page", 0)
  1133. limit, _ := c.GetInt64("limit", 0)
  1134. if id <= 0 {
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "solutions": nil,
  1137. })
  1138. return
  1139. }
  1140. if page <= 0 {
  1141. page = 1
  1142. }
  1143. if limit <= 0 {
  1144. limit = 10
  1145. }
  1146. adminUserInfo := c.GetAdminUserInfo()
  1147. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  1148. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "solutions": solutions,
  1151. "total": total,
  1152. "stockType": stockType,
  1153. })
  1154. return
  1155. }
  1156. func (c *PatientApiController) DeleteDialysisSolution() {
  1157. id, _ := c.GetInt64("id", 0)
  1158. if id <= 0 {
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. adminUserInfo := c.GetAdminUserInfo()
  1163. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1164. if solution.ID == 0 {
  1165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1166. return
  1167. }
  1168. if solution.UseState == 1 {
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  1170. return
  1171. }
  1172. solution.UpdatedTime = time.Now().Unix()
  1173. solution.Status = 0
  1174. err := service.DeleteSolution(&solution)
  1175. if err != nil {
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  1177. return
  1178. }
  1179. c.ServeSuccessJSON(map[string]interface{}{
  1180. "msg": "ok",
  1181. })
  1182. return
  1183. }
  1184. // GetDryWeights 取患者干体重调整铺
  1185. func (c *PatientApiController) GetDryWeights() {
  1186. page, _ := c.GetInt64("page", 1)
  1187. limit, _ := c.GetInt64("limit", 10)
  1188. id, _ := c.GetInt64("id", 0)
  1189. if id <= 0 {
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1191. return
  1192. }
  1193. adminUserInfo := c.GetAdminUserInfo()
  1194. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  1195. c.ServeSuccessJSON(map[string]interface{}{
  1196. "weights": weights,
  1197. "total": total,
  1198. })
  1199. return
  1200. }
  1201. func (c *PatientApiController) CreateDryWeights() {
  1202. patient, _ := c.GetInt64("id", 0)
  1203. if patient <= 0 {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. adminUserInfo := c.GetAdminUserInfo()
  1208. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1209. if patientInfo.ID == 0 {
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1211. return
  1212. }
  1213. var theWeight models.DryWeightAdjust
  1214. dataBody := make(map[string]interface{}, 0)
  1215. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1216. if err != nil {
  1217. utils.ErrorLog(err.Error())
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1223. return
  1224. }
  1225. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  1226. theWeight.Weight = weight
  1227. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  1228. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1229. // return
  1230. // }
  1231. // doctor := int64(dataBody["doctor"].(float64))
  1232. // theWeight.Doctor = doctor
  1233. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1234. remark, _ := dataBody["remark"].(string)
  1235. theWeight.Remark = remark
  1236. }
  1237. theWeight.CreatedTime = time.Now().Unix()
  1238. theWeight.UpdatedTime = time.Now().Unix()
  1239. theWeight.Status = 1
  1240. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  1241. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  1242. theWeight.PatientId = patient
  1243. theWeight.Doctor = adminUserInfo.AdminUser.Id
  1244. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  1245. if old.ID > 0 {
  1246. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1247. }
  1248. err = service.CreateDryWeightAdjust(&theWeight)
  1249. if err != nil {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1251. return
  1252. }
  1253. c.ServeSuccessJSON(map[string]interface{}{
  1254. "msg": "ok",
  1255. "weight": theWeight,
  1256. })
  1257. return
  1258. }
  1259. func (c *PatientApiController) CreateGroupAdvice() {
  1260. var err error
  1261. defer func() {
  1262. if rec := recover(); rec != nil {
  1263. err = fmt.Errorf("程序异常:%v", rec)
  1264. }
  1265. if err != nil {
  1266. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1267. }
  1268. }()
  1269. patient, _ := c.GetInt64("id", 0)
  1270. groupNo, _ := c.GetInt64("groupno", 0)
  1271. if patient <= 0 {
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1273. return
  1274. }
  1275. adminUserInfo := c.GetAdminUserInfo()
  1276. var patientInfo models.Patients
  1277. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1278. if patientInfo.ID == 0 {
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1280. return
  1281. }
  1282. dataBody := make(map[string]interface{}, 0)
  1283. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1284. if err != nil {
  1285. utils.ErrorLog(err.Error())
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. utils.ErrorLog("%v", dataBody)
  1290. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1291. if appRole.UserType == 3 {
  1292. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1293. if getPermissionErr != nil {
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1295. return
  1296. } else if headNursePermission == nil {
  1297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1298. return
  1299. }
  1300. }
  1301. timeLayout := "2006-01-02"
  1302. loc, _ := time.LoadLocation("Local")
  1303. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1304. utils.ErrorLog("advice_type")
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. adviceType := int64(dataBody["advice_type"].(float64))
  1309. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1310. utils.ErrorLog("advice_type != 1&&2")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1315. utils.ErrorLog("advice_date")
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1317. return
  1318. }
  1319. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1320. utils.ErrorLog("start_time")
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1322. return
  1323. }
  1324. startTime2, _ := dataBody["start_time"].(string)
  1325. time_arr := strings.Split(startTime2, " ")
  1326. if len(time_arr) > 0 {
  1327. startTime2 = time_arr[0]
  1328. }
  1329. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1330. utils.ErrorLog("advice_date")
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. adviceDate := startTime2
  1335. if len(adviceDate) == 0 {
  1336. utils.ErrorLog("len(adviceDate) == 0")
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1341. if err != nil {
  1342. utils.ErrorLog(err.Error())
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1344. return
  1345. }
  1346. AdviceDate := theTime.Unix()
  1347. RecordDate := theTime.Unix()
  1348. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1349. utils.ErrorLog("start_time")
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. startTime, _ := dataBody["start_time"].(string)
  1354. if len(startTime) == 0 {
  1355. utils.ErrorLog("len(start_time) == 0")
  1356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1357. return
  1358. }
  1359. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1360. if err != nil {
  1361. utils.ErrorLog(err.Error())
  1362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1363. return
  1364. }
  1365. StartTime := theTime.Unix()
  1366. Remark := ""
  1367. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1368. remark, _ := dataBody["remark"].(string)
  1369. Remark = remark
  1370. }
  1371. var advices []*models.GroupAdvice
  1372. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1373. utils.ErrorLog("adviceNames")
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1375. return
  1376. }
  1377. adviceNames := dataBody["adviceNames"].([]interface{})
  1378. for _, adviceNameMap := range adviceNames {
  1379. adviceNameM := adviceNameMap.(map[string]interface{})
  1380. var advice models.GroupAdvice
  1381. advice.Remark = Remark
  1382. advice.AdviceType = adviceType
  1383. advice.StartTime = StartTime
  1384. advice.AdviceDate = AdviceDate
  1385. advice.RecordDate = RecordDate
  1386. advice.Status = 1
  1387. advice.CreatedTime = time.Now().Unix()
  1388. advice.UpdatedTime = time.Now().Unix()
  1389. advice.StopState = 2
  1390. advice.ExecutionState = 2
  1391. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1392. advice.PatientId = patientInfo.ID
  1393. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1394. advice.IsSettle = 2
  1395. //创建步骤表
  1396. finish := models.XtDialysisFinish{
  1397. IsFinish: 1,
  1398. UserOrgId: adminUserInfo.CurrentOrgId,
  1399. Status: 1,
  1400. Ctime: time.Now().Unix(),
  1401. Mtime: 0,
  1402. Module: 4,
  1403. RecordDate: advice.RecordDate,
  1404. Sourse: 1,
  1405. PatientId: patient,
  1406. }
  1407. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
  1408. if dialysisFinish.ID == 0 {
  1409. service.CreateDialysisFinish(finish)
  1410. }
  1411. // 查询信息规挡的设置天数
  1412. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1413. if infor.ID > 0 && infor.WeekDay > 0 {
  1414. var cha_time int64
  1415. timeNowStr := time.Now().Format("2006-01-02")
  1416. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1417. //今日的日期减去设置的日期
  1418. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1419. if cha_time >= advice.AdviceDate {
  1420. //查询审核是否允许
  1421. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1422. //申请状态不允许的情况 拒绝修改
  1423. if infor.ApplicationStatus != 1 {
  1424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1425. return
  1426. }
  1427. }
  1428. }
  1429. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1430. utils.ErrorLog("advice_name")
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adviceName, _ := adviceNameM["advice_name"].(string)
  1435. if len(adviceName) == 0 {
  1436. utils.ErrorLog("len(advice_name) == 0")
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. advice.AdviceName = adviceName
  1441. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1442. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1443. advice.DrugSpec = drugSpec
  1444. }
  1445. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1446. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1447. advice.AdviceDesc = adviceDesc
  1448. }
  1449. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1450. template_id, _ := adviceNameM["template_id"].(string)
  1451. advice.TemplateId = template_id
  1452. }
  1453. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1454. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1455. advice.DrugSpecUnit = drugSpecUnit
  1456. }
  1457. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1458. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1459. advice.SingleDose = singleDose
  1460. }
  1461. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1462. singleDose := adviceNameM["single_dose"].(float64)
  1463. advice.SingleDose = singleDose
  1464. }
  1465. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1466. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1467. advice.SingleDoseUnit = singleDoseUnit
  1468. }
  1469. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1470. tmp := adviceNameM["single_dose_unit"].(float64)
  1471. singleDoseUnit := service.TypeConversion(tmp)
  1472. advice.SingleDoseUnit = singleDoseUnit
  1473. }
  1474. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1475. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1476. advice.PrescribingNumber = prescribingNumber
  1477. }
  1478. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1479. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1480. advice.PrescribingNumber = prescribingNumber
  1481. }
  1482. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1483. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1484. advice.PrescribingNumberUnit = prescribingNumberUnit
  1485. }
  1486. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1487. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1488. advice.DeliveryWay = deliveryWay
  1489. }
  1490. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1491. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1492. advice.ExecutionFrequency = executionFrequency
  1493. }
  1494. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1495. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1496. advice.Way = int64(way)
  1497. }
  1498. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1499. way := int64(adviceNameM["way"].(float64))
  1500. advice.Way = way
  1501. }
  1502. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1503. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1504. advice.DrugId = int64(drug_id)
  1505. }
  1506. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1507. drug_id := int64(adviceNameM["drug_id"].(float64))
  1508. advice.DrugId = drug_id
  1509. }
  1510. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1511. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1512. advice.DrugNameId = drug_name_id
  1513. }
  1514. remark, _ := adviceNameM["remark"].(string)
  1515. advice.Remark = remark
  1516. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1517. if advice.PrescribingNumber == 0 {
  1518. advice.PrescribingNumber = 1
  1519. }
  1520. //查询该患者今日有没有双人核对
  1521. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1522. fmt.Println("chek", check)
  1523. if check.ID > 0 {
  1524. advice.Checker = check.Modifier
  1525. advice.CheckState = 1
  1526. advice.CheckTime = time.Now().Unix()
  1527. }
  1528. }
  1529. if adviceType == 1 {
  1530. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1531. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1532. advice.FrequencyType = frequency_type
  1533. }
  1534. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1535. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1536. advice.DayCount = day_count
  1537. }
  1538. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1539. week_day, _ := adviceNameM["week_days"].(string)
  1540. advice.WeekDay = week_day
  1541. }
  1542. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1543. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1544. var startTime int64
  1545. if len(push_start_time) > 0 {
  1546. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1547. startTime = theTime.Unix()
  1548. }
  1549. advice.PushStartTime = startTime
  1550. }
  1551. }
  1552. //针对康桥
  1553. if adminUserInfo.CurrentOrgId == 10702 {
  1554. if adviceType == 3 {
  1555. adviceType = 2
  1556. }
  1557. }
  1558. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1559. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1560. advice.ExecutionFrequency = executionFrequency
  1561. }
  1562. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1563. children := adviceNameM["children"].([]interface{})
  1564. if len(children) > 0 {
  1565. for _, childrenMap := range children {
  1566. childMap := childrenMap.(map[string]interface{})
  1567. var child models.GroupAdvice
  1568. child.Remark = Remark
  1569. child.AdviceType = adviceType
  1570. child.StartTime = StartTime
  1571. child.AdviceDate = AdviceDate
  1572. child.RecordDate = RecordDate
  1573. child.Status = 1
  1574. child.CreatedTime = time.Now().Unix()
  1575. child.UpdatedTime = time.Now().Unix()
  1576. child.StopState = 2
  1577. child.ExecutionState = 2
  1578. child.UserOrgId = adminUserInfo.CurrentOrgId
  1579. child.PatientId = patientInfo.ID
  1580. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1581. child.IsSettle = 2
  1582. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1583. utils.ErrorLog("child advice_name")
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1585. return
  1586. }
  1587. childAdviceName, _ := childMap["advice_name"].(string)
  1588. if len(childAdviceName) == 0 {
  1589. utils.ErrorLog("len(child advice_name) == 0")
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. child.AdviceName = childAdviceName
  1594. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1595. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1596. child.AdviceDesc = childAdviceDesc
  1597. }
  1598. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1599. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1600. child.DrugSpec = childDrugSpec
  1601. }
  1602. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1603. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1604. child.DrugSpecUnit = childDrugSpecUnit
  1605. }
  1606. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1607. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1608. child.SingleDose = childSingleDose
  1609. }
  1610. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1611. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1612. child.SingleDoseUnit = childSingleDoseUnit
  1613. }
  1614. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1615. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1616. child.PrescribingNumber = childPrescribingNumber
  1617. }
  1618. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1619. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1620. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1621. }
  1622. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1623. drug_id := int64(childMap["drug_id"].(float64))
  1624. child.DrugId = drug_id
  1625. }
  1626. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1627. way := int64(childMap["way"].(float64))
  1628. child.Way = way
  1629. }
  1630. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1631. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1632. child.DrugNameId = drug_name_id
  1633. }
  1634. child.DeliveryWay = advice.DeliveryWay
  1635. child.ExecutionFrequency = advice.ExecutionFrequency
  1636. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1637. if child.PrescribingNumber == 0 {
  1638. child.PrescribingNumber = 1
  1639. }
  1640. //查询该患者今日有没有双人核对
  1641. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1642. if check.ID > 0 {
  1643. child.Checker = check.Modifier
  1644. child.CheckState = 1
  1645. child.CheckTime = time.Now().Unix()
  1646. }
  1647. }
  1648. advice.Children = append(advice.Children, &child)
  1649. }
  1650. }
  1651. }
  1652. advices = append(advices, &advice)
  1653. }
  1654. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1655. for _, item := range advices {
  1656. //记录日志
  1657. byterequest, _ := json.Marshal(item)
  1658. adviceLog := models.XtDoctorAdviceLog{
  1659. UserOrgId: item.UserOrgId,
  1660. PatientId: item.PatientId,
  1661. AdminUserId: adminUserInfo.AdminUser.Id,
  1662. Module: 1,
  1663. ErrLog: string(byterequest),
  1664. Status: 1,
  1665. Ctime: time.Now().Unix(),
  1666. Mtime: 0,
  1667. Source: "电导端批量插入医嘱",
  1668. RecordDate: item.AdviceDate,
  1669. }
  1670. service.CreateDoctorAdviceLog(adviceLog)
  1671. }
  1672. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1673. redis := service.RedisClient()
  1674. defer redis.Close()
  1675. redis.Set(key, "", time.Second)
  1676. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1677. redis.Set(keyOne, "", time.Second)
  1678. if err != nil {
  1679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1680. return
  1681. }
  1682. c.ServeSuccessJSON(map[string]interface{}{
  1683. "msg": "ok",
  1684. "advices": list,
  1685. })
  1686. return
  1687. }
  1688. func (c *PatientApiController) CreateDoctorAdvice() {
  1689. patient, _ := c.GetInt64("id", 0)
  1690. if patient <= 0 {
  1691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1692. return
  1693. }
  1694. adminUserInfo := c.GetAdminUserInfo()
  1695. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1696. if patientInfo.ID == 0 {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1698. return
  1699. }
  1700. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1701. if appRole.UserType == 3 {
  1702. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1703. if getPermissionErr != nil {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1705. return
  1706. } else if headNursePermission == nil {
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1708. return
  1709. }
  1710. }
  1711. var advice models.DoctorAdvice
  1712. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1713. if code > 0 {
  1714. c.ServeFailJSONWithSGJErrorCode(code)
  1715. return
  1716. }
  1717. if advice.ParentId > 0 {
  1718. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1719. if old.ID == 0 || old.PatientId != patient {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1721. return
  1722. }
  1723. if old.StopState == 1 || old.ExecutionState == 1 {
  1724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1725. return
  1726. }
  1727. if old.ParentId > 0 {
  1728. advice.ParentId = old.ParentId
  1729. }
  1730. advice.StartTime = old.StartTime
  1731. advice.AdviceDoctor = old.AdviceDoctor
  1732. advice.DeliveryWay = old.DeliveryWay
  1733. advice.ExecutionFrequency = old.ExecutionFrequency
  1734. advice.GroupNo = old.GroupNo
  1735. }
  1736. advice.Status = 1
  1737. advice.CreatedTime = time.Now().Unix()
  1738. advice.UpdatedTime = time.Now().Unix()
  1739. advice.StopState = 2
  1740. advice.ExecutionState = 2
  1741. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1742. advice.PatientId = patient
  1743. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1744. // 查询信息规挡的设置天数
  1745. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1746. if infor.ID > 0 && infor.WeekDay > 0 {
  1747. var cha_time int64
  1748. timeNowStr := time.Now().Format("2006-01-02")
  1749. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1750. //今日的日期减去设置的日期
  1751. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1752. if cha_time >= advice.AdviceDate {
  1753. //查询审核是否允许
  1754. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1755. //申请状态不允许的情况 拒绝修改
  1756. if infor.ApplicationStatus != 1 {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1758. return
  1759. }
  1760. }
  1761. }
  1762. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1763. if advice.PrescribingNumber == 0 {
  1764. advice.PrescribingNumber = 1
  1765. }
  1766. //查询该患者今日有没有双人核对
  1767. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1768. if check.ID > 0 {
  1769. advice.Checker = check.Modifier
  1770. advice.CheckState = 1
  1771. advice.CheckTime = time.Now().Unix()
  1772. }
  1773. }
  1774. err := service.CreateDoctorAdvice(&advice)
  1775. //记录日志
  1776. byterequest, _ := json.Marshal(advice)
  1777. adviceLog := models.XtDoctorAdviceLog{
  1778. UserOrgId: advice.UserOrgId,
  1779. PatientId: advice.PatientId,
  1780. AdminUserId: adminUserInfo.AdminUser.Id,
  1781. Module: 1,
  1782. ErrLog: string(byterequest),
  1783. Status: 1,
  1784. Ctime: time.Now().Unix(),
  1785. Mtime: 0,
  1786. Source: "电脑新增医嘱",
  1787. RecordDate: advice.RecordDate,
  1788. }
  1789. service.CreateDoctorAdviceLog(adviceLog)
  1790. //创建步骤表
  1791. finish := models.XtDialysisFinish{
  1792. IsFinish: 1,
  1793. UserOrgId: adminUserInfo.CurrentOrgId,
  1794. Status: 1,
  1795. Ctime: time.Now().Unix(),
  1796. Mtime: 0,
  1797. Module: 4,
  1798. RecordDate: advice.AdviceDate,
  1799. Sourse: 1,
  1800. PatientId: patient,
  1801. }
  1802. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1803. if dialysisFinish.ID == 0 {
  1804. service.CreateDialysisFinish(finish)
  1805. }
  1806. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1807. redis := service.RedisClient()
  1808. defer redis.Close()
  1809. redis.Set(key, "", time.Second)
  1810. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1811. redis.Set(keyOne, "", time.Second)
  1812. if err != nil {
  1813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1814. return
  1815. }
  1816. c.ServeSuccessJSON(map[string]interface{}{
  1817. "msg": "ok",
  1818. "advice": advice,
  1819. })
  1820. return
  1821. }
  1822. func (c *PatientApiController) ExecGroupAdvice() {
  1823. groupNo, _ := c.GetInt64("groupno", 0)
  1824. executionTime := c.GetString("execution_time")
  1825. if groupNo <= 0 {
  1826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1827. return
  1828. }
  1829. if len(executionTime) <= 0 {
  1830. utils.ErrorLog("execution_time")
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1832. return
  1833. }
  1834. adminUserInfo := c.GetAdminUserInfo()
  1835. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1836. if advice.ID == 0 {
  1837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1838. return
  1839. }
  1840. if advice.ExecutionState == 1 {
  1841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1842. return
  1843. }
  1844. executionStaff := adminUserInfo.AdminUser.Id
  1845. // checker := adminUserInfo.AdminUser.Id
  1846. timeLayout := "2006-01-02 15:04:05"
  1847. loc, _ := time.LoadLocation("Local")
  1848. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1849. if err != nil {
  1850. utils.ErrorLog(err.Error())
  1851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1852. return
  1853. }
  1854. if advice.StartTime > theTime.Unix() {
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1856. return
  1857. }
  1858. exceAdvice := models.DoctorAdvice{
  1859. ExecutionStaff: executionStaff,
  1860. ExecutionTime: theTime.Unix(),
  1861. UpdatedTime: time.Now().Unix(),
  1862. }
  1863. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1864. if err != nil {
  1865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1866. return
  1867. }
  1868. //查询自动扣减是否开启
  1869. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1870. //查询已经执行的医嘱
  1871. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1872. if drugStockConfig.IsOpen == 1 {
  1873. for _, item := range advicelist {
  1874. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1875. //查询这个患者这个患者这个药已经出库的所有数量
  1876. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1877. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1878. var total_count int64
  1879. var drug_count int64
  1880. for _, it := range advicelist {
  1881. if it.PrescribingNumberUnit == medical.MaxUnit {
  1882. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1883. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1884. total_count += prenumber * medical.MinNumber
  1885. }
  1886. if it.PrescribingNumberUnit == medical.MinUnit {
  1887. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1888. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1889. total_count += prenumber
  1890. }
  1891. }
  1892. for _, its := range drugoutlist {
  1893. if its.CountUnit == medical.MaxUnit {
  1894. drug_count += its.Count * medical.MinNumber
  1895. }
  1896. if its.CountUnit == medical.MinUnit {
  1897. drug_count += its.Count
  1898. }
  1899. }
  1900. if total_count == drug_count {
  1901. c.ServeSuccessJSON(map[string]interface{}{
  1902. "msg": "1",
  1903. "advice": advice,
  1904. })
  1905. return
  1906. }
  1907. var total int64
  1908. var prescribing_number_total int64
  1909. //查询默认出库仓库
  1910. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1911. //查询该药品在默认仓库是否有库存
  1912. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1913. //判断单位是否相等
  1914. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1915. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1916. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1917. //转化为最小单位
  1918. total = list.Count*medical.MinNumber + list.StockMinNumber
  1919. prescribing_number_total = count * medical.MinNumber
  1920. }
  1921. if medical.MinUnit == advice.PrescribingNumberUnit {
  1922. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1923. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1924. total = list.Count*medical.MinNumber + list.StockMinNumber
  1925. prescribing_number_total = count
  1926. }
  1927. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1928. c.ServeSuccessJSON(map[string]interface{}{
  1929. "msg": "3",
  1930. "advice": advice,
  1931. })
  1932. return
  1933. }
  1934. if prescribing_number_total > total {
  1935. c.ServeSuccessJSON(map[string]interface{}{
  1936. "msg": "2",
  1937. "advice": advice,
  1938. })
  1939. return
  1940. }
  1941. if prescribing_number_total <= total {
  1942. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1943. if medical.IsUse == 2 {
  1944. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1945. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1946. if drugOutInfo.ID == 0 {
  1947. if item.UserOrgId != 10644 {
  1948. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1949. }
  1950. }
  1951. }
  1952. if pharmacyConfig.IsOpen != 1 {
  1953. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1954. if drugOutInfo.ID == 0 {
  1955. if item.UserOrgId != 10644 {
  1956. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1957. }
  1958. }
  1959. }
  1960. //查询默认仓库
  1961. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1962. //查询默认仓库剩余多少库存
  1963. var sum_count int64
  1964. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1965. for _, its := range stockInfo {
  1966. if its.MaxUnit == medical.MaxUnit {
  1967. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1968. }
  1969. sum_count += its.StockMaxNumber + its.StockMinNumber
  1970. }
  1971. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1972. break
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "msg": "1",
  1975. "advice": advice,
  1976. })
  1977. return
  1978. }
  1979. if medical.IsUse == 1 {
  1980. c.ServeSuccessJSON(map[string]interface{}{
  1981. "msg": "1",
  1982. "advice": advice,
  1983. })
  1984. return
  1985. }
  1986. }
  1987. }
  1988. }
  1989. advice.ExecutionStaff = executionStaff
  1990. advice.ExecutionTime = theTime.Unix()
  1991. c.ServeSuccessJSON(map[string]interface{}{
  1992. "msg": "ok",
  1993. "advice": advice,
  1994. })
  1995. return
  1996. }
  1997. func (c *PatientApiController) ExecDoctorAdvice() {
  1998. origin, _ := c.GetInt64("origin", 0)
  1999. patient, _ := c.GetInt64("patient", 0)
  2000. id, _ := c.GetInt64("id", 0)
  2001. executionTime := c.GetString("execution_time")
  2002. if origin != 2 {
  2003. if id <= 0 || patient <= 0 {
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. if len(executionTime) <= 0 {
  2008. utils.ErrorLog("execution_time")
  2009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2010. return
  2011. }
  2012. adminUserInfo := c.GetAdminUserInfo()
  2013. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2014. //自备药
  2015. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  2016. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  2017. //查询库存是否
  2018. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  2019. if selfBasedrug.IsSelfDrug == 1 {
  2020. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  2021. var prescribing_number_total_one int64
  2022. //判断单位是否相等
  2023. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2024. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2025. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2026. //转化为最小单位
  2027. prescribing_number_total_one = count * selfBasedrug.MinNumber
  2028. }
  2029. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2030. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2031. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2032. prescribing_number_total_one = count
  2033. }
  2034. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2035. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2036. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2037. prescribing_number_total_one = count
  2038. }
  2039. //库存不足
  2040. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  2041. c.ServeSuccessJSON(map[string]interface{}{
  2042. "msg": "2",
  2043. "advice": advice,
  2044. })
  2045. return
  2046. }
  2047. }
  2048. }
  2049. if advice.ID == 0 || advice.PatientId != patient {
  2050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2051. return
  2052. }
  2053. //医嘱已执行
  2054. if advice.ExecutionState == 1 {
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2056. return
  2057. }
  2058. executionStaff := adminUserInfo.AdminUser.Id
  2059. timeLayout := "2006-01-02 15:04:05"
  2060. loc, _ := time.LoadLocation("Local")
  2061. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2062. if err != nil {
  2063. utils.ErrorLog(err.Error())
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2065. return
  2066. }
  2067. if advice.StartTime > theTime.Unix() {
  2068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2069. return
  2070. }
  2071. exceAdvice := models.DoctorAdvice{
  2072. ExecutionStaff: executionStaff,
  2073. ExecutionTime: theTime.Unix(),
  2074. UpdatedTime: time.Now().Unix(),
  2075. }
  2076. // 查询信息规挡的设置天数
  2077. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2078. if infor.ID > 0 && infor.WeekDay > 0 {
  2079. var cha_time int64
  2080. timeNowStr := time.Now().Format("2006-01-02")
  2081. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2082. //今日的日期减去设置的日期
  2083. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2084. if cha_time >= advice.AdviceDate {
  2085. //查询审核是否允许
  2086. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2087. //申请状态不允许的情况 拒绝修改
  2088. if infor.ApplicationStatus != 1 {
  2089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2090. return
  2091. }
  2092. }
  2093. }
  2094. if advice.ParentId > 0 {
  2095. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2096. //记录日志
  2097. byterequest, _ := json.Marshal(exceAdvice)
  2098. doctorAdviceLog := models.XtDoctorAdviceLog{
  2099. UserOrgId: exceAdvice.UserOrgId,
  2100. PatientId: exceAdvice.PatientId,
  2101. AdminUserId: adminUserInfo.AdminUser.Id,
  2102. Module: 2,
  2103. ErrLog: string(byterequest),
  2104. Status: 1,
  2105. Ctime: time.Now().Unix(),
  2106. Mtime: 0,
  2107. Source: "电脑端执行医嘱",
  2108. RecordDate: exceAdvice.RecordDate,
  2109. }
  2110. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2111. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2112. redis := service.RedisClient()
  2113. //清空key 值
  2114. redis.Set(key, "", time.Second)
  2115. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2116. redis.Set(keyTwo, "", time.Second)
  2117. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2118. redis.Set(keyThree, "", time.Second)
  2119. theTimes := theTime.Format("2006-01-02")
  2120. fmt.Println("theTIME", theTime)
  2121. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2122. redis.Set(keyFour, "", time.Second)
  2123. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2124. redis.Set(keyFive, "", time.Second)
  2125. defer redis.Close()
  2126. } else {
  2127. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  2128. //记录日志
  2129. byterequest, _ := json.Marshal(exceAdvice)
  2130. doctorAdviceLog := models.XtDoctorAdviceLog{
  2131. UserOrgId: exceAdvice.UserOrgId,
  2132. PatientId: exceAdvice.PatientId,
  2133. AdminUserId: adminUserInfo.AdminUser.Id,
  2134. Module: 2,
  2135. ErrLog: string(byterequest),
  2136. Status: 1,
  2137. Ctime: time.Now().Unix(),
  2138. Mtime: 0,
  2139. Source: "电脑端执行医嘱",
  2140. RecordDate: exceAdvice.RecordDate,
  2141. }
  2142. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2143. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2144. redis := service.RedisClient()
  2145. //清空key 值
  2146. redis.Set(key, "", time.Second)
  2147. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2148. redis.Set(keyTwo, "", time.Second)
  2149. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2150. redis.Set(keyThree, "", time.Second)
  2151. theTimes := theTime.Format("2006-01-02")
  2152. fmt.Println("theTIME", theTime)
  2153. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2154. redis.Set(keyFour, "", time.Second)
  2155. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2156. redis.Set(keyFive, "", time.Second)
  2157. defer redis.Close()
  2158. }
  2159. if err != nil {
  2160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2161. return
  2162. }
  2163. advice.ExecutionStaff = executionStaff
  2164. advice.ExecutionTime = theTime.Unix()
  2165. //处理出库相关逻辑
  2166. //1.判断是否启用药品管理和自备药出库功能
  2167. //药品管理信息
  2168. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2169. //自备药信息
  2170. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2171. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2172. if drugStockConfig.IsOpen == 1 {
  2173. var total int64
  2174. var prescribing_number_total int64
  2175. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2176. for _, item := range advices {
  2177. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2178. //查询该药品是否有库存
  2179. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2180. //查询改药品信息
  2181. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2182. //判断单位是否相等
  2183. if medical.MaxUnit == item.PrescribingNumberUnit {
  2184. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2185. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2186. //转化为最小单位
  2187. total = list.Count*medical.MinNumber + list.StockMinNumber
  2188. prescribing_number_total = count * medical.MinNumber
  2189. }
  2190. if medical.MinUnit == item.PrescribingNumberUnit {
  2191. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2192. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2193. total = list.Count*medical.MinNumber + list.StockMinNumber
  2194. prescribing_number_total = count
  2195. }
  2196. if medical.IsUse != 1 {
  2197. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2198. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2199. advice.ExecutionState = 2
  2200. advice.ExecutionStaff = 0
  2201. advice.ExecutionTime = 0
  2202. c.ServeSuccessJSON(map[string]interface{}{
  2203. "msg": "3",
  2204. "advice": advice,
  2205. })
  2206. return
  2207. }
  2208. if prescribing_number_total > total {
  2209. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2210. advice.ExecutionState = 2
  2211. advice.ExecutionStaff = 0
  2212. advice.ExecutionTime = 0
  2213. c.ServeSuccessJSON(map[string]interface{}{
  2214. "msg": "2",
  2215. "advice": advice,
  2216. })
  2217. return
  2218. }
  2219. }
  2220. if medical.IsUse == 1 {
  2221. c.ServeSuccessJSON(map[string]interface{}{
  2222. "msg": "1",
  2223. "advice": advice,
  2224. })
  2225. return
  2226. }
  2227. if prescribing_number_total <= total {
  2228. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2229. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2230. if adviceSetting.IsAdviceOpen == 1 {
  2231. //查询是否出库按钮开启
  2232. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2233. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2234. if prescriptionConfig.IsOpen == 1 {
  2235. if medical.IsUse == 2 {
  2236. //是通过药房发药
  2237. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2238. //执行出库
  2239. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2240. if drugOutInfo.ID == 0 {
  2241. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
  2242. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2243. }
  2244. }
  2245. }
  2246. //不通过药房发药
  2247. if pharmacyConfig.IsOpen != 1 {
  2248. //执行出库
  2249. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2250. if drugOutInfo.ID == 0 {
  2251. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
  2252. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2253. }
  2254. }
  2255. }
  2256. //查询默认仓库
  2257. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2258. //查询默认仓库剩余多少库存
  2259. var sum_count int64
  2260. //更新字典里面的库存
  2261. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2262. for _, its := range stockInfo {
  2263. if its.MaxUnit == medical.MaxUnit {
  2264. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2265. }
  2266. sum_count += its.StockMaxNumber + its.StockMinNumber
  2267. }
  2268. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2269. //剩余库存
  2270. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2271. break
  2272. c.ServeSuccessJSON(map[string]interface{}{
  2273. "msg": "1",
  2274. "advice": advice,
  2275. })
  2276. return
  2277. }
  2278. if medical.IsUse == 1 {
  2279. c.ServeSuccessJSON(map[string]interface{}{
  2280. "msg": "1",
  2281. "advice": advice,
  2282. })
  2283. return
  2284. }
  2285. } else {
  2286. if medical.IsUse == 1 {
  2287. c.ServeSuccessJSON(map[string]interface{}{
  2288. "msg": "1",
  2289. "advice": advice,
  2290. })
  2291. return
  2292. }
  2293. }
  2294. } else {
  2295. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2296. if medical.IsUse == 2 {
  2297. //是通过药房发药
  2298. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2299. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2300. if drugOutInfo.ID == 0 {
  2301. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
  2302. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2303. }
  2304. }
  2305. }
  2306. //不通过药房发药
  2307. if pharmacyConfig.IsOpen != 1 {
  2308. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2309. if drugOutInfo.ID == 0 {
  2310. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 {
  2311. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2312. }
  2313. }
  2314. }
  2315. //更新字典里面的库存
  2316. var sum_count int64
  2317. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2318. for _, its := range stockInfo {
  2319. if its.MaxUnit == medical.MaxUnit {
  2320. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2321. }
  2322. sum_count += its.StockMaxNumber + its.StockMinNumber
  2323. }
  2324. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2325. //剩余库存
  2326. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2327. break
  2328. c.ServeSuccessJSON(map[string]interface{}{
  2329. "msg": "1",
  2330. "advice": advice,
  2331. })
  2332. return
  2333. }
  2334. if medical.IsUse == 1 {
  2335. c.ServeSuccessJSON(map[string]interface{}{
  2336. "msg": "1",
  2337. "advice": advice,
  2338. })
  2339. return
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. //自备药
  2346. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  2347. if selfPrescriptionOutOpen.IsOpen == 1 {
  2348. db := service.XTWriteDB()
  2349. tx := db.Begin()
  2350. defer func() {
  2351. if r := recover(); r != nil {
  2352. tx.Rollback()
  2353. } else {
  2354. tx.Commit()
  2355. }
  2356. }()
  2357. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  2358. if selfBasedrug.IsSelfDrug == 1 {
  2359. //查询是否有库存
  2360. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  2361. if len(info) > 0 {
  2362. var total_count int64
  2363. var prescribing_number_total int64
  2364. for _, item := range info {
  2365. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2366. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  2367. }
  2368. total_count += item.StockMaxNumber + item.StockMinNumber
  2369. }
  2370. //判断单位是否相等
  2371. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2372. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2373. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2374. //转化为最小单位
  2375. prescribing_number_total = count * selfBasedrug.MinNumber
  2376. }
  2377. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2378. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2379. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2380. prescribing_number_total = count
  2381. }
  2382. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2383. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2384. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2385. prescribing_number_total = count
  2386. }
  2387. if prescribing_number_total > total_count {
  2388. c.ServeSuccessJSON(map[string]interface{}{
  2389. "msg": "3",
  2390. "advice": advice,
  2391. })
  2392. return
  2393. }
  2394. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2395. //出库
  2396. if prescribing_number_total <= total_count {
  2397. timeStr := time.Now().Format("2006-01-02")
  2398. timeArr := strings.Split(timeStr, "-")
  2399. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  2400. total = total + 1
  2401. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2402. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2403. number = number + total
  2404. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2405. operation_time := time.Now().Unix()
  2406. creater := c.GetAdminUserInfo().AdminUser.Id
  2407. //创建一个出库单
  2408. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2409. WarehouseOutOrderNumber: warehousing_out_order,
  2410. OperationTime: operation_time,
  2411. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2412. Creater: creater,
  2413. Ctime: time.Now().Unix(),
  2414. Status: 1,
  2415. WarehouseOutTime: advice.AdviceDate,
  2416. Type: 0,
  2417. PatientId: advice.PatientId,
  2418. IsCheck: 1,
  2419. IsSys: 1,
  2420. }
  2421. //查询今日是否有出库数据
  2422. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2423. if lastWarehouseOut.ID == 0 {
  2424. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2425. }
  2426. //查询今日是否有出库数据
  2427. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2428. //出库
  2429. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2430. WarehouseOutId: lastWarehouseOutOne.ID,
  2431. WarehouseOutOrderNumber: warehousing_out_order,
  2432. DrugId: advice.DrugId,
  2433. Count: prescribing_number_total,
  2434. Price: 0,
  2435. TotalPrice: 0,
  2436. Status: 1,
  2437. Ctime: advice.AdviceDate,
  2438. Mtime: advice.AdviceDate,
  2439. Remark: "",
  2440. OrgId: advice.UserOrgId,
  2441. Type: 0,
  2442. Manufacturer: selfBasedrug.Manufacturer,
  2443. Dealer: selfBasedrug.Dealer,
  2444. RetailPrice: 0,
  2445. RetailTotalPrice: 0,
  2446. CountUnit: selfBasedrug.MinUnit,
  2447. ExpiryDate: 0,
  2448. ProductDate: 0,
  2449. Number: "",
  2450. BatchNumber: "",
  2451. IsSys: 0,
  2452. WarehouseInfoId: 0,
  2453. AdminUserId: 0,
  2454. StockCount: "",
  2455. IsCheck: 1,
  2456. SysRecordTime: advice.AdviceDate,
  2457. PatientId: advice.PatientId,
  2458. AdviceId: advice.ID,
  2459. ClassType: "",
  2460. }
  2461. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2462. for _, it := range warehousingOutInfo {
  2463. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2464. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2465. //出库逻辑
  2466. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2467. //查询剩余库存
  2468. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2469. var sum_count int64
  2470. for _, its := range stockInfo {
  2471. if its.MaxUnit == medical.MaxUnit {
  2472. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2473. }
  2474. sum_count += its.StockMaxNumber + its.StockMinNumber
  2475. }
  2476. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2477. }
  2478. }
  2479. } else {
  2480. c.ServeSuccessJSON(map[string]interface{}{
  2481. "msg": "3",
  2482. "advice": advice,
  2483. })
  2484. return
  2485. }
  2486. }
  2487. }
  2488. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2489. for _, item := range advices {
  2490. if item.Way == 2 {
  2491. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2492. if item.ExecutionState == 1 {
  2493. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2494. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2495. timeStr := time.Now().Format("2006-01-02")
  2496. timeArr := strings.Split(timeStr, "-")
  2497. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2498. total = total + 1
  2499. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2500. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2501. number = number + total
  2502. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2503. //插入自备药出库单
  2504. outStock := models.XtSelfOutStock{
  2505. DrugName: item.AdviceName,
  2506. DrugNameId: item.DrugId,
  2507. DrugSpec: item.AdviceDesc,
  2508. OutstoreNumber: count,
  2509. AdminUserId: adminUserInfo.AdminUser.Id,
  2510. StorckTime: item.RecordDate,
  2511. UserOrgId: adminUserInfo.CurrentOrgId,
  2512. CreatedTime: time.Now().Unix(),
  2513. Status: 1,
  2514. PatientId: item.PatientId,
  2515. ExitMode: 2,
  2516. MedicId: item.DrugId,
  2517. StockOutNumber: warehousing_out_order,
  2518. }
  2519. service.CreateOutStock(&outStock)
  2520. }
  2521. }
  2522. }
  2523. }
  2524. c.ServeSuccessJSON(map[string]interface{}{
  2525. "msg": "1",
  2526. "advice": advice,
  2527. })
  2528. return
  2529. } else {
  2530. if id <= 0 || patient <= 0 {
  2531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2532. return
  2533. }
  2534. if len(executionTime) <= 0 {
  2535. utils.ErrorLog("execution_time")
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2537. return
  2538. }
  2539. adminUserInfo := c.GetAdminUserInfo()
  2540. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2541. if advice.ID == 0 || advice.PatientId != patient {
  2542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2543. return
  2544. }
  2545. //医嘱已执行
  2546. if advice.ExecutionState == 1 {
  2547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2548. return
  2549. }
  2550. executionStaff := adminUserInfo.AdminUser.Id
  2551. timeLayout := "2006-01-02 15:04:05"
  2552. loc, _ := time.LoadLocation("Local")
  2553. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2554. if err != nil {
  2555. utils.ErrorLog(err.Error())
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2557. return
  2558. }
  2559. if advice.StartTime > theTime.Unix() {
  2560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2561. return
  2562. }
  2563. exceAdvice := models.HisDoctorAdviceInfo{
  2564. ExecutionStaff: executionStaff,
  2565. ExecutionTime: theTime.Unix(),
  2566. UpdatedTime: time.Now().Unix(),
  2567. }
  2568. if advice.ParentId > 0 {
  2569. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2570. //记录日志
  2571. byterequest, _ := json.Marshal(exceAdvice)
  2572. doctorAdviceLog := models.XtDoctorAdviceLog{
  2573. UserOrgId: exceAdvice.UserOrgId,
  2574. PatientId: exceAdvice.PatientId,
  2575. AdminUserId: adminUserInfo.AdminUser.Id,
  2576. Module: 2,
  2577. ErrLog: string(byterequest),
  2578. Status: 1,
  2579. Ctime: time.Now().Unix(),
  2580. Mtime: 0,
  2581. Source: "电脑端执行His医嘱",
  2582. RecordDate: exceAdvice.RecordDate,
  2583. }
  2584. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2585. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2586. redis := service.RedisClient()
  2587. //清空key 值
  2588. redis.Set(key, "", time.Second)
  2589. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2590. redis.Set(keyTwo, "", time.Second)
  2591. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2592. redis.Set(keyThree, "", time.Second)
  2593. theTimes := theTime.Format("2006-01-02")
  2594. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2595. redis.Set(keyFour, "", time.Second)
  2596. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2597. redis.Set(keyFive, "", time.Second)
  2598. defer redis.Close()
  2599. } else {
  2600. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2601. //记录日志
  2602. byterequest, _ := json.Marshal(exceAdvice)
  2603. doctorAdviceLog := models.XtDoctorAdviceLog{
  2604. UserOrgId: exceAdvice.UserOrgId,
  2605. PatientId: exceAdvice.PatientId,
  2606. AdminUserId: adminUserInfo.AdminUser.Id,
  2607. Module: 2,
  2608. ErrLog: string(byterequest),
  2609. Status: 1,
  2610. Ctime: time.Now().Unix(),
  2611. Mtime: 0,
  2612. Source: "电脑端执行His医嘱",
  2613. RecordDate: exceAdvice.RecordDate,
  2614. }
  2615. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2616. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2617. redis := service.RedisClient()
  2618. //清空key 值
  2619. redis.Set(key, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2623. redis.Set(keyThree, "", time.Second)
  2624. theTimes := theTime.Format("2006-01-02")
  2625. fmt.Println("theTIME", theTime)
  2626. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2627. redis.Set(keyFour, "", time.Second)
  2628. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2629. redis.Set(keyFive, "", time.Second)
  2630. defer redis.Close()
  2631. }
  2632. if err != nil {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2634. return
  2635. }
  2636. advice.ExecutionStaff = executionStaff
  2637. advice.ExecutionTime = theTime.Unix()
  2638. //处理出库相关逻辑
  2639. //1.判断是否启用药品管理和自备药出库功能
  2640. //药品自动出库开关管理信息
  2641. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2642. if drugStockConfig.IsOpen == 1 {
  2643. //查询已经执行的医嘱
  2644. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2645. for _, item := range advices {
  2646. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2647. var total int64
  2648. var prescribing_number_total int64
  2649. //药品保存处方出库
  2650. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2651. if config.IsOpen != 1 {
  2652. //查询默认出库仓库
  2653. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2654. //查询该药品在默认仓库是否有库存
  2655. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2656. //判断单位是否相等
  2657. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2658. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2659. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2660. //转化为最小单位
  2661. total = list.Count*medical.MinNumber + list.StockMinNumber
  2662. prescribing_number_total = count * medical.MinNumber
  2663. }
  2664. if medical.MinUnit == advice.PrescribingNumberUnit {
  2665. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2666. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2667. total = list.Count*medical.MinNumber + list.StockMinNumber
  2668. prescribing_number_total = count
  2669. }
  2670. if medical.IsUse == 1 {
  2671. drugError := models.XtDrugError{
  2672. UserOrgId: item.UserOrgId,
  2673. DrugId: item.DrugId,
  2674. RecordDate: item.AdviceDate,
  2675. PatientId: item.PatientId,
  2676. Remark: "电脑端零用药品",
  2677. Status: 1,
  2678. Ctime: time.Now().Unix(),
  2679. Mtime: 0,
  2680. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2681. Prescribingnumber: item.PrescribingNumber,
  2682. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2683. }
  2684. service.CreateDrugError(drugError)
  2685. c.ServeSuccessJSON(map[string]interface{}{
  2686. "msg": "1",
  2687. "advice": advice,
  2688. })
  2689. return
  2690. }
  2691. if medical.IsUse != 1 {
  2692. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2693. drugError := models.XtDrugError{
  2694. UserOrgId: item.UserOrgId,
  2695. DrugId: item.DrugId,
  2696. RecordDate: item.AdviceDate,
  2697. PatientId: item.PatientId,
  2698. Remark: "电脑端药品库存不足",
  2699. Status: 1,
  2700. Ctime: time.Now().Unix(),
  2701. Mtime: 0,
  2702. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2703. Prescribingnumber: item.PrescribingNumber,
  2704. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2705. }
  2706. service.CreateDrugError(drugError)
  2707. c.ServeSuccessJSON(map[string]interface{}{
  2708. "msg": "3",
  2709. "advice": advice,
  2710. })
  2711. return
  2712. }
  2713. if prescribing_number_total > total {
  2714. drugError := models.XtDrugError{
  2715. UserOrgId: item.UserOrgId,
  2716. DrugId: item.DrugId,
  2717. RecordDate: item.AdviceDate,
  2718. PatientId: item.PatientId,
  2719. Remark: "电脑端出库数量大于总库存",
  2720. Status: 1,
  2721. Ctime: time.Now().Unix(),
  2722. Mtime: 0,
  2723. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2724. Prescribingnumber: item.PrescribingNumber,
  2725. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2726. }
  2727. service.CreateDrugError(drugError)
  2728. c.ServeSuccessJSON(map[string]interface{}{
  2729. "msg": "2",
  2730. "advice": advice,
  2731. })
  2732. return
  2733. }
  2734. }
  2735. if prescribing_number_total <= total {
  2736. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2737. if medical.IsUse == 2 {
  2738. if config.IsOpen != 1 {
  2739. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2740. // 开始主事务
  2741. db := service.XTWriteDB()
  2742. tx := db.Begin()
  2743. // 在函数结束时处理事务回滚
  2744. defer func() {
  2745. if r := recover(); r != nil {
  2746. tx.Rollback()
  2747. }
  2748. }()
  2749. creater := c.GetAdminUserInfo().AdminUser.Id
  2750. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2751. var out_count int64
  2752. if len(outListExport) > 0 {
  2753. for _, item := range outListExport {
  2754. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2755. out_count = item.Count * medical.MinNumber
  2756. }
  2757. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2758. out_count = item.Count
  2759. }
  2760. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2761. out_count = item.Count * medical.MinNumber
  2762. }
  2763. }
  2764. }
  2765. newadviceInfo := &models.HisDoctorAdviceInfo{
  2766. ID: item.ID,
  2767. UserOrgId: item.UserOrgId,
  2768. PatientId: item.PatientId,
  2769. HisPatientId: item.HisPatientId,
  2770. AdviceType: item.AdviceType,
  2771. AdviceDate: item.AdviceDate,
  2772. StartTime: item.StartTime,
  2773. AdviceName: item.AdviceName,
  2774. AdviceDesc: item.AdviceDesc,
  2775. ReminderDate: item.ReminderDate,
  2776. SingleDose: item.SingleDose,
  2777. SingleDoseUnit: item.SingleDoseUnit,
  2778. PrescribingNumber: item.PrescribingNumber,
  2779. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2780. DeliveryWay: item.DeliveryWay,
  2781. ExecutionFrequency: item.ExecutionFrequency,
  2782. AdviceDoctor: item.AdviceDoctor,
  2783. Status: item.Status,
  2784. CreatedTime: item.CreatedTime,
  2785. UpdatedTime: item.UpdatedTime,
  2786. AdviceAffirm: item.AdviceAffirm,
  2787. Remark: item.Remark,
  2788. StopTime: item.StopTime,
  2789. StopReason: item.StopReason,
  2790. StopDoctor: item.StopDoctor,
  2791. StopState: item.StopState,
  2792. ParentId: item.ParentId,
  2793. ExecutionTime: item.ExecutionTime,
  2794. ExecutionStaff: item.ExecutionStaff,
  2795. ExecutionState: item.ExecutionState,
  2796. Checker: item.Checker,
  2797. RecordDate: item.RecordDate,
  2798. DialysisOrderId: item.DialysisOrderId,
  2799. CheckTime: item.CheckTime,
  2800. CheckState: item.CheckState,
  2801. DrugSpec: item.DrugSpec,
  2802. DrugSpecUnit: item.DrugSpecUnit,
  2803. Groupno: item.Groupno,
  2804. RemindType: item.RemindType,
  2805. FrequencyType: item.FrequencyType,
  2806. DayCount: item.DayCount,
  2807. WeekDay: item.WeekDay,
  2808. TemplateId: item.TemplateId,
  2809. Modifier: item.Modifier,
  2810. DrugId: item.DrugId,
  2811. Price: item.Price,
  2812. PrescriptionId: item.PrescriptionId,
  2813. MedListCodg: item.MedListCodg,
  2814. FeedetlSn: item.FeedetlSn,
  2815. Day: item.DayCount,
  2816. ChildDoctorAdvice: nil,
  2817. Drug: models.Drug{},
  2818. Diagnosis: item.Diagnosis,
  2819. Way: item.Way,
  2820. HospApprFlag: item.HospApprFlag,
  2821. LmtUsedFlag: item.LmtUsedFlag,
  2822. HisOrderInfo: models.HisOrderInfo{},
  2823. IsMedicine: item.IsMedicine,
  2824. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2825. Child: nil,
  2826. IsSettle: item.IsSettle,
  2827. IsMobile: item.IsMobile,
  2828. IsSelfDrug: item.IsSelfDrug,
  2829. DrugWayCount: item.DrugWayCount,
  2830. }
  2831. //如果当前医嘱数量大于历史出库数据则需要出库
  2832. if prescribing_number_total > out_count {
  2833. //按最小单位出库
  2834. var cha_count = prescribing_number_total - out_count
  2835. item.PrescribingNumber = float64(cha_count)
  2836. item.PrescribingNumberUnit = medical.MinUnit
  2837. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2838. }
  2839. //如果当前医嘱数量小于历史出库数据则需要退库
  2840. if prescribing_number_total < out_count {
  2841. var cha_count = out_count - prescribing_number_total
  2842. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2843. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2844. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2845. }
  2846. if prescribing_number_total == out_count {
  2847. if out_count == 0 {
  2848. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2849. }
  2850. }
  2851. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2852. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2853. //查询该药品是否有出库记录
  2854. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2855. if len(flowMap) == 0 {
  2856. errs := service.UpdateHisAdviceById(item.ID)
  2857. if errs != nil {
  2858. drugError := models.XtDrugError{
  2859. UserOrgId: item.UserOrgId,
  2860. DrugId: item.DrugId,
  2861. RecordDate: item.AdviceDate,
  2862. PatientId: item.PatientId,
  2863. Remark: "出库记录为空,更新执行人失败",
  2864. Status: 1,
  2865. Ctime: time.Now().Unix(),
  2866. Mtime: 0,
  2867. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2868. Prescribingnumber: item.PrescribingNumber,
  2869. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2870. }
  2871. service.CreateDrugError(drugError)
  2872. }
  2873. c.ServeSuccessJSON(map[string]interface{}{
  2874. "msg": "6",
  2875. "advice": advice,
  2876. })
  2877. return
  2878. }
  2879. }
  2880. tx.Commit()
  2881. }
  2882. //不通过药房发药
  2883. if pharmacyConfig.IsOpen != 1 {
  2884. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2885. // 开始主事务
  2886. db := service.XTWriteDB()
  2887. tx := db.Begin()
  2888. // 在函数结束时处理事务回滚
  2889. defer func() {
  2890. if r := recover(); r != nil {
  2891. tx.Rollback()
  2892. }
  2893. }()
  2894. creater := c.GetAdminUserInfo().AdminUser.Id
  2895. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2896. var out_count int64
  2897. if len(outListExport) > 0 {
  2898. for _, item := range outListExport {
  2899. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2900. out_count = item.Count * medical.MinNumber
  2901. }
  2902. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2903. out_count = item.Count
  2904. }
  2905. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2906. out_count = item.Count * medical.MinNumber
  2907. }
  2908. }
  2909. }
  2910. newadviceInfo := &models.HisDoctorAdviceInfo{
  2911. ID: item.ID,
  2912. UserOrgId: item.UserOrgId,
  2913. PatientId: item.PatientId,
  2914. HisPatientId: item.HisPatientId,
  2915. AdviceType: item.AdviceType,
  2916. AdviceDate: item.AdviceDate,
  2917. StartTime: item.StartTime,
  2918. AdviceName: item.AdviceName,
  2919. AdviceDesc: item.AdviceDesc,
  2920. ReminderDate: item.ReminderDate,
  2921. SingleDose: item.SingleDose,
  2922. SingleDoseUnit: item.SingleDoseUnit,
  2923. PrescribingNumber: item.PrescribingNumber,
  2924. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2925. DeliveryWay: item.DeliveryWay,
  2926. ExecutionFrequency: item.ExecutionFrequency,
  2927. AdviceDoctor: item.AdviceDoctor,
  2928. Status: item.Status,
  2929. CreatedTime: item.CreatedTime,
  2930. UpdatedTime: item.UpdatedTime,
  2931. AdviceAffirm: item.AdviceAffirm,
  2932. Remark: item.Remark,
  2933. StopTime: item.StopTime,
  2934. StopReason: item.StopReason,
  2935. StopDoctor: item.StopDoctor,
  2936. StopState: item.StopState,
  2937. ParentId: item.ParentId,
  2938. ExecutionTime: item.ExecutionTime,
  2939. ExecutionStaff: item.ExecutionStaff,
  2940. ExecutionState: item.ExecutionState,
  2941. Checker: item.Checker,
  2942. RecordDate: item.RecordDate,
  2943. DialysisOrderId: item.DialysisOrderId,
  2944. CheckTime: item.CheckTime,
  2945. CheckState: item.CheckState,
  2946. DrugSpec: item.DrugSpec,
  2947. DrugSpecUnit: item.DrugSpecUnit,
  2948. Groupno: item.Groupno,
  2949. RemindType: item.RemindType,
  2950. FrequencyType: item.FrequencyType,
  2951. DayCount: item.DayCount,
  2952. WeekDay: item.WeekDay,
  2953. TemplateId: item.TemplateId,
  2954. Modifier: item.Modifier,
  2955. DrugId: item.DrugId,
  2956. Price: item.Price,
  2957. PrescriptionId: item.PrescriptionId,
  2958. MedListCodg: item.MedListCodg,
  2959. FeedetlSn: item.FeedetlSn,
  2960. Day: item.DayCount,
  2961. ChildDoctorAdvice: nil,
  2962. Drug: models.Drug{},
  2963. Diagnosis: item.Diagnosis,
  2964. Way: item.Way,
  2965. HospApprFlag: item.HospApprFlag,
  2966. LmtUsedFlag: item.LmtUsedFlag,
  2967. HisOrderInfo: models.HisOrderInfo{},
  2968. IsMedicine: item.IsMedicine,
  2969. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2970. Child: nil,
  2971. IsSettle: item.IsSettle,
  2972. IsMobile: item.IsMobile,
  2973. IsSelfDrug: item.IsSelfDrug,
  2974. DrugWayCount: item.DrugWayCount,
  2975. }
  2976. //如果当前医嘱数量大于历史出库数据则需要出库
  2977. if prescribing_number_total > out_count {
  2978. //按最小单位出库
  2979. var cha_count = prescribing_number_total - out_count
  2980. newadviceInfo.PrescribingNumber = float64(cha_count)
  2981. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2982. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2983. }
  2984. //如果当前医嘱数量小于历史出库数据则需要退库
  2985. if prescribing_number_total < out_count {
  2986. var cha_count = out_count - prescribing_number_total
  2987. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2988. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2989. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2990. }
  2991. if prescribing_number_total == out_count {
  2992. if out_count == 0 {
  2993. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2994. }
  2995. }
  2996. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2997. tx.Commit()
  2998. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2999. //查询该药品是否有出库记录
  3000. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  3001. if len(flowMap) == 0 {
  3002. errs := service.UpdateHisAdviceById(item.ID)
  3003. if errs != nil {
  3004. drugError := models.XtDrugError{
  3005. UserOrgId: item.UserOrgId,
  3006. DrugId: item.DrugId,
  3007. RecordDate: item.AdviceDate,
  3008. PatientId: item.PatientId,
  3009. Remark: "出库记录为空,更新执行人失败",
  3010. Status: 1,
  3011. Ctime: time.Now().Unix(),
  3012. Mtime: 0,
  3013. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  3014. Prescribingnumber: item.PrescribingNumber,
  3015. PrescribingNumberUnit: item.PrescribingNumberUnit,
  3016. }
  3017. service.CreateDrugError(drugError)
  3018. }
  3019. c.ServeSuccessJSON(map[string]interface{}{
  3020. "msg": "6",
  3021. "advice": advice,
  3022. })
  3023. return
  3024. }
  3025. }
  3026. }
  3027. //查询默认仓库
  3028. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3029. //查询默认仓库剩余多少库存
  3030. var sum_count int64
  3031. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3032. for _, its := range stockInfo {
  3033. if its.MaxUnit == medical.MaxUnit {
  3034. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3035. }
  3036. sum_count += its.StockMaxNumber + its.StockMinNumber
  3037. }
  3038. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3039. //出库数量累加
  3040. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  3041. //剩余库存
  3042. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  3043. break
  3044. c.ServeSuccessJSON(map[string]interface{}{
  3045. "msg": "1",
  3046. "advice": advice,
  3047. })
  3048. return
  3049. }
  3050. }
  3051. if medical.IsUse == 1 {
  3052. c.ServeSuccessJSON(map[string]interface{}{
  3053. "msg": "1",
  3054. "advice": advice,
  3055. })
  3056. return
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. //自备药
  3063. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3064. if selfPrescriptionOutOpen.IsOpen == 1 {
  3065. db := service.XTWriteDB()
  3066. tx := db.Begin()
  3067. defer func() {
  3068. if r := recover(); r != nil {
  3069. tx.Rollback()
  3070. } else {
  3071. tx.Commit()
  3072. }
  3073. }()
  3074. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  3075. if selfBasedrug.IsSelfDrug == 1 {
  3076. //查询是否有库存
  3077. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  3078. if len(info) > 0 {
  3079. var total_count int64
  3080. var prescribing_number_total int64
  3081. for _, item := range info {
  3082. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3083. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  3084. }
  3085. total_count += item.StockMaxNumber + item.StockMinNumber
  3086. }
  3087. //判断单位是否相等
  3088. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3089. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3090. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3091. //转化为最小单位
  3092. prescribing_number_total = count * selfBasedrug.MinNumber
  3093. }
  3094. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3095. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3096. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3097. prescribing_number_total = count
  3098. }
  3099. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  3100. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3101. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3102. prescribing_number_total = count
  3103. }
  3104. if prescribing_number_total > total_count {
  3105. c.ServeSuccessJSON(map[string]interface{}{
  3106. "msg": "3",
  3107. "advice": advice,
  3108. })
  3109. return
  3110. }
  3111. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  3112. //出库
  3113. if prescribing_number_total <= total_count {
  3114. timeStr := time.Now().Format("2006-01-02")
  3115. timeArr := strings.Split(timeStr, "-")
  3116. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  3117. total = total + 1
  3118. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3119. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3120. number = number + total
  3121. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3122. operation_time := time.Now().Unix()
  3123. creater := c.GetAdminUserInfo().AdminUser.Id
  3124. //创建一个出库单
  3125. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  3126. WarehouseOutOrderNumber: warehousing_out_order,
  3127. OperationTime: operation_time,
  3128. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3129. Creater: creater,
  3130. Ctime: time.Now().Unix(),
  3131. Status: 1,
  3132. WarehouseOutTime: advice.AdviceDate,
  3133. Type: 0,
  3134. PatientId: advice.PatientId,
  3135. IsCheck: 1,
  3136. IsSys: 1,
  3137. }
  3138. //查询今日是否有出库数据
  3139. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3140. if lastWarehouseOut.ID == 0 {
  3141. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  3142. }
  3143. //查询今日是否有出库数据
  3144. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3145. //出库
  3146. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  3147. WarehouseOutId: lastWarehouseOutOne.ID,
  3148. WarehouseOutOrderNumber: warehousing_out_order,
  3149. DrugId: advice.DrugId,
  3150. Count: prescribing_number_total,
  3151. Price: 0,
  3152. TotalPrice: 0,
  3153. Status: 1,
  3154. Ctime: advice.AdviceDate,
  3155. Mtime: advice.AdviceDate,
  3156. Remark: "",
  3157. OrgId: advice.UserOrgId,
  3158. Type: 0,
  3159. Manufacturer: selfBasedrug.Manufacturer,
  3160. Dealer: selfBasedrug.Dealer,
  3161. RetailPrice: 0,
  3162. RetailTotalPrice: 0,
  3163. CountUnit: selfBasedrug.MinUnit,
  3164. ExpiryDate: 0,
  3165. ProductDate: 0,
  3166. Number: "",
  3167. BatchNumber: "",
  3168. IsSys: 0,
  3169. WarehouseInfoId: 0,
  3170. AdminUserId: 0,
  3171. StockCount: "",
  3172. IsCheck: 1,
  3173. SysRecordTime: advice.AdviceDate,
  3174. PatientId: advice.PatientId,
  3175. AdviceId: advice.ID,
  3176. ClassType: "",
  3177. }
  3178. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  3179. for _, it := range warehousingOutInfo {
  3180. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  3181. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  3182. //出库逻辑
  3183. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  3184. //查询剩余库存
  3185. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  3186. var sum_count int64
  3187. for _, its := range stockInfo {
  3188. if its.MaxUnit == medical.MaxUnit {
  3189. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3190. }
  3191. sum_count += its.StockMaxNumber + its.StockMinNumber
  3192. }
  3193. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  3194. }
  3195. }
  3196. }
  3197. }
  3198. }
  3199. c.ServeSuccessJSON(map[string]interface{}{
  3200. "msg": "1",
  3201. "advice": advice,
  3202. })
  3203. return
  3204. }
  3205. }
  3206. func (c *PatientApiController) CheckGroupAdvice() {
  3207. groupno, _ := c.GetInt64("groupno", 0)
  3208. if groupno <= 0 {
  3209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3210. return
  3211. }
  3212. adminUserInfo := c.GetAdminUserInfo()
  3213. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  3214. if advice.ID == 0 {
  3215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3216. return
  3217. }
  3218. if advice.CheckState == 1 {
  3219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3220. return
  3221. }
  3222. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3224. return
  3225. }
  3226. checker := adminUserInfo.AdminUser.Id
  3227. theTime := time.Now()
  3228. exceAdvice := models.DoctorAdvice{
  3229. Checker: checker,
  3230. CheckTime: theTime.Unix(),
  3231. UpdatedTime: time.Now().Unix(),
  3232. }
  3233. var err error
  3234. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  3235. if err != nil {
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3237. return
  3238. }
  3239. advice.Checker = checker
  3240. advice.CheckTime = theTime.Unix()
  3241. c.ServeSuccessJSON(map[string]interface{}{
  3242. "msg": "ok",
  3243. "advice": advice,
  3244. })
  3245. return
  3246. }
  3247. func (c *PatientApiController) CheckDoctorAdvice() {
  3248. patient, _ := c.GetInt64("patient", 0)
  3249. id, _ := c.GetInt64("id", 0)
  3250. origin, _ := c.GetInt64("origin", 0)
  3251. if origin != 2 {
  3252. // executionTime := c.GetString("execution_time")
  3253. if id <= 0 || patient <= 0 {
  3254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3255. return
  3256. }
  3257. adminUserInfo := c.GetAdminUserInfo()
  3258. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3259. if advice.ID == 0 || advice.PatientId != patient {
  3260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3261. return
  3262. }
  3263. if advice.CheckState == 1 {
  3264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3265. return
  3266. }
  3267. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3269. return
  3270. }
  3271. // executionStaff := adminUserInfo.AdminUser.Id
  3272. checker := adminUserInfo.AdminUser.Id
  3273. // timeLayout := "2006-01-02 15:04:05"
  3274. // loc, _ := time.LoadLocation("Local")
  3275. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  3276. // if err != nil {
  3277. // utils.ErrorLog(err.Error())
  3278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3279. // return
  3280. // }
  3281. theTime := time.Now()
  3282. if advice.ExecutionTime > theTime.Unix() {
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3284. return
  3285. }
  3286. exceAdvice := models.DoctorAdvice{
  3287. Checker: checker,
  3288. CheckTime: theTime.Unix(),
  3289. UpdatedTime: time.Now().Unix(),
  3290. }
  3291. var err error
  3292. // 查询信息规挡的设置天数
  3293. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3294. if infor.ID > 0 && infor.WeekDay > 0 {
  3295. var cha_time int64
  3296. timeNowStr := time.Now().Format("2006-01-02")
  3297. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3298. //今日的日期减去设置的日期
  3299. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3300. if cha_time >= advice.AdviceDate {
  3301. //查询审核是否允许
  3302. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3303. //申请状态不允许的情况 拒绝修改
  3304. if infor.ApplicationStatus != 1 {
  3305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3306. return
  3307. }
  3308. }
  3309. }
  3310. if advice.ParentId > 0 {
  3311. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3312. //记录日志
  3313. byterequest, _ := json.Marshal(exceAdvice)
  3314. adviceLog := models.XtDoctorAdviceLog{
  3315. UserOrgId: exceAdvice.UserOrgId,
  3316. PatientId: exceAdvice.PatientId,
  3317. AdminUserId: adminUserInfo.AdminUser.Id,
  3318. Module: 3,
  3319. ErrLog: string(byterequest),
  3320. Status: 1,
  3321. Ctime: time.Now().Unix(),
  3322. Mtime: 0,
  3323. Source: "核对医嘱",
  3324. RecordDate: exceAdvice.AdviceDate,
  3325. }
  3326. service.CreateDoctorAdviceLog(adviceLog)
  3327. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3328. redis := service.RedisClient()
  3329. //清空key 值
  3330. redis.Set(key, "", time.Second)
  3331. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3332. redis.Set(keyTwo, "", time.Second)
  3333. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3334. redis.Set(keyThree, "", time.Second)
  3335. recordDate := theTime.Format("2006-01-02")
  3336. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3337. redis.Set(keyFour, "", time.Second)
  3338. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3339. redis.Set(keyFive, "", time.Second)
  3340. } else {
  3341. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  3342. //记录日志
  3343. byterequest, _ := json.Marshal(exceAdvice)
  3344. adviceLog := models.XtDoctorAdviceLog{
  3345. UserOrgId: exceAdvice.UserOrgId,
  3346. PatientId: exceAdvice.PatientId,
  3347. AdminUserId: adminUserInfo.AdminUser.Id,
  3348. Module: 3,
  3349. ErrLog: string(byterequest),
  3350. Status: 1,
  3351. Ctime: time.Now().Unix(),
  3352. Mtime: 0,
  3353. Source: "核对医嘱",
  3354. RecordDate: exceAdvice.AdviceDate,
  3355. }
  3356. service.CreateDoctorAdviceLog(adviceLog)
  3357. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3358. redis := service.RedisClient()
  3359. //清空key 值
  3360. redis.Set(key, "", time.Second)
  3361. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3362. redis.Set(keyTwo, "", time.Second)
  3363. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3364. redis.Set(keyThree, "", time.Second)
  3365. recordDate := theTime.Format("2006-01-02")
  3366. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3367. redis.Set(keyFour, "", time.Second)
  3368. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3369. redis.Set(keyFive, "", time.Second)
  3370. }
  3371. if err != nil {
  3372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3373. return
  3374. }
  3375. // advice.ExecutionStaff = executionStaff
  3376. // advice.ExecutionTime = theTime.Unix()
  3377. advice.Checker = checker
  3378. advice.CheckTime = theTime.Unix()
  3379. c.ServeSuccessJSON(map[string]interface{}{
  3380. "msg": "ok",
  3381. "advice": advice,
  3382. })
  3383. return
  3384. } else {
  3385. if id <= 0 || patient <= 0 {
  3386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3387. return
  3388. }
  3389. adminUserInfo := c.GetAdminUserInfo()
  3390. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3391. if advice.ID == 0 || advice.PatientId != patient {
  3392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3393. return
  3394. }
  3395. if advice.CheckState == 1 {
  3396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3397. return
  3398. }
  3399. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3401. return
  3402. }
  3403. checker := adminUserInfo.AdminUser.Id
  3404. theTime := time.Now()
  3405. if advice.ExecutionTime > theTime.Unix() {
  3406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3407. return
  3408. }
  3409. exceAdvice := models.HisDoctorAdviceInfo{
  3410. Checker: checker,
  3411. CheckTime: theTime.Unix(),
  3412. UpdatedTime: time.Now().Unix(),
  3413. }
  3414. var err error
  3415. if advice.ParentId > 0 {
  3416. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3417. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3418. redis := service.RedisClient()
  3419. //清空key 值
  3420. redis.Set(key, "", time.Second)
  3421. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3422. redis.Set(keyTwo, "", time.Second)
  3423. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3424. redis.Set(keyThree, "", time.Second)
  3425. recordDate := theTime.Format("2006-01-02")
  3426. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3427. redis.Set(keyFour, "", time.Second)
  3428. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3429. redis.Set(keyFive, "", time.Second)
  3430. } else {
  3431. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  3432. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3433. redis := service.RedisClient()
  3434. //清空key 值
  3435. redis.Set(key, "", time.Second)
  3436. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3437. redis.Set(keyTwo, "", time.Second)
  3438. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3439. redis.Set(keyThree, "", time.Second)
  3440. recordDate := theTime.Format("2006-01-02")
  3441. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3442. redis.Set(keyFour, "", time.Second)
  3443. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3444. redis.Set(keyFive, "", time.Second)
  3445. }
  3446. if err != nil {
  3447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3448. return
  3449. }
  3450. // advice.ExecutionStaff = executionStaff
  3451. // advice.ExecutionTime = theTime.Unix()
  3452. advice.Checker = checker
  3453. advice.CheckTime = theTime.Unix()
  3454. c.ServeSuccessJSON(map[string]interface{}{
  3455. "msg": "ok",
  3456. "advice": advice,
  3457. })
  3458. return
  3459. }
  3460. }
  3461. func (c *PatientApiController) UpdateDoctorAdvice() {
  3462. patient, _ := c.GetInt64("patient", 0)
  3463. id, _ := c.GetInt64("id", 0)
  3464. if id <= 0 || patient <= 0 {
  3465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3466. return
  3467. }
  3468. adminUserInfo := c.GetAdminUserInfo()
  3469. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3470. if advice.ID == 0 || advice.PatientId != patient {
  3471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3472. return
  3473. }
  3474. //if advice.AdviceType == 1 {
  3475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  3476. // return
  3477. //}
  3478. //if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  3479. // if advice.StopState == 1 || advice.ExecutionState == 1 {
  3480. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3481. // return
  3482. // }
  3483. //}
  3484. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3485. //if appRole.UserType == 3 {
  3486. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3487. // if getPermissionErr != nil {
  3488. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3489. // return
  3490. // } else if headNursePermission == nil {
  3491. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3492. // return
  3493. // }
  3494. //}
  3495. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3496. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  3497. // return
  3498. //}
  3499. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  3500. if code > 0 {
  3501. c.ServeFailJSONWithSGJErrorCode(code)
  3502. return
  3503. }
  3504. advice.UpdatedTime = time.Now().Unix()
  3505. advice.Modifier = adminUserInfo.AdminUser.Id
  3506. // 查询信息规挡的设置天数
  3507. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3508. if infor.ID > 0 && infor.WeekDay > 0 {
  3509. var cha_time int64
  3510. timeNowStr := time.Now().Format("2006-01-02")
  3511. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3512. //今日的日期减去设置的日期
  3513. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3514. if cha_time >= advice.AdviceDate {
  3515. //查询审核是否允许
  3516. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3517. //申请状态不允许的情况 拒绝修改
  3518. if infor.ApplicationStatus != 1 {
  3519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3520. return
  3521. }
  3522. }
  3523. }
  3524. err := service.UpdateDoctorAdvice(&advice)
  3525. //记录日志
  3526. byterequest, _ := json.Marshal(advice)
  3527. doctorAdviceLog := models.XtDoctorAdviceLog{
  3528. UserOrgId: advice.UserOrgId,
  3529. PatientId: advice.PatientId,
  3530. AdminUserId: adminUserInfo.AdminUser.Id,
  3531. Module: 1,
  3532. ErrLog: string(byterequest),
  3533. Status: 1,
  3534. Ctime: time.Now().Unix(),
  3535. Mtime: 0,
  3536. Source: "电脑端修改医嘱",
  3537. RecordDate: advice.AdviceDate,
  3538. }
  3539. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3540. redis := service.RedisClient()
  3541. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3542. redis.Set(key, "", time.Second)
  3543. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3544. redis.Set(keyOne, "", time.Second)
  3545. defer redis.Close()
  3546. if err != nil {
  3547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3548. return
  3549. }
  3550. c.ServeSuccessJSON(map[string]interface{}{
  3551. "msg": "ok",
  3552. "advice": advice,
  3553. })
  3554. return
  3555. }
  3556. func (c *PatientApiController) StopGroupAdvice() {
  3557. groupNo, _ := c.GetInt64("groupno", 0)
  3558. if groupNo <= 0 {
  3559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3560. return
  3561. }
  3562. adminUserInfo := c.GetAdminUserInfo()
  3563. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3564. if advice.ID == 0 {
  3565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3566. return
  3567. }
  3568. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3570. return
  3571. }
  3572. dataBody := make(map[string]interface{}, 0)
  3573. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3574. if err != nil {
  3575. utils.ErrorLog(err.Error())
  3576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3577. return
  3578. }
  3579. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3580. utils.ErrorLog("stop_time")
  3581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3582. return
  3583. }
  3584. stopTime, _ := dataBody["stop_time"].(string)
  3585. if len(stopTime) == 0 {
  3586. utils.ErrorLog("len(stop_time) == 0")
  3587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3588. return
  3589. }
  3590. timeLayout := "2006-01-02"
  3591. loc, _ := time.LoadLocation("Local")
  3592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3593. if err != nil {
  3594. utils.ErrorLog(err.Error())
  3595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3596. return
  3597. }
  3598. advice.StopTime = theTime.Unix()
  3599. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3600. stopReason, _ := dataBody["stop_reason"].(string)
  3601. advice.StopReason = stopReason
  3602. }
  3603. advice.UpdatedTime = time.Now().Unix()
  3604. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3605. advice.StopState = 1
  3606. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  3607. if err != nil {
  3608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3609. return
  3610. }
  3611. c.ServeSuccessJSON(map[string]interface{}{
  3612. "msg": "ok",
  3613. })
  3614. return
  3615. }
  3616. func (c *PatientApiController) StopDoctorAdvice() {
  3617. id, _ := c.GetInt64("id", 0)
  3618. if id <= 0 {
  3619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3620. return
  3621. }
  3622. adminUserInfo := c.GetAdminUserInfo()
  3623. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3624. //
  3625. //if appRole.UserType == 3 {
  3626. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3627. // if getPermissionErr != nil {
  3628. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3629. // return
  3630. // } else if headNursePermission == nil {
  3631. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3632. // return
  3633. // }
  3634. //}
  3635. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3636. if advice.ID == 0 {
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3638. return
  3639. }
  3640. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3642. return
  3643. }
  3644. dataBody := make(map[string]interface{}, 0)
  3645. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3646. if err != nil {
  3647. utils.ErrorLog(err.Error())
  3648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3649. return
  3650. }
  3651. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3652. utils.ErrorLog("stop_time")
  3653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3654. return
  3655. }
  3656. stopTime, _ := dataBody["stop_time"].(string)
  3657. if len(stopTime) == 0 {
  3658. utils.ErrorLog("len(stop_time) == 0")
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3660. return
  3661. }
  3662. timeLayout := "2006-01-02"
  3663. loc, _ := time.LoadLocation("Local")
  3664. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3665. if err != nil {
  3666. utils.ErrorLog(err.Error())
  3667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3668. return
  3669. }
  3670. advice.StopTime = theTime.Unix()
  3671. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3672. stopReason, _ := dataBody["stop_reason"].(string)
  3673. advice.StopReason = stopReason
  3674. }
  3675. advice.UpdatedTime = time.Now().Unix()
  3676. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3677. advice.StopState = 1
  3678. err = service.StopDoctorAdvice(&advice)
  3679. if err != nil {
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3681. return
  3682. }
  3683. c.ServeSuccessJSON(map[string]interface{}{
  3684. "msg": "ok",
  3685. "advice": advice,
  3686. })
  3687. return
  3688. }
  3689. func (c *PatientApiController) DeleteDoctorAdvice() {
  3690. id, _ := c.GetInt64("id", 0)
  3691. if id <= 0 {
  3692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3693. return
  3694. }
  3695. adminUserInfo := c.GetAdminUserInfo()
  3696. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3697. if advice.ID == 0 {
  3698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3699. return
  3700. }
  3701. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3702. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3703. // return
  3704. //}
  3705. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3706. //
  3707. //if appRole.UserType == 3 {
  3708. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3709. // if getPermissionErr != nil {
  3710. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3711. // return
  3712. // } else if headNursePermission == nil {
  3713. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3714. // return
  3715. // }
  3716. //}
  3717. advice.UpdatedTime = time.Now().Unix()
  3718. advice.Status = 0
  3719. advice.Modifier = adminUserInfo.AdminUser.Id
  3720. // 查询信息规挡的设置天数
  3721. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3722. if infor.ID > 0 && infor.WeekDay > 0 {
  3723. var cha_time int64
  3724. timeNowStr := time.Now().Format("2006-01-02")
  3725. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3726. //今日的日期减去设置的日期
  3727. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3728. if cha_time >= advice.AdviceDate {
  3729. //查询审核是否允许
  3730. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3731. //申请状态不允许的情况 拒绝修改
  3732. if infor.ApplicationStatus != 1 {
  3733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3734. return
  3735. }
  3736. }
  3737. }
  3738. //自备药
  3739. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3740. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3741. //查询库存是否是自备药
  3742. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3743. if selfBasedrug.IsSelfDrug == 1 {
  3744. creater := adminUserInfo.AdminUser.Id
  3745. //退库
  3746. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3747. }
  3748. }
  3749. err := service.DeleteDoctorAdvice(&advice)
  3750. //记录日志
  3751. byterequest, _ := json.Marshal(advice)
  3752. doctorAdviceLog := models.XtDoctorAdviceLog{
  3753. UserOrgId: advice.UserOrgId,
  3754. PatientId: advice.PatientId,
  3755. AdminUserId: adminUserInfo.AdminUser.Id,
  3756. Module: 4,
  3757. ErrLog: string(byterequest),
  3758. Status: 1,
  3759. Ctime: time.Now().Unix(),
  3760. Mtime: 0,
  3761. Source: "电脑端删除医嘱",
  3762. RecordDate: advice.RecordDate,
  3763. }
  3764. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3765. redis := service.RedisClient()
  3766. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3767. redis.Set(keyOne, "", time.Second)
  3768. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3769. redis.Set(key, "", time.Second)
  3770. redis.Close()
  3771. if err != nil {
  3772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3773. return
  3774. }
  3775. c.ServeSuccessJSON(map[string]interface{}{
  3776. "msg": "ok",
  3777. })
  3778. return
  3779. }
  3780. func (c *PatientApiController) DeleteGroupAdvice() {
  3781. groupNo, _ := c.GetInt64("groupno", 0)
  3782. if groupNo <= 0 {
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3784. return
  3785. }
  3786. adminUserInfo := c.GetAdminUserInfo()
  3787. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3788. if advice.ID == 0 {
  3789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3790. return
  3791. }
  3792. //自备药
  3793. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3794. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3795. //查询库存是否是自备药
  3796. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3797. if selfBasedrug.IsSelfDrug == 1 {
  3798. creater := adminUserInfo.AdminUser.Id
  3799. //退库
  3800. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3801. }
  3802. }
  3803. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3804. //if appRole.UserType == 3 {
  3805. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3806. // if getPermissionErr != nil {
  3807. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3808. // return
  3809. // } else if headNursePermission == nil {
  3810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3811. // return
  3812. // }
  3813. //}
  3814. // 查询信息规挡的设置天数
  3815. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3816. if infor.ID > 0 && infor.WeekDay > 0 {
  3817. var cha_time int64
  3818. timeNowStr := time.Now().Format("2006-01-02")
  3819. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3820. //今日的日期减去设置的日期
  3821. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3822. if cha_time >= advice.AdviceDate {
  3823. //查询审核是否允许
  3824. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3825. //申请状态不允许的情况 拒绝修改
  3826. if infor.ApplicationStatus != 1 {
  3827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3828. return
  3829. }
  3830. }
  3831. }
  3832. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3833. byterequest, _ := json.Marshal(advice)
  3834. doctorAdviceLog := models.XtDoctorAdviceLog{
  3835. UserOrgId: advice.UserOrgId,
  3836. PatientId: advice.PatientId,
  3837. AdminUserId: adminUserInfo.AdminUser.Id,
  3838. Module: 4,
  3839. ErrLog: string(byterequest),
  3840. Status: 1,
  3841. Ctime: time.Now().Unix(),
  3842. Mtime: 0,
  3843. Source: "电脑端批量删除医嘱",
  3844. RecordDate: advice.RecordDate,
  3845. }
  3846. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3847. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3848. redis := service.RedisClient()
  3849. redis.Set(key, "", time.Second)
  3850. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3851. redis.Set(keyOne, "", time.Second)
  3852. defer redis.Close()
  3853. if err != nil {
  3854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3855. return
  3856. }
  3857. c.ServeSuccessJSON(map[string]interface{}{
  3858. "msg": "ok",
  3859. })
  3860. return
  3861. }
  3862. // GetDoctorAdvices 医嘱列表
  3863. func (c *PatientApiController) GetDoctorAdvices() {
  3864. id, _ := c.GetInt64("id", 0)
  3865. adviceType, _ := c.GetInt64("advice_type", 0)
  3866. stopType, _ := c.GetInt64("stop_state", 0)
  3867. startTime := c.GetString("start_time", "")
  3868. endTime := c.GetString("end_time", "")
  3869. keywords := c.GetString("keywords", "")
  3870. page, _ := c.GetInt64("page")
  3871. limit, _ := c.GetInt64("limit")
  3872. adminUserInfo := c.GetAdminUserInfo()
  3873. delivery_way_one := c.GetString("delivery_way_one", "")
  3874. operatorIDs := make([]int64, 0)
  3875. timeLayout := "2006-01-02"
  3876. loc, _ := time.LoadLocation("Local")
  3877. var theStartTIme int64
  3878. if len(startTime) > 0 {
  3879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3880. if err != nil {
  3881. utils.ErrorLog(err.Error())
  3882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3883. return
  3884. }
  3885. theStartTIme = theTime.Unix()
  3886. }
  3887. var theEndtTIme int64
  3888. if len(endTime) > 0 {
  3889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3890. if err != nil {
  3891. utils.ErrorLog(err.Error())
  3892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3893. return
  3894. }
  3895. theEndtTIme = theTime.Unix()
  3896. }
  3897. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3898. if hisconfig.IsOpen == 1 {
  3899. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
  3900. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
  3901. if len(advices) > 0 {
  3902. for _, item := range advices {
  3903. if item.AdviceDoctor > 0 {
  3904. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3905. }
  3906. if item.ExecutionStaff > 0 {
  3907. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3908. }
  3909. if item.Checker > 0 {
  3910. operatorIDs = append(operatorIDs, item.Checker)
  3911. }
  3912. if item.StopDoctor > 0 {
  3913. operatorIDs = append(operatorIDs, item.StopDoctor)
  3914. }
  3915. }
  3916. }
  3917. //相关操作对应的操作人
  3918. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3919. //获取长期医嘱
  3920. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3921. c.ServeSuccessJSON(map[string]interface{}{
  3922. "advices": advices,
  3923. "operators": operators,
  3924. "total": total,
  3925. "advicetwo": advicestwo,
  3926. "longAdvice": longAdvice,
  3927. "is_open": hisconfig.IsOpen,
  3928. })
  3929. return
  3930. } else {
  3931. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
  3932. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
  3933. if len(advices) > 0 {
  3934. for _, item := range advices {
  3935. if item.AdviceDoctor > 0 {
  3936. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3937. }
  3938. if item.ExecutionStaff > 0 {
  3939. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3940. }
  3941. if item.Checker > 0 {
  3942. operatorIDs = append(operatorIDs, item.Checker)
  3943. }
  3944. if item.StopDoctor > 0 {
  3945. operatorIDs = append(operatorIDs, item.StopDoctor)
  3946. }
  3947. }
  3948. }
  3949. //相关操作对应的操作人
  3950. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3951. c.ServeSuccessJSON(map[string]interface{}{
  3952. "advices": advices,
  3953. "operators": operators,
  3954. "total": total,
  3955. "advicetwo": advicestwo,
  3956. "is_open": hisconfig.IsOpen,
  3957. })
  3958. return
  3959. }
  3960. }
  3961. func (c *PatientApiController) GetPatientSchedules() {
  3962. id, _ := c.GetInt64("id", 0)
  3963. if id <= 0 {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. adminUserInfo := c.GetAdminUserInfo()
  3968. todayTime := time.Now().Format("2006-01-02")
  3969. timeLayout := "2006-01-02 15:04:05"
  3970. loc, _ := time.LoadLocation("Local")
  3971. var theStartTime int64
  3972. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3973. theStartTime = theTime.Unix()
  3974. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3975. if len(schedules) > 0 {
  3976. for index, item := range schedules {
  3977. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3978. schedules[index].Week = int64(week)
  3979. }
  3980. }
  3981. c.ServeSuccessJSON(map[string]interface{}{
  3982. "schedules": schedules,
  3983. })
  3984. return
  3985. }
  3986. func (c *PatientApiController) GetPatientDialysisRecords() {
  3987. patientID, _ := c.GetInt64("patient_id", 0)
  3988. page, _ := c.GetInt64("page", 0)
  3989. limit, _ := c.GetInt64("limit", 0)
  3990. startTime := c.GetString("start_time", "")
  3991. endTime := c.GetString("end_time", "")
  3992. mode_id, _ := c.GetInt64("mode_id", 0)
  3993. if page <= 0 {
  3994. page = 1
  3995. }
  3996. if limit <= 0 {
  3997. limit = 10
  3998. }
  3999. if patientID <= 0 {
  4000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4001. return
  4002. }
  4003. timeLayout := "2006-01-02"
  4004. loc, _ := time.LoadLocation("Local")
  4005. var theStartTIme int64
  4006. if len(startTime) > 0 {
  4007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4008. if err != nil {
  4009. theStartTIme = 0
  4010. }
  4011. theStartTIme = theTime.Unix()
  4012. }
  4013. var theEndtTIme int64
  4014. if len(endTime) > 0 {
  4015. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4016. if err != nil {
  4017. theEndtTIme = 0
  4018. }
  4019. theEndtTIme = theTime.Unix()
  4020. }
  4021. adminInfo := c.GetAdminUserInfo()
  4022. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4023. fmt.Println("长度", len(records))
  4024. if len(records) == 0 {
  4025. list, _ := service.GetAllDialysisOrder(patientID, theStartTIme, theEndtTIme)
  4026. for _, item := range list {
  4027. schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
  4028. prescribeOne, _ := service.GetDialysisPrescribeOne(adminInfo.CurrentOrgId, item.PatientId, item.DialysisDate)
  4029. service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID, prescribeOne.ModeId)
  4030. }
  4031. }
  4032. c.ServeSuccessJSON(map[string]interface{}{
  4033. "total": total,
  4034. "records": records,
  4035. })
  4036. return
  4037. }
  4038. func (c *PatientApiController) ProEducation() {
  4039. patientID, _ := c.GetInt64("patient_id", 0)
  4040. page, _ := c.GetInt64("page", 0)
  4041. limit, _ := c.GetInt64("limit", 0)
  4042. startTime := c.GetString("start_time", "")
  4043. endTime := c.GetString("end_time", "")
  4044. if page <= 0 {
  4045. page = 1
  4046. }
  4047. if limit <= 0 {
  4048. limit = 10
  4049. }
  4050. if patientID <= 0 {
  4051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4052. return
  4053. }
  4054. timeLayout := "2006-01-02"
  4055. loc, _ := time.LoadLocation("Local")
  4056. var theStartTIme int64
  4057. if len(startTime) > 0 {
  4058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4059. if err != nil {
  4060. theStartTIme = 0
  4061. }
  4062. theStartTIme = theTime.Unix()
  4063. }
  4064. var theEndtTIme int64
  4065. if len(endTime) > 0 {
  4066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4067. if err != nil {
  4068. theEndtTIme = 0
  4069. }
  4070. theEndtTIme = theTime.Unix()
  4071. }
  4072. adminInfo := c.GetAdminUserInfo()
  4073. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  4074. c.ServeSuccessJSON(map[string]interface{}{
  4075. "total": total,
  4076. "edus": edus,
  4077. })
  4078. return
  4079. }
  4080. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4081. dataBody := make(map[string]interface{}, 0)
  4082. err := json.Unmarshal(data, &dataBody)
  4083. if err != nil {
  4084. utils.ErrorLog(err.Error())
  4085. code = enums.ErrorCodeParamWrong
  4086. return
  4087. }
  4088. timeLayout := "2006-01-02"
  4089. loc, _ := time.LoadLocation("Local")
  4090. isChild := false
  4091. if action == "create" {
  4092. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4093. utils.ErrorLog("advice_type")
  4094. code = enums.ErrorCodeParamWrong
  4095. return
  4096. }
  4097. adviceType := int64(dataBody["advice_type"].(float64))
  4098. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  4099. utils.ErrorLog("advice_type != 1&&2")
  4100. code = enums.ErrorCodeParamWrong
  4101. return
  4102. }
  4103. advice.AdviceType = adviceType
  4104. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4105. utils.ErrorLog("advice_date")
  4106. code = enums.ErrorCodeParamWrong
  4107. return
  4108. }
  4109. adviceDate, _ := dataBody["advice_date"].(string)
  4110. if len(adviceDate) == 0 {
  4111. utils.ErrorLog("len(adviceDate) == 0")
  4112. code = enums.ErrorCodeParamWrong
  4113. return
  4114. }
  4115. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4116. if err != nil {
  4117. utils.ErrorLog(err.Error())
  4118. code = enums.ErrorCodeParamWrong
  4119. return
  4120. }
  4121. advice.AdviceDate = theTime.Unix()
  4122. advice.RecordDate = theTime.Unix()
  4123. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4124. parentId := int64(dataBody["parent_id"].(float64))
  4125. advice.ParentId = parentId
  4126. if parentId > 0 {
  4127. isChild = true
  4128. }
  4129. }
  4130. }
  4131. if !isChild {
  4132. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4133. utils.ErrorLog("start_time")
  4134. code = enums.ErrorCodeParamWrong
  4135. return
  4136. }
  4137. startTime, _ := dataBody["start_time"].(string)
  4138. if len(startTime) == 0 {
  4139. utils.ErrorLog("len(start_time) == 0")
  4140. code = enums.ErrorCodeParamWrong
  4141. return
  4142. }
  4143. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  4144. if err != nil {
  4145. utils.ErrorLog(err.Error())
  4146. code = enums.ErrorCodeParamWrong
  4147. return
  4148. }
  4149. advice.StartTime = theTime.Unix()
  4150. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  4151. // utils.ErrorLog("advice_doctor")
  4152. // code = enums.ErrorCodeParamWrong
  4153. // return
  4154. // }
  4155. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  4156. // if adviceDoctor <= 0 {
  4157. // utils.ErrorLog("advice_doctor <=0")
  4158. // code = enums.ErrorCodeParamWrong
  4159. // return
  4160. // }
  4161. // advice.AdviceDoctor = adviceDoctor
  4162. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4163. deliveryWay, _ := dataBody["delivery_way"].(string)
  4164. advice.DeliveryWay = deliveryWay
  4165. }
  4166. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4167. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4168. advice.ExecutionFrequency = executionFrequency
  4169. }
  4170. if advice.AdviceType == 1 && advice.ParentId == 0 {
  4171. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  4172. frequency_type := int64(dataBody["frequency_type"].(float64))
  4173. advice.FrequencyType = frequency_type
  4174. }
  4175. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  4176. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  4177. advice.DayCount = day_count
  4178. }
  4179. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  4180. week_day, _ := dataBody["week_days"].(string)
  4181. advice.WeekDay = week_day
  4182. }
  4183. }
  4184. }
  4185. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4186. utils.ErrorLog("advice_name")
  4187. code = enums.ErrorCodeParamWrong
  4188. return
  4189. }
  4190. adviceName, _ := dataBody["advice_name"].(string)
  4191. if len(adviceName) == 0 {
  4192. utils.ErrorLog("len(advice_name) == 0")
  4193. code = enums.ErrorCodeParamWrong
  4194. return
  4195. }
  4196. advice.AdviceName = adviceName
  4197. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4198. adviceDsc, _ := dataBody["advice_desc"].(string)
  4199. advice.AdviceDesc = adviceDsc
  4200. }
  4201. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  4202. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  4203. advice.DialysisOrderId = int64(dialysisOrderId)
  4204. }
  4205. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4206. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4207. advice.SingleDose = singleDose
  4208. }
  4209. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  4210. singleDose := dataBody["single_dose"].(float64)
  4211. advice.SingleDose = singleDose
  4212. }
  4213. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4214. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4215. advice.SingleDoseUnit = singleDoseUnit
  4216. }
  4217. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  4218. tmp := dataBody["single_dose_unit"].(float64)
  4219. singleDoseUnit := service.TypeConversion(tmp)
  4220. advice.SingleDoseUnit = singleDoseUnit
  4221. }
  4222. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4223. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4224. advice.DrugSpec = drugSpec
  4225. }
  4226. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4227. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4228. advice.DrugSpecUnit = drugSpecUnit
  4229. }
  4230. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4231. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4232. advice.PrescribingNumber = prescribingNumber
  4233. }
  4234. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  4235. prescribingNumber := dataBody["prescribing_number"].(float64)
  4236. advice.PrescribingNumber = prescribingNumber
  4237. }
  4238. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4239. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4240. advice.PrescribingNumberUnit = prescribingNumberUnit
  4241. }
  4242. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4243. remark, _ := dataBody["remark"].(string)
  4244. advice.Remark = remark
  4245. }
  4246. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  4247. drug_id, _ := dataBody["drug_id"].(string)
  4248. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  4249. advice.DrugId = tmpDrugId
  4250. }
  4251. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4252. drug_id, _ := dataBody["drug_id"].(float64)
  4253. advice.DrugId = int64(drug_id)
  4254. }
  4255. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4256. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  4257. advice.DrugNameId = int64(drug_name_id)
  4258. }
  4259. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4260. way, _ := dataBody["way"].(float64)
  4261. advice.Way = int64(way)
  4262. }
  4263. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  4264. push_start_time, _ := dataBody["push_start_time"].(string)
  4265. var startTime int64
  4266. if len(push_start_time) > 0 {
  4267. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  4268. startTime = theTime.Unix()
  4269. }
  4270. advice.PushStartTime = startTime
  4271. }
  4272. return
  4273. }
  4274. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  4275. dataBody := make(map[string]interface{}, 0)
  4276. err := json.Unmarshal(data, &dataBody)
  4277. utils.InfoLog(string(data))
  4278. if err != nil {
  4279. utils.ErrorLog(err.Error())
  4280. code = enums.ErrorCodeParamWrong
  4281. return
  4282. }
  4283. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4284. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4285. solution.DialysisDuration = dialysisDuration
  4286. }
  4287. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4288. replacementWay := int64(dataBody["replacement_way"].(float64))
  4289. solution.ReplacementWay = replacementWay
  4290. }
  4291. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4292. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4293. solution.BloodFlowVolume = bloodFlowVolume
  4294. }
  4295. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4296. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4297. solution.HemodialysisMachine = hemodialysisMachine
  4298. }
  4299. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  4300. bloodFilter := int64(dataBody["blood_filter"].(float64))
  4301. solution.BloodFilter = bloodFilter
  4302. }
  4303. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4304. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4305. solution.PerfusionApparatus = perfusionApparatus
  4306. }
  4307. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4308. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4309. solution.DialysateFlow = dialysateFlow
  4310. }
  4311. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4312. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4313. solution.Kalium = kalium
  4314. }
  4315. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4316. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4317. solution.Sodium = sodium
  4318. }
  4319. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4320. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4321. solution.Calcium = calcium
  4322. }
  4323. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4324. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4325. solution.Bicarbonate = bicarbonate
  4326. }
  4327. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4328. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4329. solution.Anticoagulant = anticoagulant
  4330. }
  4331. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4332. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4333. solution.AnticoagulantShouji = anticoagulantShouji
  4334. }
  4335. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4336. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4337. solution.AnticoagulantWeichi = anticoagulantWeichi
  4338. }
  4339. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4340. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4341. solution.AnticoagulantZongliang = anticoagulantZongliang
  4342. }
  4343. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4344. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4345. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4346. }
  4347. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4348. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4349. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4350. }
  4351. return
  4352. }
  4353. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4354. dataBody := make(map[string]interface{}, 0)
  4355. err := json.Unmarshal(data, &dataBody)
  4356. utils.InfoLog(string(data))
  4357. if err != nil {
  4358. utils.ErrorLog(err.Error())
  4359. code = enums.ErrorCodeParamWrong
  4360. return
  4361. }
  4362. if method == "create" {
  4363. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  4364. utils.ErrorLog("mode")
  4365. code = enums.ErrorCodeParamWrong
  4366. return
  4367. }
  4368. mode := int64(dataBody["mode"].(float64))
  4369. if mode <= 0 {
  4370. utils.ErrorLog("mode <= 0")
  4371. code = enums.ErrorCodeParamWrong
  4372. return
  4373. }
  4374. solution.ModeId = mode
  4375. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  4376. utils.ErrorLog("mode_name")
  4377. code = enums.ErrorCodeParamWrong
  4378. return
  4379. }
  4380. modeName, _ := dataBody["mode_name"].(string)
  4381. if len(modeName) == 0 {
  4382. utils.ErrorLog("len(mode_name) == 0")
  4383. code = enums.ErrorCodeParamWrong
  4384. return
  4385. }
  4386. solution.ModeName = modeName
  4387. solution.Name = modeName
  4388. }
  4389. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4390. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4391. solution.DialysisDuration = dialysisDuration
  4392. }
  4393. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4394. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4395. solution.TargetUltrafiltration = targetUltrafiltration
  4396. }
  4397. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4398. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  4399. solution.DialysateFormulation = dialysateFormulation
  4400. }
  4401. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4402. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  4403. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4404. }
  4405. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4406. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  4407. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4408. }
  4409. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4410. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4411. solution.HemodialysisMachine = hemodialysisMachine
  4412. }
  4413. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  4414. dialyzer := int64(dataBody["dialyzer"].(float64))
  4415. solution.Dialyzer = dialyzer
  4416. }
  4417. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4418. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4419. solution.PerfusionApparatus = perfusionApparatus
  4420. }
  4421. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4422. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4423. solution.BloodFlowVolume = bloodFlowVolume
  4424. }
  4425. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  4426. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  4427. solution.Dewater = dewater
  4428. }
  4429. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  4430. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  4431. solution.DisplaceLiqui = displaceLiqui
  4432. }
  4433. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4434. replacementWay := int64(dataBody["replacement_way"].(float64))
  4435. solution.ReplacementWay = replacementWay
  4436. }
  4437. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4438. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4439. solution.Anticoagulant = anticoagulant
  4440. }
  4441. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4442. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4443. solution.AnticoagulantShouji = anticoagulantShouji
  4444. }
  4445. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4446. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4447. solution.AnticoagulantWeichi = anticoagulantWeichi
  4448. }
  4449. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4450. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4451. solution.AnticoagulantZongliang = anticoagulantZongliang
  4452. }
  4453. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4454. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4455. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4456. }
  4457. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4458. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4459. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4460. }
  4461. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4462. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4463. solution.Kalium = kalium
  4464. }
  4465. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4466. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4467. solution.Sodium = sodium
  4468. }
  4469. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4470. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4471. solution.Calcium = calcium
  4472. }
  4473. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4474. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4475. solution.Bicarbonate = bicarbonate
  4476. }
  4477. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4478. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4479. solution.Glucose = glucose
  4480. }
  4481. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4482. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4483. // solution.DryWeight = dryWeight
  4484. // }
  4485. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4486. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4487. solution.DialysateFlow = dialysateFlow
  4488. }
  4489. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4490. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4491. solution.DialysateTemperature = dialysateTemperature
  4492. }
  4493. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4494. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4495. solution.Conductivity = conductivity
  4496. }
  4497. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  4498. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  4499. solution.ReplacementTotal = replacementTotal
  4500. }
  4501. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  4502. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  4503. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  4504. }
  4505. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  4506. body_fluid := int64(dataBody["body_fluid"].(float64))
  4507. solution.BodyFluid = body_fluid
  4508. }
  4509. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  4510. body_fluid_other := dataBody["body_fluid_other"].(string)
  4511. solution.BodyFluidOther = body_fluid_other
  4512. }
  4513. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  4514. special_medicine := int64(dataBody["special_medicine"].(float64))
  4515. solution.SpecialMedicine = special_medicine
  4516. }
  4517. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  4518. special_medicine_other := dataBody["special_medicine_other"].(string)
  4519. solution.SpecialMedicineOther = special_medicine_other
  4520. }
  4521. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  4522. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  4523. solution.DisplaceLiquiPart = displace_liqui_part
  4524. }
  4525. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  4526. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  4527. solution.DisplaceLiquiValue = displace_liqui_value
  4528. }
  4529. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  4530. blood_access := int64(dataBody["blood_access"].(float64))
  4531. solution.BloodAccess = blood_access
  4532. }
  4533. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  4534. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  4535. solution.Ultrafiltration = ultrafiltration
  4536. }
  4537. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  4538. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  4539. solution.TargetKtv = target_ktv
  4540. }
  4541. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4542. remark := dataBody["remark"].(string)
  4543. solution.Remark = remark
  4544. }
  4545. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  4546. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  4547. solution.HemodialysisPipelines = hemodialysis_pipelines
  4548. }
  4549. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  4550. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  4551. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  4552. }
  4553. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4554. puncture_needle := dataBody["puncture_needle"].(string)
  4555. solution.PunctureNeedle = puncture_needle
  4556. }
  4557. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  4558. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  4559. solution.PunctureNeedleCount = puncture_needle_count
  4560. }
  4561. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  4562. epo := dataBody["epo"].(string)
  4563. solution.Epo = epo
  4564. }
  4565. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  4566. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  4567. solution.EpoCount = epo_count
  4568. }
  4569. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  4570. created_time := int64(dataBody["created_time"].(float64))
  4571. solution.CreatedTime = created_time
  4572. }
  4573. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  4574. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  4575. solution.DialysisDialyszers = dialysisDialyszers
  4576. }
  4577. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  4578. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  4579. solution.DialysisIrrigation = dialysisIrrigation
  4580. }
  4581. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  4582. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  4583. solution.DialysisStrainer = dialysis_strainer
  4584. }
  4585. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  4586. plasmaSeparator := dataBody["plasma_separator"].(string)
  4587. solution.PlasmaSeparator = plasmaSeparator
  4588. }
  4589. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  4590. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  4591. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  4592. }
  4593. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  4594. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  4595. solution.OxygenUptake = oxygen_uptake
  4596. }
  4597. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  4598. oxygen_flow := dataBody["oxygen_flow"].(string)
  4599. solution.OxygenFlow = oxygen_flow
  4600. }
  4601. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  4602. oxygen_time := dataBody["oxygen_time"].(string)
  4603. solution.OxygenTime = oxygen_time
  4604. }
  4605. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  4606. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  4607. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  4608. }
  4609. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  4610. amylaceum := dataBody["amylaceum"].(string)
  4611. solution.Amylaceum = amylaceum
  4612. }
  4613. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  4614. chaptalization := dataBody["chaptalization"].(string)
  4615. solution.Chaptalization = chaptalization
  4616. }
  4617. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4618. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4619. solution.BloodAccessPartId = blood_access_part_id
  4620. }
  4621. return
  4622. }
  4623. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4624. dataBody := make(map[string]interface{}, 0)
  4625. err := json.Unmarshal(data, &dataBody)
  4626. utils.InfoLog(string(data))
  4627. if err != nil {
  4628. utils.ErrorLog(err.Error())
  4629. code = enums.ErrorCodeParamWrong
  4630. return
  4631. }
  4632. if method == "create" {
  4633. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  4634. utils.ErrorLog("parent_id")
  4635. code = enums.ErrorCodeParamWrong
  4636. return
  4637. }
  4638. parentID := int64(dataBody["parent_id"].(float64))
  4639. if parentID <= 0 {
  4640. utils.ErrorLog("parentID <= 0")
  4641. code = enums.ErrorCodeParamWrong
  4642. return
  4643. }
  4644. solution.ParentId = parentID
  4645. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  4646. utils.ErrorLog("sub_name")
  4647. code = enums.ErrorCodeParamWrong
  4648. return
  4649. }
  4650. subName, _ := dataBody["sub_name"].(string)
  4651. if len(subName) == 0 {
  4652. utils.ErrorLog("len(sub_name) == 0")
  4653. code = enums.ErrorCodeParamWrong
  4654. return
  4655. }
  4656. solution.SubName = subName
  4657. }
  4658. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4659. utils.ErrorLog("initiate_mode")
  4660. code = enums.ErrorCodeParamWrong
  4661. return
  4662. }
  4663. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4664. if initiateMode != 1 && initiateMode != 2 {
  4665. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4666. code = enums.ErrorCodeParamWrong
  4667. return
  4668. }
  4669. solution.InitiateMode = initiateMode
  4670. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4671. utils.ErrorLog("doctor")
  4672. code = enums.ErrorCodeParamWrong
  4673. return
  4674. }
  4675. doctor := int64(dataBody["doctor"].(float64))
  4676. if doctor <= 0 {
  4677. utils.ErrorLog("doctor <= 0")
  4678. code = enums.ErrorCodeParamWrong
  4679. return
  4680. }
  4681. solution.Doctor = doctor
  4682. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4683. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4684. solution.BloodAccessPartId = blood_access_part_id
  4685. }
  4686. return
  4687. }
  4688. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4689. patientBody := make(map[string]interface{}, 0)
  4690. err := json.Unmarshal(data, &patientBody)
  4691. if err != nil {
  4692. utils.ErrorLog(err.Error())
  4693. code = enums.ErrorCodeParamWrong
  4694. return
  4695. }
  4696. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4697. formItem, _ := patientBody["formItem"].([]interface{})
  4698. if len(formItem) > 0 {
  4699. for _, item := range formItem {
  4700. items := item.(map[string]interface{})
  4701. project_name, _ := items["project_name"].(string)
  4702. fmt.Println(project_name)
  4703. range_type := int64(items["range_type"].(float64))
  4704. fmt.Println(range_type)
  4705. project_id := int64(items["project_id"].(float64))
  4706. fmt.Println(project_id)
  4707. item_id := int64(items["item_id"].(float64))
  4708. fmt.Println(item_id)
  4709. item, _ := items["item"].(string)
  4710. fmt.Println(items["item"].(string))
  4711. item_name, _ := items["item_name"].(string)
  4712. fmt.Println(item_name)
  4713. value, _ := items["value"].(string)
  4714. fmt.Println(items["value"].(string))
  4715. var form models.FormItem
  4716. form.ProjectName = project_name
  4717. form.RangeType = range_type
  4718. form.ProjectId = project_id
  4719. form.ItemId = item_id
  4720. form.Item = item
  4721. form.ItemName = item_name
  4722. form.Value = value
  4723. formItems = append(formItems, &form)
  4724. }
  4725. }
  4726. }
  4727. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4728. utils.ErrorLog("avatar")
  4729. code = enums.ErrorCodeParamWrong
  4730. return
  4731. }
  4732. avatar, _ := patientBody["avatar"].(string)
  4733. if len(avatar) == 0 {
  4734. utils.ErrorLog("len(avatar) == 0")
  4735. code = enums.ErrorCodeParamWrong
  4736. return
  4737. }
  4738. patient.Avatar = avatar
  4739. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4740. utils.ErrorLog("name")
  4741. code = enums.ErrorCodeParamWrong
  4742. return
  4743. }
  4744. name, _ := patientBody["name"].(string)
  4745. if len(name) == 0 {
  4746. utils.ErrorLog("len(name) == 0")
  4747. code = enums.ErrorCodeParamWrong
  4748. return
  4749. }
  4750. patient.Name = name
  4751. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4752. alias := patientBody["alias"].(string)
  4753. patient.Alias = alias
  4754. }
  4755. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4756. nation := patientBody["nation"].(string)
  4757. patient.Nation = nation
  4758. }
  4759. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4760. native_place := patientBody["native_place"].(string)
  4761. patient.NativePlace = native_place
  4762. }
  4763. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4764. utils.ErrorLog("idCardNo")
  4765. code = enums.ErrorCodeParamWrong
  4766. return
  4767. }
  4768. idCardNo, _ := patientBody["idCardNo"].(string)
  4769. if len(idCardNo) == 0 {
  4770. utils.ErrorLog("len(idCardNo) == 0")
  4771. code = enums.ErrorCodeParamWrong
  4772. return
  4773. }
  4774. patient.IdCardNo = idCardNo
  4775. patient.PatientType = 1
  4776. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4777. utils.ErrorLog("dialysisNo")
  4778. code = enums.ErrorCodeParamWrong
  4779. return
  4780. }
  4781. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4782. if len(dialysisNo) == 0 {
  4783. utils.ErrorLog("len(dialysisNo) == 0")
  4784. code = enums.ErrorCodeParamWrong
  4785. return
  4786. }
  4787. patient.DialysisNo = dialysisNo
  4788. // }
  4789. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4790. utils.ErrorLog("lapseto")
  4791. code = enums.ErrorCodeParamWrong
  4792. return
  4793. }
  4794. lapseto := int64(patientBody["lapseto"].(float64))
  4795. if lapseto <= 0 {
  4796. utils.ErrorLog("lapseto == 0")
  4797. code = enums.ErrorCodeParamWrong
  4798. return
  4799. }
  4800. patient.Lapseto = lapseto
  4801. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4802. utils.ErrorLog("gender")
  4803. code = enums.ErrorCodeParamWrong
  4804. return
  4805. }
  4806. gender := int64(patientBody["gender"].(float64))
  4807. if gender <= 0 {
  4808. utils.ErrorLog("gender <= 0")
  4809. code = enums.ErrorCodeParamWrong
  4810. return
  4811. }
  4812. patient.Gender = gender
  4813. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4814. response_result := patientBody["response_result"].(string)
  4815. patient.ResponseResult = response_result
  4816. }
  4817. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4818. utils.ErrorLog("age")
  4819. code = enums.ErrorCodeParamWrong
  4820. return
  4821. }
  4822. age := int64(patientBody["age"].(float64))
  4823. patient.Age = age
  4824. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4825. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4826. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4827. patient.UserSysBeforeCount = count
  4828. }
  4829. timeLayout := "2006-01-02"
  4830. loc, _ := time.LoadLocation("Local")
  4831. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4832. utils.ErrorLog("birth")
  4833. code = enums.ErrorCodeParamWrong
  4834. return
  4835. }
  4836. birth, _ := patientBody["birth"].(string)
  4837. if len(birth) == 0 {
  4838. utils.ErrorLog("len(birth) == 0")
  4839. code = enums.ErrorCodeParamWrong
  4840. return
  4841. }
  4842. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4843. if err != nil {
  4844. utils.ErrorLog("birthTime")
  4845. code = enums.ErrorCodeParamWrong
  4846. return
  4847. }
  4848. patient.Birthday = birthTime.Unix()
  4849. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4850. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4851. patient.Height = height
  4852. }
  4853. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4854. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4855. patient.MaritalStatus = maritalStatus
  4856. }
  4857. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4858. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4859. patient.Children = children
  4860. }
  4861. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4862. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4863. patient.AdmissionNumber = admissionNumber
  4864. }
  4865. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4866. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4867. patient.ReimbursementWayId = reimbursementWayID
  4868. }
  4869. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4870. healthCareNo := patientBody["healthCareNo"].(string)
  4871. patient.HealthCareNo = healthCareNo
  4872. }
  4873. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4874. utils.ErrorLog("phone")
  4875. code = enums.ErrorCodeParamWrong
  4876. return
  4877. }
  4878. phone := patientBody["phone"].(string)
  4879. if len(phone) == 0 {
  4880. utils.ErrorLog("len(phone) == 0")
  4881. code = enums.ErrorCodeParamWrong
  4882. return
  4883. }
  4884. if !utils.CheckMobile(phone) {
  4885. utils.ErrorLog("!phone")
  4886. code = enums.ErrorCodeMobileFormat
  4887. return
  4888. }
  4889. patient.Phone = phone
  4890. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4891. homeTelephone := patientBody["homeTelephone"].(string)
  4892. patient.HomeTelephone = homeTelephone
  4893. }
  4894. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4895. relativePhone := patientBody["relative_phone"].(string)
  4896. patient.RelativePhone = relativePhone
  4897. }
  4898. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4899. relativeRelations := patientBody["relative_relations"].(string)
  4900. patient.RelativeRelations = relativeRelations
  4901. }
  4902. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4903. homeAddress := patientBody["homeAddress"].(string)
  4904. patient.HomeAddress = homeAddress
  4905. }
  4906. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4907. work := patientBody["work"].(string)
  4908. patient.WorkUnit = work
  4909. }
  4910. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4911. unitAddress := patientBody["unit_address"].(string)
  4912. patient.UnitAddress = unitAddress
  4913. }
  4914. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4915. profession := int64(patientBody["profession"].(float64))
  4916. patient.Profession = profession
  4917. }
  4918. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4919. education := int64(patientBody["education"].(float64))
  4920. patient.EducationLevel = education
  4921. }
  4922. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4923. utils.ErrorLog("source")
  4924. code = enums.ErrorCodeParamWrong
  4925. return
  4926. }
  4927. source := int64(patientBody["source"].(float64))
  4928. if source <= 0 {
  4929. utils.ErrorLog("source <= 0")
  4930. code = enums.ErrorCodeParamWrong
  4931. return
  4932. }
  4933. patient.Source = source
  4934. zb_patient_id := patientBody["zb_patient_id"].(string)
  4935. patient.ZbPatientId = zb_patient_id
  4936. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4937. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4938. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4939. }
  4940. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4941. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4942. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4943. if err == nil {
  4944. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4945. }
  4946. }
  4947. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4948. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4949. patient.FirstDialysisHospital = firstDialysisHospital
  4950. }
  4951. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4952. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4953. if len(thePredialysisCondition) > 0 {
  4954. conditions := make([]string, 0)
  4955. for _, item := range thePredialysisCondition {
  4956. if reflect.TypeOf(item).String() != "string" {
  4957. continue
  4958. }
  4959. condition := item.(string)
  4960. if len(condition) > 0 {
  4961. conditions = append(conditions, condition)
  4962. }
  4963. }
  4964. patient.PredialysisCondition = strings.Join(conditions, ",")
  4965. }
  4966. }
  4967. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4968. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4969. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4970. }
  4971. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4972. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4973. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4974. }
  4975. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4976. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4977. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4978. if err == nil {
  4979. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4980. }
  4981. }
  4982. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4983. partition := int64(patientBody["partition"].(float64))
  4984. patient.PartitionId = partition
  4985. }
  4986. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4987. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4988. patient.BedId = bed
  4989. }
  4990. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4991. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4992. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4993. if err == nil {
  4994. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4995. }
  4996. }
  4997. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4998. blood := int64(patientBody["blood"].(float64))
  4999. patient.BloodType = blood
  5000. }
  5001. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  5002. rh := int64(patientBody["rh"].(float64))
  5003. patient.Rh = rh
  5004. }
  5005. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  5006. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  5007. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  5008. if err == nil {
  5009. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  5010. }
  5011. }
  5012. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  5013. receivingDate := patientBody["receivingDate"].(string)
  5014. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  5015. if err == nil {
  5016. patient.ReceivingDate = receivingDateTime.Unix()
  5017. }
  5018. }
  5019. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  5020. induction := int64(patientBody["induction"].(float64))
  5021. patient.InductionPeriod = induction
  5022. }
  5023. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  5024. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  5025. patient.InitialDialysis = initial
  5026. }
  5027. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  5028. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  5029. patient.TotalDialysis = dialysisTotal
  5030. }
  5031. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  5032. thisContagions, _ := patientBody["contagions"].([]interface{})
  5033. if len(thisContagions) > 0 {
  5034. for _, item := range thisContagions {
  5035. if reflect.TypeOf(item).String() != "float64" {
  5036. continue
  5037. }
  5038. contagion := int64(item.(float64))
  5039. if contagion > 0 {
  5040. contagions = append(contagions, contagion)
  5041. }
  5042. }
  5043. }
  5044. }
  5045. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  5046. doctor := int64(patientBody["doctor"].(float64))
  5047. patient.AttendingDoctorId = doctor
  5048. }
  5049. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  5050. nurse := int64(patientBody["nurse"].(float64))
  5051. patient.HeadNurseId = nurse
  5052. }
  5053. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  5054. assessment := patientBody["assessment"].(string)
  5055. patient.Evaluate = assessment
  5056. }
  5057. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  5058. thisDiseases, _ := patientBody["diseases"].([]interface{})
  5059. if len(thisDiseases) > 0 {
  5060. for _, item := range thisDiseases {
  5061. if reflect.TypeOf(item).String() != "float64" {
  5062. continue
  5063. }
  5064. disease := int64(item.(float64))
  5065. if disease > 0 {
  5066. diseases = append(diseases, disease)
  5067. }
  5068. }
  5069. }
  5070. }
  5071. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  5072. diagnose := patientBody["diagnose"].(string)
  5073. patient.Diagnose = diagnose
  5074. }
  5075. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  5076. remark := patientBody["remark"].(string)
  5077. patient.Remark = remark
  5078. }
  5079. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  5080. sch_remark := patientBody["sch_remark"].(string)
  5081. patient.SchRemark = sch_remark
  5082. }
  5083. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  5084. patient_complains := patientBody["patient_complains"].(string)
  5085. patient.PatientComplains = patient_complains
  5086. }
  5087. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  5088. present_history := patientBody["present_history"].(string)
  5089. patient.PresentHistory = present_history
  5090. }
  5091. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  5092. past_history := patientBody["past_history"].(string)
  5093. patient.PastHistory = past_history
  5094. }
  5095. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  5096. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  5097. patient.Temperature = temperature
  5098. }
  5099. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  5100. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  5101. patient.Pulse = pulse
  5102. }
  5103. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  5104. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  5105. patient.Respiratory = respiratory
  5106. }
  5107. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  5108. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  5109. patient.SBP = sbp
  5110. }
  5111. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  5112. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  5113. patient.DBP = dbp
  5114. }
  5115. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  5116. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  5117. patient.DialysisAge = dialysis_age
  5118. }
  5119. fmt.Println(patient.DialysisAge)
  5120. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  5121. first_treatment_date := patientBody["first_treatment_date"].(string)
  5122. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5123. if err == nil {
  5124. patient.FirstTreatmentDate = first_treatment_time.Unix()
  5125. }
  5126. }
  5127. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  5128. expense_kind := int64(patientBody["expense_kind"].(float64))
  5129. patient.ExpenseKind = expense_kind
  5130. }
  5131. fmt.Println(patient.ExpenseKind)
  5132. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  5133. tell_phone := patientBody["tell_phone"].(string)
  5134. patient.TellPhone = tell_phone
  5135. }
  5136. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  5137. contact_name := patientBody["contact_name"].(string)
  5138. patient.ContactName = contact_name
  5139. }
  5140. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  5141. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  5142. patient.TrobleShoot = troble_shoot
  5143. }
  5144. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  5145. treatment_plan := patientBody["treatment_plan"].(string)
  5146. patient.TreatmentPlan = treatment_plan
  5147. }
  5148. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  5149. doctor := int64(patientBody["doctor"].(float64))
  5150. patient.Doctor = doctor
  5151. }
  5152. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  5153. record_number := patientBody["record_number"].(string)
  5154. patient.RecordNumber = record_number
  5155. }
  5156. patient_source := int64(patientBody["patient_source"].(float64))
  5157. if patient_source <= 0 {
  5158. utils.ErrorLog("patient_source <= 0")
  5159. code = enums.ErrorCodeParamWrong
  5160. return
  5161. }
  5162. patient.PatientSource = patient_source
  5163. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  5164. patient_start_time := patientBody["patient_start_time"].(string)
  5165. var startTime int64
  5166. if len(patient_start_time) > 0 {
  5167. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  5168. startTime = theTime.Unix()
  5169. }
  5170. patient.PatientStartTime = startTime
  5171. }
  5172. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  5173. patient_end_time := patientBody["patient_end_time"].(string)
  5174. var endTime int64
  5175. if len(patient_end_time) > 0 {
  5176. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  5177. endTime = theTime.Unix()
  5178. }
  5179. patient.PatientEndTime = endTime
  5180. }
  5181. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  5182. record_number := patientBody["infectious_remark"].(string)
  5183. patient.InfectiousRemark = record_number
  5184. }
  5185. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  5186. allergic_history := patientBody["allergic_history"].(string)
  5187. patient.AllergicHistory = allergic_history
  5188. }
  5189. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  5190. patient_address := patientBody["patient_address"].(string)
  5191. patient.PatientAddress = patient_address
  5192. }
  5193. if patientBody["famality_record"] != nil && reflect.TypeOf(patientBody["famality_record"]).String() == "string" {
  5194. famality_record := patientBody["famality_record"].(string)
  5195. patient.FamalityRecord = famality_record
  5196. }
  5197. if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
  5198. print_date := patientBody["print_date"].(string)
  5199. printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
  5200. if err == nil {
  5201. patient.PrintDate = printDateTime.Unix()
  5202. }
  5203. }
  5204. if patientBody["patient_type"] != nil && reflect.TypeOf(patientBody["patient_type"]).String() == "float64" {
  5205. patient_type := int64(patientBody["patient_type"].(float64))
  5206. patient.PatientType = patient_type
  5207. }
  5208. return
  5209. }
  5210. func (c *PatientApiController) GetPatientsByKeyWord() {
  5211. keyWord := c.GetString("keyword")
  5212. adminUserInfo := c.GetAdminUserInfo()
  5213. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  5214. if err != nil {
  5215. utils.ErrorLog(err.Error())
  5216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5217. return
  5218. }
  5219. c.ServeSuccessJSON(map[string]interface{}{
  5220. "patient": patient,
  5221. })
  5222. }
  5223. func (c *PatientApiController) QueryPatientById() {
  5224. id, _ := c.GetInt64("id")
  5225. fmt.Println(id)
  5226. patientInfo := service.QueryPatientById(id)
  5227. c.ServeSuccessJSON(map[string]interface{}{
  5228. "patient": patientInfo,
  5229. })
  5230. return
  5231. }
  5232. func (c *PatientApiController) GetRemindPatientList() {
  5233. page, _ := c.GetInt64("page", 1)
  5234. limit, _ := c.GetInt64("limit", 10)
  5235. adminUserInfo := c.GetAdminUserInfo()
  5236. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  5237. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  5238. if errcode == gorm.ErrRecordNotFound {
  5239. information, err := service.GetAdminUserRoleInformation(0)
  5240. if err != nil {
  5241. utils.ErrorLog(err.Error())
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5243. return
  5244. }
  5245. c.ServeSuccessJSON(map[string]interface{}{
  5246. "total": total,
  5247. "patients": patients,
  5248. "information": information,
  5249. })
  5250. } else if errcode == nil {
  5251. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  5252. if err != nil {
  5253. utils.ErrorLog(err.Error())
  5254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5255. return
  5256. }
  5257. c.ServeSuccessJSON(map[string]interface{}{
  5258. "total": total,
  5259. "patients": patients,
  5260. "information": information,
  5261. })
  5262. }
  5263. }
  5264. func (c *PatientApiController) PostIsOpenRemind() {
  5265. patient_id, _ := c.GetInt64("id", 1)
  5266. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  5267. adminUserInfo := c.GetAdminUserInfo()
  5268. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  5269. if err == nil {
  5270. c.ServeSuccessJSON(map[string]interface{}{
  5271. "msg": "成功",
  5272. "is_open_remind": is_open_remind,
  5273. })
  5274. } else if err != nil {
  5275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5276. }
  5277. }
  5278. func (c *PatientApiController) GetPatientScheduleOne() {
  5279. id, _ := c.GetInt64("id")
  5280. //查询该病人是否当天是排班
  5281. nowDateTime := time.Now()
  5282. nowDate := nowDateTime.Format("2006-01-02")
  5283. nowDate += " 00:00:00"
  5284. timeLayout := "2006-01-02"
  5285. loc, _ := time.LoadLocation("Local")
  5286. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  5287. nowdate := theTime.Unix()
  5288. fmt.Println("nowdate", nowdate)
  5289. adminUser := c.GetAdminUserInfo()
  5290. orgId := adminUser.CurrentOrgId
  5291. fmt.Println("orgid", orgId)
  5292. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  5293. if err != nil {
  5294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5295. return
  5296. }
  5297. c.ServeSuccessJSON(map[string]interface{}{
  5298. "scheduls": scheduls,
  5299. })
  5300. }
  5301. func (c *PatientApiController) ExportPatients() {
  5302. dataBody := make(map[string]interface{}, 0)
  5303. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  5304. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  5305. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  5306. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5307. if err != nil {
  5308. utils.ErrorLog(err.Error())
  5309. return
  5310. }
  5311. utils.ErrorLog("%v", dataBody)
  5312. export_time := time.Now().Unix()
  5313. var patients []*models.Patients
  5314. var total_patients []interface{}
  5315. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  5316. tempPatients := dataBody["patients"].([]interface{})
  5317. total_patients = tempPatients
  5318. for index, patientMap := range tempPatients {
  5319. patientNameM := patientMap.(map[string]interface{})
  5320. var patient models.Patients
  5321. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  5322. utils.ErrorLog("name")
  5323. return
  5324. }
  5325. name, _ := patientNameM["name"].(string)
  5326. if len(name) == 0 { //名字为空则生成一条导入错误日志
  5327. err_log := models.ExportErrLog{
  5328. LogType: 1,
  5329. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5330. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  5331. Status: 1,
  5332. CreateTime: time.Now().Unix(),
  5333. UpdateTime: time.Now().Unix(),
  5334. ExportTime: export_time,
  5335. }
  5336. service.CreateExportErrLog(&err_log)
  5337. continue
  5338. }
  5339. patient.Name = name
  5340. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  5341. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  5342. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  5343. err_log := models.ExportErrLog{
  5344. LogType: 1,
  5345. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5346. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  5347. Status: 1,
  5348. CreateTime: time.Now().Unix(),
  5349. UpdateTime: time.Now().Unix(),
  5350. ExportTime: export_time,
  5351. }
  5352. service.CreateExportErrLog(&err_log)
  5353. continue
  5354. } else {
  5355. patient.Gender = gender
  5356. }
  5357. }
  5358. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  5359. phone, _ := patientNameM["phone"].(string)
  5360. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  5361. if len(phone) == 0 {
  5362. err_log := models.ExportErrLog{
  5363. LogType: 1,
  5364. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5365. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  5366. Status: 1,
  5367. CreateTime: time.Now().Unix(),
  5368. UpdateTime: time.Now().Unix(),
  5369. ExportTime: export_time,
  5370. }
  5371. service.CreateExportErrLog(&err_log)
  5372. continue
  5373. } else {
  5374. err_log := models.ExportErrLog{
  5375. LogType: 1,
  5376. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5377. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  5378. Status: 1,
  5379. CreateTime: time.Now().Unix(),
  5380. UpdateTime: time.Now().Unix(),
  5381. ExportTime: export_time,
  5382. }
  5383. service.CreateExportErrLog(&err_log)
  5384. continue
  5385. }
  5386. } else {
  5387. //var tempPatient *models.Patients
  5388. //for _, item := range all_patient {
  5389. // if item.Phone == phone {
  5390. // tempPatient = item
  5391. // }
  5392. //}
  5393. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  5394. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  5395. if count >= 1 {
  5396. err_log := models.ExportErrLog{
  5397. LogType: 1,
  5398. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5399. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  5400. Status: 1,
  5401. CreateTime: time.Now().Unix(),
  5402. UpdateTime: time.Now().Unix(),
  5403. ExportTime: export_time,
  5404. }
  5405. service.CreateExportErrLog(&err_log)
  5406. continue
  5407. }
  5408. patient.Phone = phone
  5409. }
  5410. }
  5411. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  5412. id_card_no, _ := patientNameM["id_card_no"].(string)
  5413. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5414. if count >= 1 {
  5415. //if tempPatient != nil && tempPatient.ID > 0 {
  5416. err_log := models.ExportErrLog{
  5417. LogType: 1,
  5418. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5419. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  5420. Status: 1,
  5421. CreateTime: time.Now().Unix(),
  5422. UpdateTime: time.Now().Unix(),
  5423. ExportTime: export_time,
  5424. }
  5425. service.CreateExportErrLog(&err_log)
  5426. continue
  5427. }
  5428. //}
  5429. patient.IdCardNo = id_card_no
  5430. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  5431. if GetBirthDay(id_card_no) == nil {
  5432. patient.Birthday = 0
  5433. } else {
  5434. patient.Birthday = GetBirthDay(id_card_no).Unix()
  5435. }
  5436. }
  5437. fmt.Println("111112222")
  5438. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  5439. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  5440. timeLayout := "2006/01/02"
  5441. loc, _ := time.LoadLocation("Local")
  5442. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5443. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5444. if len(first_treatment_date) == 0 {
  5445. err_log := models.ExportErrLog{
  5446. LogType: 1,
  5447. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5448. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5449. Status: 1,
  5450. CreateTime: time.Now().Unix(),
  5451. UpdateTime: time.Now().Unix(),
  5452. ExportTime: export_time,
  5453. }
  5454. service.CreateExportErrLog(&err_log)
  5455. continue
  5456. } else {
  5457. err_log := models.ExportErrLog{
  5458. LogType: 1,
  5459. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5460. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5461. Status: 1,
  5462. CreateTime: time.Now().Unix(),
  5463. UpdateTime: time.Now().Unix(),
  5464. ExportTime: export_time,
  5465. }
  5466. service.CreateExportErrLog(&err_log)
  5467. continue
  5468. }
  5469. } else {
  5470. if len(first_treatment_date) == 0 {
  5471. err_log := models.ExportErrLog{
  5472. LogType: 1,
  5473. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5474. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5475. Status: 1,
  5476. CreateTime: time.Now().Unix(),
  5477. UpdateTime: time.Now().Unix(),
  5478. ExportTime: export_time,
  5479. }
  5480. service.CreateExportErrLog(&err_log)
  5481. continue
  5482. } else {
  5483. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5484. err_log := models.ExportErrLog{
  5485. LogType: 1,
  5486. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5487. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5488. Status: 1,
  5489. CreateTime: time.Now().Unix(),
  5490. UpdateTime: time.Now().Unix(),
  5491. ExportTime: export_time,
  5492. }
  5493. service.CreateExportErrLog(&err_log)
  5494. continue
  5495. } else {
  5496. patient.FirstDialysisDate = first_dialysis_date.Unix()
  5497. }
  5498. }
  5499. }
  5500. }
  5501. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  5502. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  5503. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  5504. err_log := models.ExportErrLog{
  5505. LogType: 1,
  5506. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5507. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  5508. Status: 1,
  5509. CreateTime: time.Now().Unix(),
  5510. UpdateTime: time.Now().Unix(),
  5511. ExportTime: export_time,
  5512. }
  5513. service.CreateExportErrLog(&err_log)
  5514. continue
  5515. } else if source == 3 {
  5516. err_log := models.ExportErrLog{
  5517. LogType: 1,
  5518. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5519. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  5520. Status: 1,
  5521. CreateTime: time.Now().Unix(),
  5522. UpdateTime: time.Now().Unix(),
  5523. ExportTime: export_time,
  5524. }
  5525. service.CreateExportErrLog(&err_log)
  5526. continue
  5527. } else {
  5528. patient.Source = source
  5529. }
  5530. }
  5531. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  5532. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  5533. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  5534. err_log := models.ExportErrLog{
  5535. LogType: 1,
  5536. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5537. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  5538. Status: 1,
  5539. CreateTime: time.Now().Unix(),
  5540. UpdateTime: time.Now().Unix(),
  5541. ExportTime: export_time,
  5542. }
  5543. service.CreateExportErrLog(&err_log)
  5544. continue
  5545. } else if lapseto == 3 {
  5546. err_log := models.ExportErrLog{
  5547. LogType: 1,
  5548. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5549. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  5550. Status: 1,
  5551. CreateTime: time.Now().Unix(),
  5552. UpdateTime: time.Now().Unix(),
  5553. ExportTime: export_time,
  5554. }
  5555. service.CreateExportErrLog(&err_log)
  5556. continue
  5557. } else {
  5558. patient.Lapseto = lapseto
  5559. }
  5560. }
  5561. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  5562. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  5563. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  5564. err_log := models.ExportErrLog{
  5565. LogType: 1,
  5566. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5567. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  5568. Status: 1,
  5569. CreateTime: time.Now().Unix(),
  5570. UpdateTime: time.Now().Unix(),
  5571. ExportTime: export_time,
  5572. }
  5573. service.CreateExportErrLog(&err_log)
  5574. continue
  5575. } else if is_infectious == 3 {
  5576. err_log := models.ExportErrLog{
  5577. LogType: 1,
  5578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5579. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  5580. Status: 1,
  5581. CreateTime: time.Now().Unix(),
  5582. UpdateTime: time.Now().Unix(),
  5583. ExportTime: export_time,
  5584. }
  5585. service.CreateExportErrLog(&err_log)
  5586. continue
  5587. } else {
  5588. patient.IsInfectious = is_infectious
  5589. }
  5590. }
  5591. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  5592. var contagions []int64
  5593. thisContagions, _ := patientNameM["contagions"].([]interface{})
  5594. if len(thisContagions) > 0 {
  5595. for _, item := range thisContagions {
  5596. if reflect.TypeOf(item).String() != "float64" {
  5597. continue
  5598. }
  5599. contagion := int64(item.(float64))
  5600. if contagion > 0 {
  5601. contagions = append(contagions, contagion)
  5602. }
  5603. }
  5604. }
  5605. patient.ContagionIds = contagions
  5606. }
  5607. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  5608. diagnose, _ := patientNameM["diagnose"].(string)
  5609. patient.Diagnose = diagnose
  5610. }
  5611. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  5612. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  5613. var tempPatient *models.Patients
  5614. for _, item := range all_patient {
  5615. if item.DialysisNo == dialysis_no {
  5616. tempPatient = item
  5617. }
  5618. }
  5619. if tempPatient != nil && tempPatient.ID > 0 {
  5620. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  5621. } else {
  5622. patient.DialysisNo = dialysis_no
  5623. }
  5624. }
  5625. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  5626. height, _ := patientNameM["height"].(string)
  5627. heights, _ := strconv.ParseFloat(height, 64)
  5628. patient.Height = int64(heights)
  5629. }
  5630. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  5631. home_address, _ := patientNameM["home_address"].(string)
  5632. patient.HomeAddress = home_address
  5633. }
  5634. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5635. dry_weight, _ := patientNameM["dry_weight"].(string)
  5636. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5637. patient.DryWeight = dry_weights
  5638. }
  5639. patient.CreatedTime = time.Now().Unix()
  5640. patient.UpdatedTime = time.Now().Unix()
  5641. patient.Status = 1
  5642. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5643. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5644. patient.IsExcelExport = 1
  5645. patient.PatientType = 1
  5646. patients = append(patients, &patient)
  5647. }
  5648. }
  5649. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5650. if len(patients) > 0 {
  5651. for _, item := range patients {
  5652. hans := item.Name // 要转换的汉字字符串
  5653. // 创建一个拼音转换器
  5654. p := pinyin.NewArgs()
  5655. // 将汉字转为拼音
  5656. pinyinSlice := pinyin.Pinyin(hans, p)
  5657. // 输出拼音
  5658. fmt.Println("Pinyin:", pinyinSlice)
  5659. // 获取首字母
  5660. firstLetter := ""
  5661. for _, py := range pinyinSlice {
  5662. if len(py) > 0 {
  5663. firstLetter += string(py[0][0])
  5664. }
  5665. }
  5666. item.FirstLetter = firstLetter
  5667. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5668. }
  5669. log := models.ExportLog{
  5670. LogType: 1,
  5671. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5672. TotalNum: int64(len(total_patients)),
  5673. FailNum: int64(len(errLogs)),
  5674. SuccessNum: int64(len(patients)),
  5675. CreateTime: time.Now().Unix(),
  5676. UpdateTime: time.Now().Unix(),
  5677. ExportTime: export_time,
  5678. Status: 1,
  5679. }
  5680. service.CreateExportLog(&log)
  5681. c.ServeSuccessJSON(map[string]interface{}{
  5682. "msg": "导入成功",
  5683. "total_num": len(total_patients),
  5684. "success_num": len(patients),
  5685. "fail_num": int64(len(errLogs)),
  5686. })
  5687. } else {
  5688. log := models.ExportLog{
  5689. LogType: 1,
  5690. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5691. TotalNum: int64(len(total_patients)),
  5692. FailNum: int64(len(errLogs)),
  5693. SuccessNum: int64(len(patients)),
  5694. CreateTime: time.Now().Unix(),
  5695. UpdateTime: time.Now().Unix(),
  5696. ExportTime: export_time,
  5697. Status: 1,
  5698. }
  5699. service.CreateExportLog(&log)
  5700. c.ServeSuccessJSON(map[string]interface{}{
  5701. "msg": "导入成功",
  5702. "total_num": len(total_patients),
  5703. "success_num": len(patients),
  5704. "fail_num": int64(len(errLogs)),
  5705. })
  5706. }
  5707. }
  5708. func GetBirthDay(IDCardNo string) *time.Time {
  5709. dayStr := IDCardNo[6:14]
  5710. birthDay, err := time.Parse("20060102", dayStr)
  5711. if err != nil {
  5712. fmt.Println(err)
  5713. return nil
  5714. }
  5715. return &birthDay
  5716. }
  5717. func IsIdCard(id string) (res bool) {
  5718. id = strings.ToUpper(id)
  5719. if len(id) != 15 && len(id) != 18 {
  5720. fmt.Println("1111111")
  5721. return false
  5722. }
  5723. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5724. if !r.MatchString(id) {
  5725. fmt.Println("222222")
  5726. return false
  5727. }
  5728. if len(id) == 15 {
  5729. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5730. if tm2.Unix() == 0 {
  5731. fmt.Println("44444443333")
  5732. return false
  5733. }
  5734. return true
  5735. } else {
  5736. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5737. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5738. fmt.Println(tm2.Unix())
  5739. if tm2.Unix() == 0 {
  5740. fmt.Println("44445555555")
  5741. return false
  5742. }
  5743. //检验18位身份证的校验码是否正确。
  5744. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5745. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5746. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5747. sign := 0
  5748. for k, v := range arr_int {
  5749. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5750. sign += int_temp * v
  5751. }
  5752. n := sign % 11
  5753. val_num := arr_ch[n]
  5754. if val_num != string([]byte(id)[17:18]) {
  5755. fmt.Println("5556666666")
  5756. return false
  5757. }
  5758. return true
  5759. }
  5760. }
  5761. func (c *PatientApiController) SaveEditAdvices() {
  5762. adminInfo := c.GetAdminUserInfo()
  5763. orgid := adminInfo.CurrentOrgId
  5764. startTime := c.GetString("start_time")
  5765. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5766. groupno, _ := c.GetInt64("groupno")
  5767. fmt.Println("组", groupno)
  5768. date, _ := c.GetInt64("date")
  5769. fmt.Println("date", date)
  5770. patient_id, _ := c.GetInt64("patient_id")
  5771. fmt.Println("paitent_id", patient_id)
  5772. advice := models.XtDoctorAdvice{
  5773. StartTime: theTime.Unix(),
  5774. }
  5775. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5776. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5777. redis := service.RedisClient()
  5778. redis.Set(key, "", time.Second)
  5779. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5780. redis.Set(keyOne, "", time.Second)
  5781. scheduleTime := theTime.Format("2006-01-02")
  5782. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5783. fmt.Println("keyFour323223323232323232", keyFour)
  5784. redis.Set(keyFour, "", time.Second)
  5785. defer redis.Close()
  5786. if err != nil {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5788. return
  5789. }
  5790. c.ServeSuccessJSON(map[string]interface{}{
  5791. "advice": advice,
  5792. })
  5793. }
  5794. func (c *PatientApiController) GetMaxDialysisNo() {
  5795. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5796. c.ServeSuccessJSON(map[string]interface{}{
  5797. "dialysis_no": dialysisNo,
  5798. })
  5799. }
  5800. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5801. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5802. var tempPatient *models.Patients
  5803. for _, item := range patients {
  5804. if item.DialysisNo == dialysisNo2 {
  5805. tempPatient = item
  5806. }
  5807. }
  5808. if tempPatient == nil || tempPatient.ID == 0 {
  5809. return dialysisNo2
  5810. }
  5811. return GenerateDialysisNoTwo(patients)
  5812. }
  5813. func (c *PatientApiController) GetBanner() {
  5814. orgId := c.GetAdminUserInfo().CurrentOrgId
  5815. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5816. if errcodes == gorm.ErrRecordNotFound {
  5817. information, err := service.GetAdminUserRoleInformation(0)
  5818. if err != nil {
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5820. return
  5821. }
  5822. c.ServeSuccessJSON(map[string]interface{}{
  5823. "information": information,
  5824. })
  5825. } else if errcodes == nil {
  5826. information, err := service.GetAdminUserRoleInformation(orgId)
  5827. if err != nil {
  5828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5829. return
  5830. }
  5831. c.ServeSuccessJSON(map[string]interface{}{
  5832. "information": information,
  5833. })
  5834. }
  5835. }
  5836. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5837. patient_id, _ := c.GetInt64("id", 0)
  5838. page, _ := c.GetInt64("page", 0)
  5839. limit, _ := c.GetInt64("limit", 0)
  5840. if patient_id <= 0 {
  5841. c.ServeSuccessJSON(map[string]interface{}{
  5842. "solutions": nil,
  5843. })
  5844. return
  5845. }
  5846. if page <= 0 {
  5847. page = 1
  5848. }
  5849. if limit <= 0 {
  5850. limit = 10
  5851. }
  5852. adminUserInfo := c.GetAdminUserInfo()
  5853. //获取该患者分组的透析模式
  5854. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5855. for _, item := range list {
  5856. //获取该模式最新的1条数据
  5857. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5858. //更新状态值
  5859. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5860. }
  5861. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5862. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5863. if err != nil {
  5864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5865. return
  5866. }
  5867. c.ServeSuccessJSON(map[string]interface{}{
  5868. "solutions": solution,
  5869. "total": total,
  5870. "stockType": stockType,
  5871. })
  5872. }
  5873. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5874. patient_id, _ := c.GetInt64("patient_id")
  5875. mode_id, _ := c.GetInt64("mode_id")
  5876. page, _ := c.GetInt64("page")
  5877. limit, _ := c.GetInt64("limit")
  5878. orgId := c.GetAdminUserInfo().CurrentOrgId
  5879. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5880. if err != nil {
  5881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5882. return
  5883. }
  5884. c.ServeSuccessJSON(map[string]interface{}{
  5885. "list": list,
  5886. "total": total,
  5887. })
  5888. }
  5889. func (c *PatientApiController) SaveFallOutBedPrint() {
  5890. adminInfo := c.GetAdminUserInfo()
  5891. orgid := adminInfo.CurrentOrgId
  5892. dataBody := make(map[string]interface{}, 0)
  5893. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5894. fmt.Println("err", err)
  5895. content := dataBody["content"].(string)
  5896. outPrint := models.XtFallOutPrint{
  5897. UserOrgId: orgid,
  5898. Content: content,
  5899. Status: 1,
  5900. Ctime: time.Now().Unix(),
  5901. Mtime: time.Now().Unix(),
  5902. }
  5903. //查询该机构是否存在
  5904. list, err := service.GetOutPrintList(orgid)
  5905. if list.ID == 0 {
  5906. service.CreateFallOutBedPrint(outPrint)
  5907. }
  5908. if list.ID > 0 {
  5909. service.UpdateFallOutBedPrint(list.ID, content)
  5910. }
  5911. c.ServeSuccessJSON(map[string]interface{}{
  5912. "list": list,
  5913. })
  5914. }
  5915. func (c *PatientApiController) GetFallOutBedPrintList() {
  5916. adminInfo := c.GetAdminUserInfo()
  5917. orgid := adminInfo.CurrentOrgId
  5918. list, _ := service.GetFallOutBedPrintList(orgid)
  5919. c.ServeSuccessJSON(map[string]interface{}{
  5920. "list": list,
  5921. })
  5922. }
  5923. func (c *PatientApiController) SaveFilterInformed() {
  5924. adminInfo := c.GetAdminUserInfo()
  5925. orgid := adminInfo.CurrentOrgId
  5926. dataBody := make(map[string]interface{}, 0)
  5927. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5928. fmt.Println("err", err)
  5929. content := dataBody["content"].(string)
  5930. informed := models.XtFilterInformed{
  5931. UserOrgId: orgid,
  5932. Content: content,
  5933. Status: 1,
  5934. Ctime: time.Now().Unix(),
  5935. Mtime: time.Now().Unix(),
  5936. }
  5937. filterInformed, _ := service.GetFilterInformed(orgid)
  5938. if filterInformed.ID == 0 {
  5939. service.CreateFilterInformed(informed)
  5940. }
  5941. if filterInformed.ID > 0 {
  5942. service.UpdateFilterInformed(filterInformed.ID, content)
  5943. }
  5944. c.ServeSuccessJSON(map[string]interface{}{
  5945. "informed": informed,
  5946. })
  5947. }
  5948. func (c *PatientApiController) GetFilterInformed() {
  5949. adminInfo := c.GetAdminUserInfo()
  5950. orgid := adminInfo.CurrentOrgId
  5951. filterInformed, _ := service.GetFilterInformed(orgid)
  5952. c.ServeSuccessJSON(map[string]interface{}{
  5953. "list": filterInformed,
  5954. })
  5955. }
  5956. func (c *PatientApiController) SaveProfundaInformed() {
  5957. adminInfo := c.GetAdminUserInfo()
  5958. orgid := adminInfo.CurrentOrgId
  5959. dataBody := make(map[string]interface{}, 0)
  5960. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5961. fmt.Println("err", err)
  5962. content := dataBody["content"].(string)
  5963. informed := models.XtProfundaInformed{
  5964. UserOrgId: orgid,
  5965. Content: content,
  5966. Status: 1,
  5967. Ctime: time.Now().Unix(),
  5968. Mtime: time.Now().Unix(),
  5969. }
  5970. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5971. if profundaInformed.ID == 0 {
  5972. service.CreateProfundaInformed(informed)
  5973. }
  5974. if profundaInformed.ID > 0 {
  5975. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5976. }
  5977. c.ServeSuccessJSON(map[string]interface{}{
  5978. "list": profundaInformed,
  5979. })
  5980. }
  5981. func (c *PatientApiController) GetProfundaInformed() {
  5982. adminInfo := c.GetAdminUserInfo()
  5983. orgid := adminInfo.CurrentOrgId
  5984. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5985. c.ServeSuccessJSON(map[string]interface{}{
  5986. "list": profundaInformed,
  5987. })
  5988. }
  5989. func (c *PatientApiController) SaveArterOvenous() {
  5990. adminInfo := c.GetAdminUserInfo()
  5991. orgid := adminInfo.CurrentOrgId
  5992. dataBody := make(map[string]interface{}, 0)
  5993. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5994. fmt.Println("err", err)
  5995. content := dataBody["content"].(string)
  5996. arterOvenous := models.XtArterOvenous{
  5997. UserOrgId: orgid,
  5998. Content: content,
  5999. Status: 1,
  6000. Ctime: time.Now().Unix(),
  6001. Mtime: time.Now().Unix(),
  6002. }
  6003. list, _ := service.GetArterOvenousList(orgid)
  6004. if list.ID == 0 {
  6005. service.CreateArterOvernous(arterOvenous)
  6006. }
  6007. if list.ID > 0 {
  6008. service.UpdateArterOvernous(list.ID, content)
  6009. }
  6010. c.ServeSuccessJSON(map[string]interface{}{
  6011. "list": list,
  6012. })
  6013. }
  6014. func (c *PatientApiController) GetArterOverNous() {
  6015. adminInfo := c.GetAdminUserInfo()
  6016. orgid := adminInfo.CurrentOrgId
  6017. list, _ := service.GetArterOvenousList(orgid)
  6018. c.ServeSuccessJSON(map[string]interface{}{
  6019. "list": list,
  6020. })
  6021. }
  6022. func (c *PatientApiController) SaveHighRikInformed() {
  6023. adminInfo := c.GetAdminUserInfo()
  6024. orgid := adminInfo.CurrentOrgId
  6025. dataBody := make(map[string]interface{}, 0)
  6026. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6027. fmt.Println("err", err)
  6028. content := dataBody["content"].(string)
  6029. risk := models.XtHightRisk{
  6030. UserOrgId: orgid,
  6031. Content: content,
  6032. Status: 1,
  6033. Ctime: time.Now().Unix(),
  6034. Mtime: time.Now().Unix(),
  6035. }
  6036. highRik, _ := service.GetHightRikInformed(orgid)
  6037. if highRik.ID == 0 {
  6038. service.CreateHighRik(risk)
  6039. }
  6040. if highRik.ID > 0 {
  6041. service.UpdateHighRik(highRik.ID, content)
  6042. }
  6043. c.ServeSuccessJSON(map[string]interface{}{
  6044. "list": risk,
  6045. })
  6046. }
  6047. func (c *PatientApiController) GetHighRiskInformed() {
  6048. orgId := c.GetAdminUserInfo().CurrentOrgId
  6049. rikInformed, _ := service.GetHightRikInformed(orgId)
  6050. c.ServeSuccessJSON(map[string]interface{}{
  6051. "list": rikInformed,
  6052. })
  6053. }
  6054. func (c *PatientApiController) SaveAnticoagulation() {
  6055. orgId := c.GetAdminUserInfo().CurrentOrgId
  6056. dataBody := make(map[string]interface{}, 0)
  6057. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6058. fmt.Println("err", err)
  6059. content := dataBody["content"].(string)
  6060. auticoagutionPrint := models.XtAuticoagutionPrint{
  6061. Content: content,
  6062. UserOrgId: orgId,
  6063. Status: 1,
  6064. Ctime: time.Now().Unix(),
  6065. Mtime: time.Now().Unix(),
  6066. }
  6067. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6068. if anticoagulation.ID == 0 {
  6069. service.CreateAnticoagulation(auticoagutionPrint)
  6070. }
  6071. if anticoagulation.ID > 0 {
  6072. service.UpdateAnticoagulation(anticoagulation.ID, content)
  6073. }
  6074. c.ServeSuccessJSON(map[string]interface{}{
  6075. "list": auticoagutionPrint,
  6076. })
  6077. }
  6078. func (c *PatientApiController) GetAnticoagulationInformed() {
  6079. orgId := c.GetAdminUserInfo().CurrentOrgId
  6080. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6081. c.ServeSuccessJSON(map[string]interface{}{
  6082. "list": anticoagulation,
  6083. })
  6084. }
  6085. func (c *PatientApiController) SaveCriticalInfomed() {
  6086. orgId := c.GetAdminUserInfo().CurrentOrgId
  6087. dataBody := make(map[string]interface{}, 0)
  6088. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6089. fmt.Println("err", err)
  6090. content := dataBody["content"].(string)
  6091. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  6092. UserOrgId: orgId,
  6093. Content: content,
  6094. Status: 1,
  6095. Ctime: time.Now().Unix(),
  6096. Mtime: time.Now().Unix(),
  6097. }
  6098. infomed, _ := service.GetCriticalInfomed(orgId)
  6099. if infomed.ID == 0 {
  6100. service.CreatedCriticalInfomed(criticalinfomedPrint)
  6101. }
  6102. if infomed.ID > 0 {
  6103. service.UpdateCriticalInfomed(infomed.ID, content)
  6104. }
  6105. c.ServeSuccessJSON(map[string]interface{}{
  6106. "list": criticalinfomedPrint,
  6107. })
  6108. }
  6109. func (c *PatientApiController) GetCriticalInformed() {
  6110. orgId := c.GetAdminUserInfo().CurrentOrgId
  6111. infomed, _ := service.GetCriticalInfomed(orgId)
  6112. c.ServeSuccessJSON(map[string]interface{}{
  6113. "list": infomed,
  6114. })
  6115. }
  6116. func (c *PatientApiController) SaveHemoperfusionInformed() {
  6117. orgId := c.GetAdminUserInfo().CurrentOrgId
  6118. dataBody := make(map[string]interface{}, 0)
  6119. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6120. fmt.Println("err", err)
  6121. content := dataBody["content"].(string)
  6122. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  6123. UserOrgId: orgId,
  6124. Content: content,
  6125. Status: 1,
  6126. Ctime: time.Now().Unix(),
  6127. Mtime: time.Now().Unix(),
  6128. }
  6129. informed, _ := service.GetHemoperfusionInformed(orgId)
  6130. if informed.ID == 0 {
  6131. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  6132. }
  6133. if informed.ID > 0 {
  6134. service.UpdateHemoperfusionInformed(informed.ID, content)
  6135. }
  6136. c.ServeSuccessJSON(map[string]interface{}{
  6137. "list": hemoperfusionmedPrint,
  6138. })
  6139. }
  6140. func (c *PatientApiController) GetHemoperfusionInformed() {
  6141. orgId := c.GetAdminUserInfo().CurrentOrgId
  6142. informed, _ := service.GetHemoperfusionInformed(orgId)
  6143. c.ServeSuccessJSON(map[string]interface{}{
  6144. "list": informed,
  6145. })
  6146. }
  6147. func (c *PatientApiController) SaveBringInformed() {
  6148. orgId := c.GetAdminUserInfo().CurrentOrgId
  6149. dataBody := make(map[string]interface{}, 0)
  6150. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6151. fmt.Println("err", err)
  6152. content := dataBody["content"].(string)
  6153. bringinformedPrint := models.XtBringinformedPrint{
  6154. Content: content,
  6155. UserOrgId: orgId,
  6156. Ctime: time.Now().Unix(),
  6157. Mtime: time.Now().Unix(),
  6158. Status: 1,
  6159. }
  6160. informed, _ := service.GetBringInformed(orgId)
  6161. if informed.ID == 0 {
  6162. service.CreateBringInformed(bringinformedPrint)
  6163. }
  6164. if informed.ID > 0 {
  6165. service.UpdateBringInformed(informed.ID, content)
  6166. }
  6167. c.ServeSuccessJSON(map[string]interface{}{
  6168. "list": bringinformedPrint,
  6169. })
  6170. }
  6171. func (c *PatientApiController) GetInformedContsent() {
  6172. orgId := c.GetAdminUserInfo().CurrentOrgId
  6173. informed, _ := service.GetBringInformed(orgId)
  6174. c.ServeSuccessJSON(map[string]interface{}{
  6175. "list": informed,
  6176. })
  6177. }
  6178. func (c *PatientApiController) SaveCatheterization() {
  6179. orgId := c.GetAdminUserInfo().CurrentOrgId
  6180. dataBody := make(map[string]interface{}, 0)
  6181. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6182. fmt.Println("err", err)
  6183. content := dataBody["content"].(string)
  6184. cathetercationPrint := models.XtCathetercationPrint{
  6185. UserOrgId: orgId,
  6186. Content: content,
  6187. Status: 1,
  6188. Ctime: time.Now().Unix(),
  6189. Mtime: time.Now().Unix(),
  6190. }
  6191. catheterization, _ := service.GetCatheterization(orgId)
  6192. if cathetercationPrint.ID == 0 {
  6193. service.CreateCatheteriztion(cathetercationPrint)
  6194. }
  6195. if cathetercationPrint.ID > 0 {
  6196. service.UpdateCatheterization(catheterization.ID, content)
  6197. }
  6198. c.ServeSuccessJSON(map[string]interface{}{
  6199. "list": catheterization,
  6200. })
  6201. }
  6202. func (c *PatientApiController) GetCatheterization() {
  6203. orgId := c.GetAdminUserInfo().CurrentOrgId
  6204. catheterization, _ := service.GetCatheterization(orgId)
  6205. c.ServeSuccessJSON(map[string]interface{}{
  6206. "list": catheterization,
  6207. })
  6208. }
  6209. func (c *PatientApiController) SaveDialyzerInformed() {
  6210. orgId := c.GetAdminUserInfo().CurrentOrgId
  6211. dataBody := make(map[string]interface{}, 0)
  6212. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6213. fmt.Println("err", err)
  6214. content := dataBody["content"].(string)
  6215. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  6216. UserOrgId: orgId,
  6217. Content: content,
  6218. Status: 1,
  6219. Ctime: time.Now().Unix(),
  6220. Mtime: time.Now().Unix(),
  6221. }
  6222. informed, _ := service.GetDialyzerInformed(orgId)
  6223. if informed.ID == 0 {
  6224. service.CreateDialyzerInformed(dialyszerinformedPrint)
  6225. }
  6226. if informed.ID > 0 {
  6227. service.UpdateDialyszerInformed(informed.ID, content)
  6228. }
  6229. c.ServeSuccessJSON(map[string]interface{}{
  6230. "list": dialyszerinformedPrint,
  6231. })
  6232. }
  6233. func (c *PatientApiController) GetDialyzerInformed() {
  6234. orgId := c.GetAdminUserInfo().CurrentOrgId
  6235. informed, _ := service.GetDialyzerInformed(orgId)
  6236. c.ServeSuccessJSON(map[string]interface{}{
  6237. "list": informed,
  6238. })
  6239. }
  6240. func (c *PatientApiController) SaveTheapyInformed() {
  6241. orgId := c.GetAdminUserInfo().CurrentOrgId
  6242. dataBody := make(map[string]interface{}, 0)
  6243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6244. fmt.Println("err", err)
  6245. content := dataBody["content"].(string)
  6246. theapyinformedPrint := models.XtTheapyinformedPrint{
  6247. Content: content,
  6248. UserOrgId: orgId,
  6249. Status: 1,
  6250. Ctime: time.Now().Unix(),
  6251. Mtime: time.Now().Unix(),
  6252. }
  6253. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6254. if theapyInformed.ID == 0 {
  6255. service.CreateTheapyInformed(theapyinformedPrint)
  6256. }
  6257. if theapyInformed.ID > 0 {
  6258. service.UpdateTheaphInformed(theapyInformed.ID, content)
  6259. }
  6260. c.ServeSuccessJSON(map[string]interface{}{
  6261. "list": theapyinformedPrint,
  6262. })
  6263. }
  6264. func (c *PatientApiController) GetTherapyInformed() {
  6265. orgId := c.GetAdminUserInfo().CurrentOrgId
  6266. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6267. c.ServeSuccessJSON(map[string]interface{}{
  6268. "list": theapyInformed,
  6269. })
  6270. }
  6271. func (c *PatientApiController) SaveMedicalHistory() {
  6272. orgId := c.GetAdminUserInfo().CurrentOrgId
  6273. dataBody := make(map[string]interface{}, 0)
  6274. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6275. fmt.Println("err", err)
  6276. content := dataBody["content"].(string)
  6277. patient_id := int64(dataBody["patient_id"].(float64))
  6278. medicalHistory := models.XtMedicalHistory{
  6279. UserOrgId: orgId,
  6280. PatientId: patient_id,
  6281. Ctime: time.Now().Unix(),
  6282. Mtime: 0,
  6283. Status: 1,
  6284. Content: content,
  6285. }
  6286. //
  6287. history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
  6288. if history.ID > 0 {
  6289. service.UpdatePatientMedicalHistory(history.ID, content)
  6290. }
  6291. if history.ID == 0 {
  6292. service.CreatePatientMedicalHistory(medicalHistory)
  6293. }
  6294. c.ServeSuccessJSON(map[string]interface{}{
  6295. "medicalHistory": medicalHistory,
  6296. })
  6297. }
  6298. func (c *PatientApiController) SavePatientCritaicalInformed() {
  6299. orgId := c.GetAdminUserInfo().CurrentOrgId
  6300. dataBody := make(map[string]interface{}, 0)
  6301. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6302. fmt.Println("err", err)
  6303. content := dataBody["content"].(string)
  6304. patientCritical := models.XtPatientCritical{
  6305. UserOrgId: orgId,
  6306. Content: content,
  6307. Status: 1,
  6308. Ctime: time.Now().Unix(),
  6309. Mtime: time.Now().Unix(),
  6310. }
  6311. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6312. if patientCritaicalInformed.ID == 0 {
  6313. service.CreatePatientCritaicalinformed(patientCritical)
  6314. }
  6315. if patientCritaicalInformed.ID > 0 {
  6316. service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
  6317. }
  6318. c.ServeSuccessJSON(map[string]interface{}{
  6319. "patientCritical": patientCritical,
  6320. })
  6321. }
  6322. func (c *PatientApiController) GetPatientCriticalList() {
  6323. orgId := c.GetAdminUserInfo().CurrentOrgId
  6324. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6325. c.ServeSuccessJSON(map[string]interface{}{
  6326. "patientCritaicalInformed": patientCritaicalInformed,
  6327. })
  6328. }
  6329. func (c *PatientApiController) SavePatientCriticalInformedOne() {
  6330. orgId := c.GetAdminUserInfo().CurrentOrgId
  6331. dataBody := make(map[string]interface{}, 0)
  6332. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6333. fmt.Println("err", err)
  6334. content := dataBody["content"].(string)
  6335. criticalOne := models.XtPatientCriticalOne{
  6336. UserOrgId: orgId,
  6337. Content: content,
  6338. Status: 1,
  6339. Ctime: time.Now().Unix(),
  6340. Mtime: time.Now().Unix(),
  6341. }
  6342. critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
  6343. if critical.ID == 0 {
  6344. service.CreatePatientCritical(criticalOne)
  6345. }
  6346. if critical.ID > 0 {
  6347. service.UpdatePatientCriticalOne(orgId, content)
  6348. }
  6349. c.ServeSuccessJSON(map[string]interface{}{
  6350. "criticalOne": criticalOne,
  6351. })
  6352. }
  6353. func (c *PatientApiController) GetPatientCriticalOneList() {
  6354. orgId := c.GetAdminUserInfo().CurrentOrgId
  6355. list, _ := service.GetPatientCriticalOneList(orgId)
  6356. c.ServeSuccessJSON(map[string]interface{}{
  6357. "list": list,
  6358. })
  6359. }
  6360. func (c *PatientApiController) DeleteSolution() {
  6361. id, _ := c.GetInt64("id")
  6362. solution, _ := service.DeleteSolutionById(id)
  6363. c.ServeSuccessJSON(map[string]interface{}{
  6364. "solution": solution,
  6365. })
  6366. }
  6367. func (c *PatientApiController) SaveTreatmentPlan() {
  6368. orgId := c.GetAdminUserInfo().CurrentOrgId
  6369. dataBody := make(map[string]interface{}, 0)
  6370. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6371. fmt.Println("err", err)
  6372. content := dataBody["content"].(string)
  6373. theapyinformedPrint := models.XtTreatmentPlan{
  6374. Content: content,
  6375. UserOrgId: orgId,
  6376. Status: 1,
  6377. Ctime: time.Now().Unix(),
  6378. Mtime: time.Now().Unix(),
  6379. }
  6380. treamentPlan, _ := service.GetTreamentPland(orgId)
  6381. if treamentPlan.ID == 0 {
  6382. service.CreateTreatqmentPland(theapyinformedPrint)
  6383. }
  6384. if treamentPlan.ID > 0 {
  6385. service.UpdateTheatmentPland(treamentPlan.ID, content)
  6386. }
  6387. c.ServeSuccessJSON(map[string]interface{}{
  6388. "list": theapyinformedPrint,
  6389. })
  6390. }
  6391. func (c *PatientApiController) GetTreatMentPlanList() {
  6392. orgId := c.GetAdminUserInfo().CurrentOrgId
  6393. treamentPlan, _ := service.GetTreamentPland(orgId)
  6394. c.ServeSuccessJSON(map[string]interface{}{
  6395. "treamentPlan": treamentPlan,
  6396. })
  6397. }
  6398. func (c *PatientApiController) GetPatientByPatientId() {
  6399. orgId := c.GetAdminUserInfo().CurrentOrgId
  6400. id, _ := c.GetInt64("id")
  6401. patients, _ := service.GetPatientByIDOne(orgId, id)
  6402. c.ServeSuccessJSON(map[string]interface{}{
  6403. "patients": patients,
  6404. })
  6405. }
  6406. func (c *PatientApiController) SavePatientLapse() {
  6407. dataBody := make(map[string]interface{}, 0)
  6408. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6409. fmt.Println(err)
  6410. patient_id := int64(dataBody["patient_id"].(float64))
  6411. admin_user_id := int64(dataBody["admin_user_id"].(float64))
  6412. lapse_class := int64(dataBody["lapse_class"].(float64))
  6413. lapse_type := int64(dataBody["lapse_type"].(float64))
  6414. lapse_reason := dataBody["lapse_reason"].(string)
  6415. record_date := dataBody["record_date"].(string)
  6416. lapse_type_name := dataBody["lapse_type_name"].(string)
  6417. his_bed := dataBody["his_bed"].(string)
  6418. his_zone := dataBody["his_zone"].(string)
  6419. his_type := int64(dataBody["his_type"].(float64))
  6420. patient_address := dataBody["patient_address"].(string)
  6421. start_time := dataBody["start_time"].(string)
  6422. end_time := dataBody["end_time"].(string)
  6423. start_time_one := dataBody["start_time_one"].(string)
  6424. end_time_one := dataBody["end_time_one"].(string)
  6425. is_check := int64(dataBody["is_check"].(float64))
  6426. timeLayout := "2006-01-02"
  6427. loc, _ := time.LoadLocation("Local")
  6428. var recordDate int64
  6429. if len(record_date) > 0 {
  6430. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6431. if err != nil {
  6432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6433. return
  6434. }
  6435. recordDate = theTime.Unix()
  6436. }
  6437. var startTime int64
  6438. if len(start_time) > 0 {
  6439. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6440. if err != nil {
  6441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6442. return
  6443. }
  6444. startTime = theTime.Unix()
  6445. }
  6446. var endTime int64
  6447. if len(end_time) > 0 {
  6448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6449. if err != nil {
  6450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6451. return
  6452. }
  6453. endTime = theTime.Unix()
  6454. }
  6455. var startTimeOne int64
  6456. if len(start_time_one) > 0 {
  6457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  6458. if err != nil {
  6459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6460. return
  6461. }
  6462. startTimeOne = theTime.Unix()
  6463. }
  6464. var endTimeOne int64
  6465. if len(end_time_one) > 0 {
  6466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
  6467. if err != nil {
  6468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6469. return
  6470. }
  6471. endTimeOne = theTime.Unix()
  6472. }
  6473. remark := dataBody["remark"].(string)
  6474. org_id := c.GetAdminUserInfo().CurrentOrgId
  6475. record := models.XtPatientLaspseRecord{
  6476. PatientId: patient_id,
  6477. RecordDate: recordDate,
  6478. LapseDate: recordDate,
  6479. LapseType: lapse_type,
  6480. LapseClass: lapse_class,
  6481. LapseReason: lapse_reason,
  6482. AdminUserId: admin_user_id,
  6483. Remark: remark,
  6484. UserOrgId: org_id,
  6485. Ctime: time.Now().Unix(),
  6486. Mtime: time.Now().Unix(),
  6487. Status: 1,
  6488. LapseTypeName: lapse_type_name,
  6489. HisBed: his_bed,
  6490. HisType: his_type,
  6491. HisZone: his_zone,
  6492. StartTime: startTime,
  6493. EndTime: endTime,
  6494. StartTimeOne: startTimeOne,
  6495. EndTimeOne: endTimeOne,
  6496. PatientAddress: patient_address,
  6497. }
  6498. //病人转出
  6499. if lapse_type == 2 {
  6500. service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
  6501. if is_check == 2 {
  6502. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6503. service.UpdateScheduleItemByPatientId(patient_id)
  6504. }
  6505. }
  6506. //病人转出
  6507. if lapse_type == 3 {
  6508. service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
  6509. if is_check == 2 {
  6510. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6511. service.UpdateScheduleItemByPatientId(patient_id)
  6512. }
  6513. }
  6514. if lapse_type == 11 {
  6515. service.UpdatePatientLasetoType(patient_id, lapse_type)
  6516. }
  6517. //病人转出
  6518. if lapse_type == 1 {
  6519. service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
  6520. }
  6521. service.CreatePatientRecord(record)
  6522. c.ServeSuccessJSON(map[string]interface{}{
  6523. "record": record,
  6524. })
  6525. }
  6526. func (c *PatientApiController) GetPatientLapsorecord() {
  6527. id, _ := c.GetInt64("id")
  6528. lapsorecord, _ := service.GetPatientLapsorecord(id)
  6529. c.ServeSuccessJSON(map[string]interface{}{
  6530. "lapsorecord": lapsorecord,
  6531. })
  6532. }
  6533. func (this *DialysisApiController) GetPatientLapseRecord() {
  6534. patient_id, _ := this.GetInt64("patient_id")
  6535. limit, _ := this.GetInt64("limit")
  6536. page, _ := this.GetInt64("page")
  6537. orgId := this.GetAdminUserInfo().CurrentOrgId
  6538. record, total, _ := service.GetPatientLapseRecord(patient_id, limit, page, orgId)
  6539. this.ServeSuccessJSON(map[string]interface{}{
  6540. "record": record,
  6541. "total": total,
  6542. })
  6543. }
  6544. func (c *DialysisApiController) UpdatePatientLapseRecord() {
  6545. dataBody := make(map[string]interface{}, 0)
  6546. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6547. fmt.Println(err)
  6548. patient_id := int64(dataBody["patient_id"].(float64))
  6549. admin_user_id := int64(dataBody["admin_user_id"].(float64))
  6550. lapse_class := int64(dataBody["lapse_class"].(float64))
  6551. lapse_type := int64(dataBody["lapse_type"].(float64))
  6552. lapse_reason := dataBody["lapse_reason"].(string)
  6553. record_date := dataBody["record_date"].(string)
  6554. lapse_type_name := dataBody["lapse_type_name"].(string)
  6555. his_bed := dataBody["his_bed"].(string)
  6556. his_zone := dataBody["his_zone"].(string)
  6557. his_type := int64(dataBody["his_type"].(float64))
  6558. patient_address := dataBody["patient_address"].(string)
  6559. start_time := dataBody["start_time"].(string)
  6560. end_time := dataBody["end_time"].(string)
  6561. start_time_one := dataBody["start_time_one"].(string)
  6562. end_time_one := dataBody["end_time_one"].(string)
  6563. timeLayout := "2006-01-02"
  6564. loc, _ := time.LoadLocation("Local")
  6565. var recordDate int64
  6566. if len(record_date) > 0 {
  6567. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6568. if err != nil {
  6569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6570. return
  6571. }
  6572. recordDate = theTime.Unix()
  6573. }
  6574. var startTime int64
  6575. if len(start_time) > 0 {
  6576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6577. if err != nil {
  6578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6579. return
  6580. }
  6581. startTime = theTime.Unix()
  6582. }
  6583. var endTime int64
  6584. if len(end_time) > 0 {
  6585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6586. if err != nil {
  6587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6588. return
  6589. }
  6590. endTime = theTime.Unix()
  6591. }
  6592. var startTimeOne int64
  6593. if len(start_time_one) > 0 {
  6594. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  6595. if err != nil {
  6596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6597. return
  6598. }
  6599. startTimeOne = theTime.Unix()
  6600. }
  6601. var endTimeOne int64
  6602. if len(end_time_one) > 0 {
  6603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
  6604. if err != nil {
  6605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6606. return
  6607. }
  6608. endTimeOne = theTime.Unix()
  6609. }
  6610. remark := dataBody["remark"].(string)
  6611. id := int64(dataBody["id"].(float64))
  6612. org_id := c.GetAdminUserInfo().CurrentOrgId
  6613. record := models.XtPatientLaspseRecord{
  6614. ID: id,
  6615. PatientId: patient_id,
  6616. RecordDate: recordDate,
  6617. LapseDate: recordDate,
  6618. LapseType: lapse_type,
  6619. LapseClass: lapse_class,
  6620. LapseReason: lapse_reason,
  6621. AdminUserId: admin_user_id,
  6622. Remark: remark,
  6623. UserOrgId: org_id,
  6624. Ctime: time.Now().Unix(),
  6625. Mtime: time.Now().Unix(),
  6626. Status: 1,
  6627. LapseTypeName: lapse_type_name,
  6628. HisZone: his_zone,
  6629. HisBed: his_bed,
  6630. HisType: his_type,
  6631. StartTime: startTime,
  6632. StartTimeOne: startTimeOne,
  6633. EndTime: endTime,
  6634. EndTimeOne: endTimeOne,
  6635. PatientAddress: patient_address,
  6636. }
  6637. //病人转出
  6638. if lapse_type == 2 {
  6639. service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
  6640. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6641. service.UpdateScheduleItemByPatientId(patient_id)
  6642. }
  6643. if lapse_type == 3 {
  6644. service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
  6645. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6646. service.UpdateScheduleItemByPatientId(patient_id)
  6647. }
  6648. //病人转出
  6649. if lapse_type == 1 {
  6650. service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
  6651. }
  6652. if lapse_type == 11 {
  6653. service.UpdatePatientLasetoType(patient_id, lapse_type)
  6654. }
  6655. service.SavePatientLapseRecord(record)
  6656. c.ServeSuccessJSON(map[string]interface{}{
  6657. "record": record,
  6658. })
  6659. }
  6660. func (c *DialysisApiController) DeletePatientLapseRecord() {
  6661. id, _ := c.GetInt64("id")
  6662. service.DeletePatientLapseRecord(id)
  6663. c.ServeSuccessJSON(map[string]interface{}{
  6664. "msg": "删除成功",
  6665. })
  6666. }
  6667. func (c *DialysisApiController) GetPatientLapseList() {
  6668. fmt.Println("除非哈哈哈哈哈")
  6669. list, _ := service.GetAllpatientFivty()
  6670. if len(list) > 0 {
  6671. for _, item := range list {
  6672. patientLaspseRecord := models.XtPatientLaspseRecord{
  6673. PatientId: item.ID,
  6674. RecordDate: 0,
  6675. LapseDate: item.CreatedTime,
  6676. LapseType: 1,
  6677. LapseClass: 0,
  6678. LapseReason: "",
  6679. AdminUserId: item.RegistrarsId,
  6680. Remark: "",
  6681. UserOrgId: item.UserOrgId,
  6682. Ctime: time.Now().Unix(),
  6683. Mtime: time.Now().Unix(),
  6684. Status: 1,
  6685. LapseTypeName: "",
  6686. HisType: 0,
  6687. HisZone: "",
  6688. HisBed: "",
  6689. PatientAddress: "",
  6690. StartTime: 0,
  6691. EndTime: 0,
  6692. StartTimeOne: 0,
  6693. EndTimeOne: 0,
  6694. }
  6695. service.CreatePatientRecord(patientLaspseRecord)
  6696. }
  6697. }
  6698. //list, _ := service.GetPatientLapsorecordListOne()
  6699. //
  6700. //if len(list) > 0 {
  6701. // for _, item := range list {
  6702. // //查询患者的信息
  6703. // patients, _ := service.GetPatientByIDTwoOne(item.PatientId)
  6704. //
  6705. // if patients.Lapseto == 2 || patients.Lapseto == 3 {
  6706. //
  6707. // patientLaspseRecord := models.XtPatientLaspseRecord{
  6708. // PatientId: item.PatientId,
  6709. // RecordDate: patients.DeathTime,
  6710. // LapseDate: patients.DeathTime,
  6711. // LapseType: patients.Lapseto,
  6712. // LapseClass: patients.Lapseto,
  6713. // LapseReason: patients.OutReason,
  6714. // AdminUserId: 0,
  6715. // Remark: "",
  6716. // UserOrgId: patients.UserOrgId,
  6717. // Ctime: time.Now().Unix(),
  6718. // Mtime: time.Now().Unix(),
  6719. // Status: 1,
  6720. // LapseTypeName: "",
  6721. // HisType: 0,
  6722. // HisZone: "",
  6723. // HisBed: "",
  6724. // PatientAddress: "",
  6725. // StartTime: patients.PatientStartTime,
  6726. // EndTime: patients.PatientEndTime,
  6727. // StartTimeOne: patients.PatientStartTime,
  6728. // EndTimeOne: patients.PatientEndTime,
  6729. // }
  6730. //
  6731. // service.CreatePatientRecord(patientLaspseRecord)
  6732. // }
  6733. // }
  6734. //}
  6735. //fmt.Println("lsit", list)
  6736. //for _, item := range list {
  6737. //
  6738. //
  6739. //}
  6740. }
  6741. func (c *DialysisApiController) AddDeathSummary() {
  6742. dataBody := make(map[string]interface{}, 0)
  6743. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6744. fmt.Println(err)
  6745. id := int64(dataBody["id"].(float64))
  6746. patient_id := int64(dataBody["patient_id"].(float64))
  6747. record_date := dataBody["record_date"].(string)
  6748. last_record_date := dataBody["last_record_date"].(string)
  6749. reason_one := dataBody["reason_one"].(string)
  6750. reason_two := dataBody["reason_two"].(string)
  6751. reason_three := dataBody["reason_three"].(string)
  6752. reason_four := dataBody["reason_four"].(string)
  6753. death_way := dataBody["death_way"].(string)
  6754. replace_way := dataBody["replace_way"].(string)
  6755. replace_reason := dataBody["replace_reason"].(string)
  6756. transplant := dataBody["transplant"].(string)
  6757. remark := dataBody["remark"].(string)
  6758. timeLayout := "2006-01-02"
  6759. loc, _ := time.LoadLocation("Local")
  6760. var recordDate int64
  6761. if len(record_date) > 0 {
  6762. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6763. if err != nil {
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6765. return
  6766. }
  6767. recordDate = theTime.Unix()
  6768. }
  6769. var lastRecordDate int64
  6770. if len(last_record_date) > 0 {
  6771. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", last_record_date+" 00:00:00", loc)
  6772. if err != nil {
  6773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6774. return
  6775. }
  6776. lastRecordDate = theTime.Unix()
  6777. }
  6778. orgId := c.GetAdminUserInfo().CurrentOrgId
  6779. admin_user_id := c.GetAdminUserInfo().AdminUser.Id
  6780. deathSummary := models.XtDeathSummary{
  6781. ID: id,
  6782. PatientId: patient_id,
  6783. UserOrgId: orgId,
  6784. RecordDate: recordDate,
  6785. ReasonOne: reason_one,
  6786. ReasonTwo: reason_two,
  6787. ReasonThree: reason_three,
  6788. ReasonFour: reason_four,
  6789. DeathWay: death_way,
  6790. ReplaceWay: replace_way,
  6791. ReplaceReason: replace_reason,
  6792. Transplant: transplant,
  6793. Ctime: time.Now().Unix(),
  6794. Remark: remark,
  6795. Mtime: time.Now().Unix(),
  6796. Status: 1,
  6797. AdminUserId: admin_user_id,
  6798. UpdateCreater: admin_user_id,
  6799. LastRecordDate: lastRecordDate,
  6800. }
  6801. service.CreateDeathSummary(deathSummary)
  6802. c.ServeSuccessJSON(map[string]interface{}{
  6803. "deathSummary": deathSummary,
  6804. })
  6805. }
  6806. func (c *DialysisApiController) GetPatientDeathSummary() {
  6807. patient_id, _ := c.GetInt64("patient_id")
  6808. orgId := c.GetAdminUserInfo().CurrentOrgId
  6809. deathSummary, _ := service.GetPatientDeathSummary(patient_id, orgId)
  6810. c.ServeSuccessJSON(map[string]interface{}{
  6811. "deathSummary": deathSummary,
  6812. })
  6813. }
  6814. func (c *DialysisApiController) DeletePatientDeathSummary() {
  6815. id, _ := c.GetInt64("id")
  6816. service.DeletePatientDeathSummary(id)
  6817. c.ServeSuccessJSON(map[string]interface{}{
  6818. "msg": "删除成功",
  6819. })
  6820. }
  6821. func (this *PatientApiController) CreateNewSickHistoryRecord() {
  6822. dataBody := make(map[string]interface{}, 0)
  6823. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6824. if err != nil {
  6825. utils.ErrorLog(err.Error())
  6826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6827. return
  6828. }
  6829. record_date := dataBody["record_time"].(string)
  6830. timeLayout := "2006-01-02"
  6831. loc, _ := time.LoadLocation("Local")
  6832. var recordDate int64
  6833. if len(record_date) > 0 {
  6834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6835. if err != nil {
  6836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6837. return
  6838. }
  6839. recordDate = theTime.Unix()
  6840. }
  6841. id := int64(dataBody["id"].(float64))
  6842. patient_id := int64(dataBody["patient_id"].(float64))
  6843. doctor_id := int64(dataBody["doctor_id"].(float64))
  6844. guominyaowu_desc := dataBody["guominyaowu_desc"].(string)
  6845. is_fumotouxishi := int64(dataBody["is_fumotouxishi"].(float64))
  6846. is_guominyaowu := int64(dataBody["is_guominyaowu"].(float64))
  6847. is_shenyizhishi := int64(dataBody["is_shenyizhishi"].(float64))
  6848. content := dataBody["content"].(string)
  6849. orgId := this.GetAdminUserInfo().CurrentOrgId
  6850. patientSickHistory := models.XtPatientSickHistory{
  6851. ID: id,
  6852. OrgId: orgId,
  6853. PatientId: patient_id,
  6854. Recorder: 0,
  6855. RecordTime: recordDate,
  6856. RecordDate: recordDate,
  6857. Content: content,
  6858. Status: 1,
  6859. Ctime: time.Now().Unix(),
  6860. Mtime: time.Now().Unix(),
  6861. Title: "",
  6862. IsShenyizhiHistory: is_shenyizhishi,
  6863. IsFumoDialysisHistory: is_fumotouxishi,
  6864. HypersusceptibilityDesc: guominyaowu_desc,
  6865. DoctorId: doctor_id,
  6866. IsHypersusceptibility: is_guominyaowu,
  6867. }
  6868. service.CreateNewSickHistoryRecord(patientSickHistory)
  6869. this.ServeSuccessJSON(map[string]interface{}{
  6870. "patientSickHistory": patientSickHistory,
  6871. })
  6872. }
  6873. func (this *PatientApiController) GetNewSickHistory() {
  6874. patient_id, _ := this.GetInt64("patient_id")
  6875. orgId := this.GetAdminUserInfo().CurrentOrgId
  6876. list, _ := service.GetNewSickHistory(patient_id, orgId)
  6877. this.ServeSuccessJSON(map[string]interface{}{
  6878. "list": list,
  6879. })
  6880. }
  6881. func (this *PatientApiController) DeleteNewSickHistory() {
  6882. id, _ := this.GetInt64("id")
  6883. service.DeleteNewSickHistory(id)
  6884. this.ServeSuccessJSON(map[string]interface{}{
  6885. "msg": "ok",
  6886. })
  6887. }
  6888. func (this *PatientApiController) SaveSickHistoryTemplate() {
  6889. dataBody := make(map[string]interface{}, 0)
  6890. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6891. if err != nil {
  6892. utils.ErrorLog(err.Error())
  6893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6894. return
  6895. }
  6896. title := dataBody["title"].(string)
  6897. content := dataBody["content"].(string)
  6898. orgId := this.GetAdminUserInfo().CurrentOrgId
  6899. sickHistoryTemplate := models.XtSickHistoryTemplate{
  6900. Content: content,
  6901. UserOrgId: orgId,
  6902. Title: title,
  6903. Ctime: time.Now().Unix(),
  6904. Mtime: time.Now().Unix(),
  6905. Status: 1,
  6906. }
  6907. service.CreateSickHistoryTemplate(sickHistoryTemplate)
  6908. this.ServeSuccessJSON(map[string]interface{}{
  6909. "sickHistoryTemplate": "sickHistoryTemplate",
  6910. })
  6911. }
  6912. func (this *PatientApiController) GetSickHistoryTemplate() {
  6913. orgId := this.GetAdminUserInfo().CurrentOrgId
  6914. templateList, _ := service.GetSickHistoryTemplate(orgId)
  6915. this.ServeSuccessJSON(map[string]interface{}{
  6916. "templateList": templateList,
  6917. })
  6918. }
  6919. func (this *PatientApiController) ModifySickHistoryTemplate() {
  6920. dataBody := make(map[string]interface{}, 0)
  6921. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6922. if err != nil {
  6923. utils.ErrorLog(err.Error())
  6924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6925. return
  6926. }
  6927. template_id := int64(dataBody["template_id"].(float64))
  6928. content := dataBody["content"].(string)
  6929. service.ModifySickHistoryTemplate(template_id, content)
  6930. this.ServeSuccessJSON(map[string]interface{}{
  6931. "msg": "ok",
  6932. })
  6933. }
  6934. func (this *PatientApiController) DeleteSickHistoryTemplate() {
  6935. template_id, _ := this.GetInt64("template_id")
  6936. service.DeleteSickHistoryTemplate(template_id)
  6937. this.ServeSuccessJSON(map[string]interface{}{
  6938. "msg": "ok",
  6939. })
  6940. }
  6941. func (this *PatientApiController) CreateNewCourseOfDiaseaseRecord() {
  6942. dataBody := make(map[string]interface{}, 0)
  6943. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6944. if err != nil {
  6945. utils.ErrorLog(err.Error())
  6946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6947. return
  6948. }
  6949. patient_id := int64(dataBody["patient_id"].(float64))
  6950. record_date := dataBody["record_date"].(string)
  6951. id := int64(dataBody["id"].(float64))
  6952. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_date)
  6953. content := dataBody["content"].(string)
  6954. admin_user_id := int64(dataBody["admin_user_id"].(float64))
  6955. orgId := this.GetAdminUserInfo().CurrentOrgId
  6956. patientCourse := models.PatientDiseaseCourse{
  6957. ID: id,
  6958. OrgID: orgId,
  6959. PatientID: patient_id,
  6960. Recorder: admin_user_id,
  6961. RecordTime: recordDate.Unix(),
  6962. Content: content,
  6963. Status: 1,
  6964. CreateTime: time.Now().Unix(),
  6965. ModifyTime: time.Now().Unix(),
  6966. Title: "",
  6967. }
  6968. service.CreateNewCourseOfDiaseaseRecord(patientCourse)
  6969. this.ServeSuccessJSON(map[string]interface{}{
  6970. "msg": "ok",
  6971. })
  6972. }
  6973. func (this *PatientApiController) GetPatientCoureseOfDiseasesList() {
  6974. patient_id, _ := this.GetInt64("patient_id")
  6975. orgId := this.GetAdminUserInfo().CurrentOrgId
  6976. list, _ := service.GetPatientCoureseOfDiseasesList(patient_id, orgId)
  6977. this.ServeSuccessJSON(map[string]interface{}{
  6978. "list": list,
  6979. })
  6980. }
  6981. func (this *PatientApiController) DeleteNewCourseOfDisease() {
  6982. id, _ := this.GetInt64("id")
  6983. service.DeleteNewCourseOfDisease(id)
  6984. this.ServeSuccessJSON(map[string]interface{}{
  6985. "msg": "ok",
  6986. })
  6987. }
  6988. func (this *PatientApiController) CreateNewCourseTemplate() {
  6989. dataBody := make(map[string]interface{}, 0)
  6990. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6991. if err != nil {
  6992. utils.ErrorLog(err.Error())
  6993. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6994. return
  6995. }
  6996. title := dataBody["title"].(string)
  6997. content := dataBody["content"].(string)
  6998. orgId := this.GetAdminUserInfo().CurrentOrgId
  6999. courseTemplate := models.XtPatientCourseTemplate{
  7000. Content: content,
  7001. UserOrgId: orgId,
  7002. Title: title,
  7003. Status: 1,
  7004. Ctime: time.Now().Unix(),
  7005. Mtime: time.Now().Unix(),
  7006. }
  7007. service.CreateCourseTemplate(courseTemplate)
  7008. this.ServeSuccessJSON(map[string]interface{}{
  7009. "msg": "ok",
  7010. })
  7011. }
  7012. func (this *PatientApiController) SavePatientDeathRecord() {
  7013. orgId := this.GetAdminUserInfo().CurrentOrgId
  7014. dataBody := make(map[string]interface{}, 0)
  7015. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7016. fmt.Println("err", err)
  7017. content := dataBody["content"].(string)
  7018. dialyszerinformedPrint := models.XtDeathRecord{
  7019. UserOrgId: orgId,
  7020. Content: content,
  7021. Status: 1,
  7022. Ctime: time.Now().Unix(),
  7023. Mtime: time.Now().Unix(),
  7024. }
  7025. informed, _ := service.GetPatientDeathRecord(orgId)
  7026. if informed.ID == 0 {
  7027. service.CreatePatientDeathRecord(dialyszerinformedPrint)
  7028. }
  7029. if informed.ID > 0 {
  7030. service.UpdatePatientDeathRecord(informed.ID, content)
  7031. }
  7032. this.ServeSuccessJSON(map[string]interface{}{
  7033. "list": dialyszerinformedPrint,
  7034. })
  7035. }
  7036. func (this *PatientApiController) GetPatientDeathRecordOne() {
  7037. orgId := this.GetAdminUserInfo().CurrentOrgId
  7038. record, _ := service.GetPatientDeathRecordList(orgId)
  7039. this.ServeSuccessJSON(map[string]interface{}{
  7040. "record": record,
  7041. })
  7042. }
  7043. func (this *PatientApiController) SaveCoureseTemplateTitle() {
  7044. orgId := this.GetAdminUserInfo().CurrentOrgId
  7045. dataBody := make(map[string]interface{}, 0)
  7046. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7047. fmt.Println("err", err)
  7048. title := dataBody["title"].(string)
  7049. content := dataBody["content"].(string)
  7050. courseTemplate := models.XtPatientCourseTemplate{
  7051. Content: content,
  7052. UserOrgId: orgId,
  7053. Title: title,
  7054. Status: 1,
  7055. Ctime: time.Now().Unix(),
  7056. Mtime: time.Now().Unix(),
  7057. }
  7058. service.SaveCoureseTemplateTitle(courseTemplate)
  7059. this.ServeSuccessJSON(map[string]interface{}{
  7060. "courseTemplate": courseTemplate,
  7061. })
  7062. }
  7063. func (this *PatientApiController) GetPatientCourseOfTemplate() {
  7064. orgId := this.GetAdminUserInfo().CurrentOrgId
  7065. list, _ := service.GetPatientCourseOfTemplate(orgId)
  7066. this.ServeSuccessJSON(map[string]interface{}{
  7067. "templateList": list,
  7068. })
  7069. }
  7070. func (this *PatientApiController) SaveCourseOfNewTemplate() {
  7071. dataBody := make(map[string]interface{}, 0)
  7072. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7073. fmt.Println("err", err)
  7074. id := int64(dataBody["template_id"].(float64))
  7075. content := dataBody["content"].(string)
  7076. service.SaveCourseOfNewTemplate(id, content)
  7077. this.ServeSuccessJSON(map[string]interface{}{
  7078. "msg": "ok",
  7079. })
  7080. }
  7081. func (this *PatientApiController) DeleteCouseTemplate() {
  7082. id, _ := this.GetInt64("id")
  7083. service.DeleteCouseTemplate(id)
  7084. this.ServeSuccessJSON(map[string]interface{}{
  7085. "msg": "ok",
  7086. })
  7087. }
  7088. func (this *PatientApiController) GetAutoPatientContent() {
  7089. timeLayout := "2006-01-02"
  7090. loc, _ := time.LoadLocation("Local")
  7091. start_time := this.GetString("start_time")
  7092. end_time := this.GetString("end_time")
  7093. patient_id, _ := this.GetInt64("patient_id")
  7094. fmt.Println("patinet_id ===========================", patient_id)
  7095. orgId := this.GetAdminUserInfo().CurrentOrgId
  7096. var startTime int64
  7097. if len(start_time) > 0 {
  7098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7099. if err != nil {
  7100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7101. return
  7102. }
  7103. startTime = theTime.Unix()
  7104. }
  7105. var endTime int64
  7106. if len(end_time) > 0 {
  7107. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7108. if err != nil {
  7109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7110. return
  7111. }
  7112. endTime = theTime.Unix()
  7113. }
  7114. //获取透析处方
  7115. prescription, _ := service.GetAutoDialysisPrescription(patient_id, startTime, endTime, orgId)
  7116. maxPrescription, _ := service.GetAutoMaxDialysisPrescription(patient_id, startTime, endTime, orgId)
  7117. minPrescription, _ := service.GetAutoMinDialysisPrescription(patient_id, startTime, endTime, orgId)
  7118. berfor, _ := service.GetAutoAssessmentBefor(patient_id, startTime, endTime, orgId)
  7119. monitorList, _ := service.GetAutoMonitorList(patient_id, startTime, endTime, orgId)
  7120. dryweightList, _ := service.GetAutoPatientDryWeight(patient_id, startTime, endTime, orgId)
  7121. inpectionList, _ := service.GetAutoInspectionList(patient_id, startTime, endTime, orgId)
  7122. dialysisOrder, _ := service.GetAutoDialysisOrder(patient_id, startTime, endTime, orgId)
  7123. patient, _ := service.GetPatientByIDOne(orgId, patient_id)
  7124. longAdvice, _ := service.GetLongDoctorAdvice(orgId, patient_id, startTime, endTime)
  7125. this.ServeSuccessJSON(map[string]interface{}{
  7126. "prescription": prescription,
  7127. "berfor": berfor,
  7128. "monitorList": monitorList,
  7129. "dryweightList": dryweightList,
  7130. "inpectionList": inpectionList,
  7131. "dialysisOrder": dialysisOrder,
  7132. "patient": patient,
  7133. "longAdvice": longAdvice,
  7134. "maxPrescription": maxPrescription,
  7135. "minPrescription": minPrescription,
  7136. })
  7137. }
  7138. func (this *PatientApiController) GetPatientRescueRecord() {
  7139. id, _ := this.GetInt64("id")
  7140. rescueRecord, _ := service.GetPatientRescueRecord(id)
  7141. this.ServeSuccessJSON(map[string]interface{}{
  7142. "rescueRecord": rescueRecord,
  7143. })
  7144. }
  7145. func (this *PatientApiController) ModifyCoursePrint() {
  7146. dataBody := make(map[string]interface{}, 0)
  7147. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7148. fmt.Println("err", err)
  7149. id := int64(dataBody["id"].(float64))
  7150. content := dataBody["content"].(string)
  7151. coursePrint, _ := service.ModifyCoursePrint(id, content)
  7152. this.ServeSuccessJSON(map[string]interface{}{
  7153. "coursePrint": coursePrint,
  7154. })
  7155. }
  7156. func (this *PatientApiController) GetPatientRescureRecordList() {
  7157. id, _ := this.GetInt64("id")
  7158. patient_id, _ := this.GetInt64("patient_id")
  7159. orgId := this.GetAdminUserInfo().CurrentOrgId
  7160. appId := this.GetAdminUserInfo().CurrentAppId
  7161. patient, _ := service.GetPatientByIDOne(orgId, patient_id)
  7162. rescueRecordList, _ := service.GetPatientRescureRecordList(id)
  7163. operators, _ := service.GetAdminUserEsTwo(orgId, appId)
  7164. this.ServeSuccessJSON(map[string]interface{}{
  7165. "rescueRecordList": rescueRecordList,
  7166. "patient": patient,
  7167. "operators": operators,
  7168. })
  7169. }