patient_api_controller.go 264KB

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