patient_api_controller.go 320KB

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