patient_api_controller.go 298KB

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