patient_api_controller.go 265KB

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