patient_api_controller.go 279KB

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