patient_api_controller.go 298KB

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