patient_api_controller.go 207KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/jinzhu/gorm"
  9. //"github.com/jinzhu/gorm"
  10. "math"
  11. "math/rand"
  12. "reflect"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  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. }
  68. func (c *PatientApiController) GetExportList() {
  69. startTime := c.GetString("start_time")
  70. endTime := c.GetString("end_time")
  71. schedulType, _ := c.GetInt64("schedul_type", 0)
  72. timeLayout := "2006-01-02"
  73. loc, _ := time.LoadLocation("Local")
  74. adminUserInfo := c.GetAdminUserInfo()
  75. var theStartTIme int64
  76. if len(startTime) > 0 {
  77. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  78. if err != nil {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  80. return
  81. }
  82. theStartTIme = theTime.Unix()
  83. }
  84. var theEndtTIme int64
  85. if len(endTime) > 0 {
  86. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  87. if err != nil {
  88. utils.ErrorLog(err.Error())
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. theEndtTIme = theTime.Unix()
  93. }
  94. timeNowStr := time.Now().Format("2006-01-02")
  95. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  96. schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
  97. fmt.Println("schedule23333333333333333", schedule)
  98. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  99. c.ServeSuccessJSON(map[string]interface{}{
  100. "schedule": schedule,
  101. "patientsList": patientsList,
  102. })
  103. return
  104. }
  105. // GetPatientsList 取患者列表
  106. func (c *PatientApiController) GetPatientsList() {
  107. var err error
  108. defer func() {
  109. if rec := recover(); rec != nil {
  110. err = fmt.Errorf("程序异常:%v", rec)
  111. }
  112. if err != nil {
  113. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  114. }
  115. }()
  116. page, _ := c.GetInt64("page", 1)
  117. limit, _ := c.GetInt64("limit", 10)
  118. schedulType, _ := c.GetInt64("schedul_type", 0)
  119. bindingState, _ := c.GetInt64("binding_state", 0)
  120. lapseto, _ := c.GetInt64("lapseto", 0)
  121. source, _ := c.GetInt64("source", 0)
  122. startTime := c.GetString("start_time", "")
  123. endTime := c.GetString("end_time", "")
  124. keywords := c.GetString("keywords", "")
  125. contagion, _ := c.GetInt64("contagion", 0)
  126. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  127. isscheduling, _ := c.GetInt64("isscheduling", 0)
  128. isprescription, _ := c.GetInt64("isprescription", 0)
  129. patientSoureType, _ := c.GetInt64("patientSoureType")
  130. nurse, _ := c.GetInt64("nurse")
  131. if page <= 0 {
  132. page = 1
  133. }
  134. if limit <= 0 {
  135. limit = 10
  136. }
  137. adminUserInfo := c.GetAdminUserInfo()
  138. timeLayout := "2006-01-02"
  139. loc, _ := time.LoadLocation("Local")
  140. var isStartTime bool
  141. var theStartTIme int64
  142. if len(startTime) > 0 {
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. isStartTime = true
  149. theStartTIme = theTime.Unix()
  150. }
  151. var isEndTime bool
  152. var theEndtTIme int64
  153. if len(endTime) > 0 {
  154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  155. if err != nil {
  156. utils.ErrorLog(err.Error())
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. isEndTime = true
  161. theEndtTIme = theTime.Unix()
  162. }
  163. var patients []*models.Patients
  164. var total int64
  165. 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)
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "patients": patients,
  168. "total": total,
  169. })
  170. return
  171. }
  172. // GetPatientTotal
  173. func (c *PatientApiController) GetPatientTotal() {
  174. adminUserInfo := c.GetAdminUserInfo()
  175. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  176. c.ServeSuccessJSON(map[string]interface{}{
  177. "total": total,
  178. })
  179. return
  180. }
  181. func (c *PatientApiController) GetPatientsAllList() {
  182. adminUserInfo := c.GetAdminUserInfo()
  183. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  184. c.ServeSuccessJSON(map[string]interface{}{
  185. "patients": patients,
  186. "total": total,
  187. })
  188. return
  189. }
  190. // GenerateDialysisNo 生成透析号
  191. func (c *PatientApiController) GenerateDialysisNo() {
  192. adminUserInfo := c.GetAdminUserInfo()
  193. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  194. if dialysisNo == 0 {
  195. dialysisNo = 1
  196. } else {
  197. dialysisNo++
  198. }
  199. no := strconv.FormatInt(dialysisNo, 10)
  200. rep := 3 - len(no)
  201. if rep > 0 {
  202. no = strings.Repeat("0", rep) + no
  203. }
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "no": no,
  206. })
  207. return
  208. }
  209. // CreatePatient 创建患者
  210. func (c *PatientApiController) CreatePatient() {
  211. record_date := c.GetString("record_date")
  212. is_infectious, _ := c.GetInt64("is_infectious")
  213. remind_cycle, _ := c.GetInt64("remind_cycle")
  214. adminUserInfo := c.GetAdminUserInfo()
  215. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  216. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  217. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  219. // return
  220. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  221. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  222. // return
  223. //}
  224. var patient models.Patients
  225. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  226. fmt.Println(code)
  227. fmt.Println(patient)
  228. if code > 0 {
  229. c.ServeFailJSONWithSGJErrorCode(code)
  230. return
  231. }
  232. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  233. if thisPatient.ID > 0 {
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  235. return
  236. }
  237. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  238. if thisPatient.ID > 0 {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  240. return
  241. }
  242. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  243. if thisPatient.ID > 0 {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  245. return
  246. }
  247. patient.RemindCycle = remind_cycle
  248. patient.IsInfectious = is_infectious
  249. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  250. patient.Status = 1
  251. patient.CreatedTime = time.Now().Unix()
  252. patient.UserOrgId = adminUserInfo.CurrentOrgId
  253. patient.UpdatedTime = time.Now().Unix()
  254. patient.BindingState = 2
  255. // patient.Lapseto = 1
  256. err := service.CreatePatient(&patient, contagions, diseases)
  257. fmt.Println("创建病人失败err")
  258. if err != nil {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  260. return
  261. }
  262. //获取老表的最后一条数据
  263. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  264. patientsNew := models.XtPatientsNew{
  265. UserOrgId: adminUserInfo.CurrentOrgId,
  266. UserId: 0,
  267. Avatar: patients.Avatar,
  268. PatientType: patients.PatientType,
  269. DialysisNo: patients.DialysisNo,
  270. AdmissionNumber: patients.AdmissionNumber,
  271. Source: patients.Source,
  272. Lapseto: patients.Lapseto,
  273. PartitionId: patients.PartitionId,
  274. BedId: patients.BedId,
  275. Name: patients.Name,
  276. Alias: patients.Alias,
  277. Gender: patients.Gender,
  278. MaritalStatus: patients.MaritalStatus,
  279. IdCardNo: patients.IdCardNo,
  280. Birthday: patients.Birthday,
  281. ReimbursementWayId: patients.ReimbursementWayId,
  282. HealthCareType: patients.HealthCareType,
  283. HealthCareNo: patients.HealthCareNo,
  284. HealthCareDueDate: patients.HealthCareDueDate,
  285. Height: patients.Height,
  286. BloodType: patients.BloodType,
  287. Rh: patients.Rh,
  288. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  289. EducationLevel: patients.EducationLevel,
  290. Profession: patients.Profession,
  291. Phone: patients.Phone,
  292. HomeTelephone: patients.HomeTelephone,
  293. RelativePhone: patients.RelativePhone,
  294. RelativeRelations: patients.RelativeRelations,
  295. HomeAddress: patients.HomeAddress,
  296. WorkUnit: patients.WorkUnit,
  297. UnitAddress: patients.UnitAddress,
  298. Children: patients.Children,
  299. ReceivingDate: patients.ReceivingDate,
  300. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  301. FirstDialysisDate: patients.FirstDialysisDate,
  302. FirstDialysisHospital: patients.FirstDialysisHospital,
  303. PredialysisCondition: patients.PredialysisCondition,
  304. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  305. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  306. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  307. InductionPeriod: patients.InductionPeriod,
  308. InitialDialysis: patients.InitialDialysis,
  309. TotalDialysis: patients.TotalDialysis,
  310. AttendingDoctorId: patients.AttendingDoctorId,
  311. HeadNurseId: patients.HeadNurseId,
  312. Evaluate: patients.Evaluate,
  313. Diagnose: patients.Diagnose,
  314. Remark: patients.Remark,
  315. RegistrarsId: patients.RegistrarsId,
  316. Registrars: patients.Registrars,
  317. QrCode: patients.QrCode,
  318. BindingState: patients.BindingState,
  319. PatientComplains: patients.PatientComplains,
  320. PresentHistory: patients.PresentHistory,
  321. PastHistory: patients.PresentHistory,
  322. Temperature: patients.Temperature,
  323. Pulse: patients.Pulse,
  324. Respiratory: patients.Respiratory,
  325. Sbp: patients.SBP,
  326. Dbp: patients.DBP,
  327. Status: patients.Status,
  328. CreatedTime: patients.CreatedTime,
  329. UpdatedTime: patients.UpdatedTime,
  330. Nation: patients.Nation,
  331. NativePlace: patients.NativePlace,
  332. Age: patients.Age,
  333. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  334. IsInfectious: patients.IsInfectious,
  335. RemindCycle: patients.RemindCycle,
  336. ResponseResult: patients.ResponseResult,
  337. IsOpenRemind: patients.IsOpenRemind,
  338. FirstTreatmentDate: patients.FirstTreatmentDate,
  339. DialysisAge: patients.DialysisAge,
  340. ExpenseKind: patients.ExpenseKind,
  341. TellPhone: patients.TellPhone,
  342. ContactName: patients.ContactName,
  343. BloodPatients: 1,
  344. SlowPatients: 0,
  345. MemberPatients: 0,
  346. EcommerPatients: "",
  347. BloodId: patients.ID,
  348. SlowId: 0,
  349. MemberId: 0,
  350. MemberFistdate: 0,
  351. MemberPatienttype: 0,
  352. MemberTreatement: 0,
  353. EquitmentId: "",
  354. UserSysBeforeCount: patient.UserSysBeforeCount,
  355. TrobleShoot: patient.TrobleShoot,
  356. TreatmentPlan: patient.TreatmentPlan,
  357. Doctor: patient.Doctor,
  358. RecordNumber: patient.RecordNumber,
  359. PatientSource: patient.PatientSource,
  360. PatientEndTime: patient.PatientEndTime,
  361. PatientStartTime: patient.PatientStartTime,
  362. InfectiousRemark: patient.InfectiousRemark,
  363. AllergicHistory: patient.AllergicHistory,
  364. PatientAddress: patient.PatientAddress,
  365. }
  366. err = service.CreatePatientsNew(&patientsNew)
  367. fmt.Print("创建失败", err)
  368. allergic := models.XtPatientAllergic{
  369. UserOrgId: adminUserInfo.CurrentOrgId,
  370. PatientId: patient.ID,
  371. StartTime: patient.PatientStartTime,
  372. EndTime: patient.PatientEndTime,
  373. PatientSource: patient.PatientSource,
  374. PatientAddress: patient.PatientAddress,
  375. Remake: patient.Remark,
  376. Status: 1,
  377. Ctime: time.Now().Unix(),
  378. }
  379. if len(patient.PatientAddress) > 0 {
  380. service.CreateAllergic(allergic)
  381. }
  382. if len(record_date) > 0 {
  383. var recordTime int64
  384. timeLayout := "2006-01-02"
  385. loc, _ := time.LoadLocation("Local")
  386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  387. if err != nil {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. recordTime = theTime.Unix()
  392. inspections := make([]models.Inspection, 0)
  393. for _, item := range formItems {
  394. var inspection models.Inspection
  395. inspection.OrgId = adminUserInfo.CurrentOrgId
  396. inspection.PatientId = patient.ID
  397. inspection.ProjectId = item.ProjectId
  398. inspection.ItemId = item.ItemId
  399. inspection.ItemName = item.ItemName
  400. inspection.ProjectName = item.ProjectName
  401. inspection.InspectType = item.RangeType
  402. inspection.InspectValue = item.Value
  403. inspection.InspectDate = recordTime
  404. inspection.Status = 1
  405. inspection.CreatedTime = time.Now().Unix()
  406. inspection.UpdatedTime = time.Now().Unix()
  407. inspections = append(inspections, inspection)
  408. }
  409. err = service.CreatePatientInspection(inspections)
  410. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  411. var record_time int64
  412. switch remind_cycle {
  413. case 1: //1个月
  414. ts := time.Unix(infectiousRecord.InspectDate, 0)
  415. record_time = ts.AddDate(0, 1, 0).Unix()
  416. break
  417. case 2: //2个月
  418. ts := time.Unix(infectiousRecord.InspectDate, 0)
  419. record_time = ts.AddDate(0, 2, 0).Unix()
  420. break
  421. case 3: //3个月
  422. ts := time.Unix(infectiousRecord.InspectDate, 0)
  423. record_time = ts.AddDate(0, 3, 0).Unix()
  424. break
  425. case 4: //6个月
  426. ts := time.Unix(infectiousRecord.InspectDate, 0)
  427. record_time = ts.AddDate(0, 6, 0).Unix()
  428. break
  429. case 5: //12个月
  430. ts := time.Unix(infectiousRecord.InspectDate, 0)
  431. record_time = ts.AddDate(0, 12, 0).Unix()
  432. break
  433. }
  434. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  435. if errs != nil {
  436. utils.ErrorLog("更新日期出错:%v", errs)
  437. }
  438. }
  439. redis := service.RedisClient()
  440. defer redis.Close()
  441. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  442. c.ServeSuccessJSON(map[string]interface{}{
  443. "msg": "ok",
  444. })
  445. return
  446. }
  447. // EditPatient 修改
  448. func (c *PatientApiController) EditPatient() {
  449. id, _ := c.GetInt64("id", 0)
  450. record_date := c.GetString("record_date")
  451. is_infectious, _ := c.GetInt64("is_infectious")
  452. remind_cycle, _ := c.GetInt64("remind_cycle")
  453. if id <= 0 {
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. adminUserInfo := c.GetAdminUserInfo()
  458. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  459. if patient.ID == 0 {
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  461. return
  462. }
  463. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  464. if code > 0 {
  465. c.ServeFailJSONWithSGJErrorCode(code)
  466. return
  467. }
  468. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  469. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  471. return
  472. }
  473. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  474. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  476. return
  477. }
  478. patient.UpdatedTime = time.Now().Unix()
  479. patient.IsInfectious = is_infectious
  480. patient.RemindCycle = remind_cycle
  481. err := service.UpdatePatient(&patient, contagions, diseases)
  482. if err != nil {
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  484. return
  485. }
  486. ////更新转归状态
  487. //lapseto := models.PatientLapseto{
  488. // LapsetoType: patient.Lapseto,
  489. // LapsetoTime: time.Now().Unix(),
  490. // UpdatedTime: time.Now().Unix(),
  491. //}
  492. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  493. //fmt.Println("更新转归失败", err)
  494. if err != nil {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  496. return
  497. }
  498. patientsNew := models.XtPatientsNew{
  499. UserOrgId: patient.UserOrgId,
  500. UserId: patient.UserId,
  501. Avatar: patient.Avatar,
  502. PatientType: patient.PatientType,
  503. DialysisNo: patient.DialysisNo,
  504. AdmissionNumber: patient.AdmissionNumber,
  505. Source: patient.Source,
  506. PartitionId: patient.PartitionId,
  507. BedId: patient.BedId,
  508. Name: patient.Name,
  509. Alias: patient.Alias,
  510. Gender: patient.Gender,
  511. MaritalStatus: patient.MaritalStatus,
  512. IdCardNo: patient.IdCardNo,
  513. Birthday: patient.Birthday,
  514. ReimbursementWayId: patient.ReimbursementWayId,
  515. HealthCareType: patient.HealthCareType,
  516. HealthCareNo: patient.HealthCareNo,
  517. HealthCareDueDate: patient.HealthCareDueDate,
  518. Height: patient.Height,
  519. BloodType: patient.BloodType,
  520. Rh: patient.Rh,
  521. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  522. EducationLevel: patient.EducationLevel,
  523. Profession: patient.Profession,
  524. Phone: patient.Phone,
  525. HomeTelephone: patient.HomeTelephone,
  526. RelativePhone: patient.RelativePhone,
  527. RelativeRelations: patient.RelativeRelations,
  528. HomeAddress: patient.HomeAddress,
  529. WorkUnit: patient.WorkUnit,
  530. UnitAddress: patient.UnitAddress,
  531. Children: patient.Children,
  532. ReceivingDate: patient.ReceivingDate,
  533. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  534. FirstDialysisDate: patient.FirstDialysisDate,
  535. FirstDialysisHospital: patient.FirstDialysisHospital,
  536. PredialysisCondition: patient.PredialysisCondition,
  537. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  538. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  539. InductionPeriod: patient.InductionPeriod,
  540. InitialDialysis: patient.InitialDialysis,
  541. TotalDialysis: patient.TotalDialysis,
  542. AttendingDoctorId: patient.AttendingDoctorId,
  543. HeadNurseId: patient.HeadNurseId,
  544. Evaluate: patient.Evaluate,
  545. Diagnose: patient.Diagnose,
  546. Remark: patient.Remark,
  547. RegistrarsId: patient.RegistrarsId,
  548. Registrars: patient.Registrars,
  549. QrCode: patient.QrCode,
  550. BindingState: patient.BindingState,
  551. PatientComplains: patient.PatientComplains,
  552. PresentHistory: patient.PresentHistory,
  553. PastHistory: patient.PastHistory,
  554. Temperature: patient.Temperature,
  555. Pulse: patient.Pulse,
  556. Respiratory: patient.Respiratory,
  557. Sbp: patient.SBP,
  558. Dbp: patient.DBP,
  559. Nation: patient.Nation,
  560. NativePlace: patient.NativePlace,
  561. Age: patient.Age,
  562. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  563. IsInfectious: patient.IsInfectious,
  564. RemindCycle: patient.RemindCycle,
  565. ResponseResult: patient.ResponseResult,
  566. IsOpenRemind: patient.IsOpenRemind,
  567. FirstTreatmentDate: patient.FirstTreatmentDate,
  568. DialysisAge: patient.DialysisAge,
  569. ExpenseKind: patient.ExpenseKind,
  570. TellPhone: patient.TellPhone,
  571. ContactName: patient.ContactName,
  572. UpdatedTime: time.Now().Unix(),
  573. BloodPatients: 1,
  574. Lapseto: patient.Lapseto,
  575. TrobleShoot: patient.TrobleShoot,
  576. SchRemark: patient.SchRemark,
  577. TreatmentPlan: patient.TreatmentPlan,
  578. RecordNumber: patient.RecordNumber,
  579. PatientSource: patient.PatientSource,
  580. PatientStartTime: patient.PatientStartTime,
  581. PatientEndTime: patient.PatientEndTime,
  582. InfectiousRemark: patient.InfectiousRemark,
  583. AllergicHistory: patient.AllergicHistory,
  584. PatientAddress: patient.PatientAddress,
  585. }
  586. // //更新病人ID获取新表病人ID
  587. err = service.UpdatepatientTwo(&patientsNew, id)
  588. allergic := models.XtPatientAllergic{
  589. PatientId: patient.ID,
  590. UserOrgId: adminUserInfo.CurrentOrgId,
  591. StartTime: patient.PatientStartTime,
  592. EndTime: patient.PatientEndTime,
  593. PatientSource: patient.PatientSource,
  594. Status: 1,
  595. Ctime: time.Now().Unix(),
  596. Mtime: time.Now().Unix(),
  597. Remake: patient.Remark,
  598. PatientAddress: patient.PatientAddress,
  599. }
  600. if len(patient.PatientAddress) > 0 {
  601. service.CreateAllergic(allergic)
  602. }
  603. nowTimeUinx := time.Now()
  604. today := nowTimeUinx.Format("2006-01-02")
  605. redis := service.RedisClient()
  606. defer redis.Close()
  607. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  608. redis.Set(key, "", time.Second*60*60*18)
  609. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  610. redis.Set(keyOne, "", time.Second*60*60*18)
  611. if len(record_date) > 0 {
  612. var recordTime int64
  613. timeLayout := "2006-01-02"
  614. loc, _ := time.LoadLocation("Local")
  615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  616. if err != nil {
  617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  618. return
  619. }
  620. recordTime = theTime.Unix()
  621. inspections := make([]models.Inspection, 0)
  622. for _, item := range formItems {
  623. var inspection models.Inspection
  624. inspection.OrgId = adminUserInfo.CurrentOrgId
  625. inspection.PatientId = patient.ID
  626. inspection.ProjectId = item.ProjectId
  627. inspection.ItemId = item.ItemId
  628. inspection.ItemName = item.ItemName
  629. inspection.ProjectName = item.ProjectName
  630. inspection.InspectType = item.RangeType
  631. inspection.InspectValue = item.Value
  632. inspection.InspectDate = recordTime
  633. inspection.Status = 1
  634. inspection.CreatedTime = time.Now().Unix()
  635. inspection.UpdatedTime = time.Now().Unix()
  636. inspections = append(inspections, inspection)
  637. }
  638. err = service.CreatePatientInspection(inspections)
  639. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  640. var record_time int64
  641. switch remind_cycle {
  642. case 1: //1个月
  643. ts := time.Unix(infectiousRecord.InspectDate, 0)
  644. record_time = ts.AddDate(0, 1, 0).Unix()
  645. break
  646. case 2: //2个月
  647. ts := time.Unix(infectiousRecord.InspectDate, 0)
  648. record_time = ts.AddDate(0, 2, 0).Unix()
  649. break
  650. case 3: //3个月
  651. ts := time.Unix(infectiousRecord.InspectDate, 0)
  652. record_time = ts.AddDate(0, 3, 0).Unix()
  653. break
  654. case 4: //6个月
  655. ts := time.Unix(infectiousRecord.InspectDate, 0)
  656. record_time = ts.AddDate(0, 6, 0).Unix()
  657. break
  658. case 5: //12个月
  659. ts := time.Unix(infectiousRecord.InspectDate, 0)
  660. record_time = ts.AddDate(0, 12, 0).Unix()
  661. break
  662. }
  663. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  664. if errs != nil {
  665. utils.ErrorLog("更新日期出错:%v", errs)
  666. }
  667. }
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "msg": "ok",
  670. })
  671. return
  672. }
  673. func (c *PatientApiController) EditLapseto() {
  674. id, _ := c.GetInt64("id", 0)
  675. if id <= 0 {
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. start_time := c.GetString("start_time")
  680. end_time := c.GetString("end_time")
  681. timeLayout := "2006-01-02"
  682. loc, _ := time.LoadLocation("Local")
  683. var startTime int64
  684. if len(start_time) > 0 {
  685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  686. if err != nil {
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  688. return
  689. }
  690. startTime = theTime.Unix()
  691. }
  692. var endTime int64
  693. if len(end_time) > 0 {
  694. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  695. if err != nil {
  696. utils.ErrorLog(err.Error())
  697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  698. return
  699. }
  700. endTime = theTime.Unix()
  701. }
  702. patient_address := c.GetString("patient_address")
  703. adminUserInfo := c.GetAdminUserInfo()
  704. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  705. if patient.ID == 0 {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  707. return
  708. }
  709. patientBody := make(map[string]interface{}, 0)
  710. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  711. if err != nil {
  712. utils.ErrorLog(err.Error())
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  714. return
  715. }
  716. var lapseto models.PatientLapseto
  717. lapseto.PatientId = patient.ID
  718. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  719. utils.ErrorLog("lapseto_type")
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  724. lapseto.LapsetoType = lapsetoType
  725. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  726. utils.ErrorLog("lapseto_time")
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  728. return
  729. }
  730. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  731. //if len(lapsetoTime) == 0 {
  732. // utils.ErrorLog("len(lapsetoTime) == 0")
  733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  734. // return
  735. //}
  736. out_reason, _ := patientBody["out_reason"].(string)
  737. //if len(out_reason) == 0 {
  738. // utils.ErrorLog("len(out_reason) == 0")
  739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  740. // return
  741. //}
  742. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  743. //if err != nil {
  744. // utils.ErrorLog("lapsetoTimeUnix")
  745. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  746. // return
  747. //}
  748. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  749. lapseto.UpdatedTime = time.Now().Unix()
  750. lapseto.CreatedTime = time.Now().Unix()
  751. lapseto.Status = 1
  752. patient.Lapseto = lapseto.LapsetoType
  753. patient.OutReason = out_reason
  754. patient.DeathTime = lapsetoTimeUnix.Unix()
  755. patient.PatientStartTime = startTime
  756. patient.PatientEndTime = endTime
  757. patient.PatientAddress = patient_address
  758. //if patient.Lapseto == 1 {
  759. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  760. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  761. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  762. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  763. // return
  764. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  765. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  766. // return
  767. // }
  768. //}
  769. err = service.EditPatientLapseto(&patient, &lapseto)
  770. if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  771. timeStr := time.Now().Format("2006-01-02")
  772. timeLayout := "2006-01-02 15:04:05"
  773. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  774. timenow := timeStringToTime.Unix()
  775. service.UpdateScheduleByDeathTime(id, timenow)
  776. service.UpdateScheduleItemByPatientId(id)
  777. }
  778. allergic := models.XtPatientAllergic{
  779. UserOrgId: adminUserInfo.CurrentOrgId,
  780. PatientId: patient.ID,
  781. StartTime: patient.PatientStartTime,
  782. EndTime: patient.PatientEndTime,
  783. PatientSource: patient.Lapseto,
  784. PatientAddress: patient.PatientAddress,
  785. Remake: patient.Remark,
  786. Status: 1,
  787. Ctime: time.Now().Unix(),
  788. }
  789. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  790. allergic.StartTime = lapseto.LapsetoTime
  791. allergic.EndTime = lapseto.LapsetoTime
  792. }
  793. service.CreateAllergic(allergic)
  794. if err != nil {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  796. return
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "ok",
  800. })
  801. return
  802. }
  803. func (c *PatientApiController) GetPatient() {
  804. id, _ := c.GetInt64("id", 0)
  805. if id <= 0 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. adminUserInfo := c.GetAdminUserInfo()
  810. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  811. if patient.ID == 0 {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  813. return
  814. }
  815. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  816. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  817. diseases := service.GetPatientDiseases(patient.ID)
  818. contagions := service.GetPatientContagions(patient.ID)
  819. c.ServeSuccessJSON(map[string]interface{}{
  820. "patient": patient,
  821. "diseases": diseases,
  822. "contagions": contagions,
  823. "infections": infections,
  824. })
  825. return
  826. }
  827. func (c *PatientApiController) CreateDialysisSolution() {
  828. id, _ := c.GetInt64("patient", 0)
  829. if id <= 0 {
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. adminUserInfo := c.GetAdminUserInfo()
  834. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  835. if patient.ID == 0 {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  837. return
  838. }
  839. var solution models.DialysisSolution
  840. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  841. if code > 0 {
  842. c.ServeFailJSONWithSGJErrorCode(code)
  843. return
  844. }
  845. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  846. //if thisSolution.ID > 0 {
  847. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  848. // return
  849. //}
  850. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  851. solution.Doctor = adminUserInfo.AdminUser.Id
  852. solution.Status = 1
  853. solution.PatientId = id
  854. solution.CreatedTime = time.Now().Unix()
  855. solution.UserOrgId = adminUserInfo.CurrentOrgId
  856. solution.UpdatedTime = time.Now().Unix()
  857. solution.SubName = ""
  858. solution.ParentId = 0
  859. solution.SolutionStatus = 1
  860. //records, _ := service.GetAllSchedules()
  861. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  862. for _, sch := range schs {
  863. var DialysisMachineName string
  864. if len(solution.DialysisDialyszers) > 0 {
  865. DialysisMachineName = solution.DialysisDialyszers
  866. }
  867. if len(solution.DialyzerPerfusionApparatus) > 0 {
  868. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  869. }
  870. if len(solution.DialysisIrrigation) > 0 {
  871. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  872. }
  873. sch.DialysisMachineName = DialysisMachineName
  874. service.UpdateSch(sch)
  875. }
  876. err := service.CreatePatientDialysisSolution(&solution)
  877. //获取最新1条
  878. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  879. //更新状态
  880. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  881. if err != nil {
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  883. return
  884. }
  885. c.ServeSuccessJSON(map[string]interface{}{
  886. "msg": "ok",
  887. "solution": solution,
  888. })
  889. return
  890. }
  891. func (c *PatientApiController) UpdateDialysisSolution() {
  892. patient, _ := c.GetInt64("patient", 0)
  893. id, _ := c.GetInt64("id", 0)
  894. if id <= 0 || patient <= 0 {
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  896. return
  897. }
  898. adminUserInfo := c.GetAdminUserInfo()
  899. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  900. if solution.ID == 0 || solution.PatientId != patient {
  901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  902. return
  903. }
  904. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  905. if code > 0 {
  906. c.ServeFailJSONWithSGJErrorCode(code)
  907. return
  908. }
  909. solution.UpdatedTime = time.Now().Unix()
  910. err := service.UpdatePatientDialysisSolution(&solution)
  911. nowTimeUinx := time.Now()
  912. today := nowTimeUinx.Format("2006-01-02")
  913. timeLayout := "2006-01-02"
  914. loc, _ := time.LoadLocation("Local")
  915. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  916. if adminUserInfo.CurrentOrgId == 9538 {
  917. prescription := models.DialysisPrescription{
  918. Dialyzer: solution.Dialyzer,
  919. Anticoagulant: solution.Anticoagulant,
  920. AnticoagulantShouji: solution.AnticoagulantShouji,
  921. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  922. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  923. ModeId: solution.ModeId,
  924. DialysisDurationHour: solution.DialysisDurationHour,
  925. Kalium: solution.Kalium,
  926. Sodium: solution.Sodium,
  927. Calcium: solution.Calcium,
  928. TargetUltrafiltration: solution.TargetUltrafiltration,
  929. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  930. BloodAccess: solution.BloodAccess,
  931. DialysateFlow: solution.DialysateFlow,
  932. DialysateTemperature: solution.DialysateTemperature,
  933. DialysisIrrigation: solution.DialysisIrrigation,
  934. DialysisDialyszers: solution.DialysisDialyszers,
  935. PlasmaSeparator: solution.PlasmaSeparator,
  936. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  937. OxygenUptake: solution.OxygenUptake,
  938. OxygenFlow: solution.OxygenFlow,
  939. OxygenTime: solution.OxygenTime,
  940. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  941. Amylaceum: solution.Amylaceum,
  942. DialysisStrainer: solution.DialysisStrainer,
  943. Chaptalization: solution.Chaptalization,
  944. BloodAccessPartId: solution.BloodAccessPartId,
  945. }
  946. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  947. }
  948. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  949. for _, sch := range schs {
  950. var DialysisMachineName string
  951. if len(solution.DialysisDialyszers) > 0 {
  952. DialysisMachineName = solution.DialysisDialyszers
  953. }
  954. if len(solution.DialyzerPerfusionApparatus) > 0 {
  955. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  956. }
  957. if len(solution.DialysisIrrigation) > 0 {
  958. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  959. }
  960. sch.DialysisMachineName = DialysisMachineName
  961. service.UpdateSch(sch)
  962. }
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  965. return
  966. }
  967. c.ServeSuccessJSON(map[string]interface{}{
  968. "msg": "ok",
  969. "solution": solution,
  970. })
  971. return
  972. }
  973. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  974. patient, _ := c.GetInt64("patient", 0)
  975. id, _ := c.GetInt64("id", 0)
  976. if id <= 0 || patient <= 0 {
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  978. return
  979. }
  980. adminUserInfo := c.GetAdminUserInfo()
  981. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  982. if solution.ID == 0 || solution.PatientId != patient {
  983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  984. return
  985. }
  986. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  987. if code > 0 {
  988. c.ServeFailJSONWithSGJErrorCode(code)
  989. return
  990. }
  991. solution.UpdatedTime = time.Now().Unix()
  992. solution.AffirmState = 1
  993. err := service.UpdatePatientDialysisSolution(&solution)
  994. if err != nil {
  995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  996. return
  997. }
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "msg": "ok",
  1000. "solution": solution,
  1001. })
  1002. return
  1003. }
  1004. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1005. id, _ := c.GetInt64("id", 0)
  1006. page, _ := c.GetInt64("page", 0)
  1007. limit, _ := c.GetInt64("limit", 0)
  1008. if id <= 0 {
  1009. c.ServeSuccessJSON(map[string]interface{}{
  1010. "solutions": nil,
  1011. })
  1012. return
  1013. }
  1014. if page <= 0 {
  1015. page = 1
  1016. }
  1017. if limit <= 0 {
  1018. limit = 10
  1019. }
  1020. adminUserInfo := c.GetAdminUserInfo()
  1021. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  1022. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  1023. c.ServeSuccessJSON(map[string]interface{}{
  1024. "solutions": solutions,
  1025. "total": total,
  1026. "stockType": stockType,
  1027. })
  1028. return
  1029. }
  1030. func (c *PatientApiController) DeleteDialysisSolution() {
  1031. id, _ := c.GetInt64("id", 0)
  1032. if id <= 0 {
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. adminUserInfo := c.GetAdminUserInfo()
  1037. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1038. if solution.ID == 0 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1040. return
  1041. }
  1042. if solution.UseState == 1 {
  1043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  1044. return
  1045. }
  1046. solution.UpdatedTime = time.Now().Unix()
  1047. solution.Status = 0
  1048. err := service.DeleteSolution(&solution)
  1049. if err != nil {
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  1051. return
  1052. }
  1053. c.ServeSuccessJSON(map[string]interface{}{
  1054. "msg": "ok",
  1055. })
  1056. return
  1057. }
  1058. // GetDryWeights 取患者干体重调整铺
  1059. func (c *PatientApiController) GetDryWeights() {
  1060. page, _ := c.GetInt64("page", 1)
  1061. limit, _ := c.GetInt64("limit", 10)
  1062. id, _ := c.GetInt64("id", 0)
  1063. if id <= 0 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1065. return
  1066. }
  1067. adminUserInfo := c.GetAdminUserInfo()
  1068. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  1069. c.ServeSuccessJSON(map[string]interface{}{
  1070. "weights": weights,
  1071. "total": total,
  1072. })
  1073. return
  1074. }
  1075. func (c *PatientApiController) CreateDryWeights() {
  1076. patient, _ := c.GetInt64("id", 0)
  1077. if patient <= 0 {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminUserInfo := c.GetAdminUserInfo()
  1082. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1083. if patientInfo.ID == 0 {
  1084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1085. return
  1086. }
  1087. var theWeight models.DryWeightAdjust
  1088. dataBody := make(map[string]interface{}, 0)
  1089. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1090. if err != nil {
  1091. utils.ErrorLog(err.Error())
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  1100. theWeight.Weight = weight
  1101. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  1102. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. // return
  1104. // }
  1105. // doctor := int64(dataBody["doctor"].(float64))
  1106. // theWeight.Doctor = doctor
  1107. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1108. remark, _ := dataBody["remark"].(string)
  1109. theWeight.Remark = remark
  1110. }
  1111. theWeight.CreatedTime = time.Now().Unix()
  1112. theWeight.UpdatedTime = time.Now().Unix()
  1113. theWeight.Status = 1
  1114. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  1115. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  1116. theWeight.PatientId = patient
  1117. theWeight.Doctor = adminUserInfo.AdminUser.Id
  1118. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  1119. if old.ID > 0 {
  1120. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1121. }
  1122. err = service.CreateDryWeightAdjust(&theWeight)
  1123. if err != nil {
  1124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1125. return
  1126. }
  1127. c.ServeSuccessJSON(map[string]interface{}{
  1128. "msg": "ok",
  1129. "weight": theWeight,
  1130. })
  1131. return
  1132. }
  1133. func (c *PatientApiController) CreateGroupAdvice() {
  1134. var err error
  1135. defer func() {
  1136. if rec := recover(); rec != nil {
  1137. err = fmt.Errorf("程序异常:%v", rec)
  1138. }
  1139. if err != nil {
  1140. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1141. }
  1142. }()
  1143. patient, _ := c.GetInt64("id", 0)
  1144. groupNo, _ := c.GetInt64("groupno", 0)
  1145. if patient <= 0 {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1147. return
  1148. }
  1149. adminUserInfo := c.GetAdminUserInfo()
  1150. var patientInfo models.Patients
  1151. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1152. if patientInfo.ID == 0 {
  1153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1154. return
  1155. }
  1156. dataBody := make(map[string]interface{}, 0)
  1157. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1158. if err != nil {
  1159. utils.ErrorLog(err.Error())
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. return
  1162. }
  1163. utils.ErrorLog("%v", dataBody)
  1164. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1165. if appRole.UserType == 3 {
  1166. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1167. if getPermissionErr != nil {
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1169. return
  1170. } else if headNursePermission == nil {
  1171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1172. return
  1173. }
  1174. }
  1175. timeLayout := "2006-01-02"
  1176. loc, _ := time.LoadLocation("Local")
  1177. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1178. utils.ErrorLog("advice_type")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. adviceType := int64(dataBody["advice_type"].(float64))
  1183. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1184. utils.ErrorLog("advice_type != 1&&2")
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1189. utils.ErrorLog("advice_date")
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1191. return
  1192. }
  1193. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1194. utils.ErrorLog("start_time")
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1196. return
  1197. }
  1198. startTime2, _ := dataBody["start_time"].(string)
  1199. time_arr := strings.Split(startTime2, " ")
  1200. if len(time_arr) > 0 {
  1201. startTime2 = time_arr[0]
  1202. }
  1203. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1204. utils.ErrorLog("advice_date")
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. adviceDate := startTime2
  1209. if len(adviceDate) == 0 {
  1210. utils.ErrorLog("len(adviceDate) == 0")
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1215. if err != nil {
  1216. utils.ErrorLog(err.Error())
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1218. return
  1219. }
  1220. AdviceDate := theTime.Unix()
  1221. RecordDate := theTime.Unix()
  1222. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1223. utils.ErrorLog("start_time")
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. startTime, _ := dataBody["start_time"].(string)
  1228. if len(startTime) == 0 {
  1229. utils.ErrorLog("len(start_time) == 0")
  1230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1231. return
  1232. }
  1233. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1234. if err != nil {
  1235. utils.ErrorLog(err.Error())
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. StartTime := theTime.Unix()
  1240. Remark := ""
  1241. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1242. remark, _ := dataBody["remark"].(string)
  1243. Remark = remark
  1244. }
  1245. var advices []*models.GroupAdvice
  1246. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1247. utils.ErrorLog("adviceNames")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. adviceNames := dataBody["adviceNames"].([]interface{})
  1252. for _, adviceNameMap := range adviceNames {
  1253. adviceNameM := adviceNameMap.(map[string]interface{})
  1254. var advice models.GroupAdvice
  1255. advice.Remark = Remark
  1256. advice.AdviceType = adviceType
  1257. advice.StartTime = StartTime
  1258. advice.AdviceDate = AdviceDate
  1259. advice.RecordDate = RecordDate
  1260. advice.Status = 1
  1261. advice.CreatedTime = time.Now().Unix()
  1262. advice.UpdatedTime = time.Now().Unix()
  1263. advice.StopState = 2
  1264. advice.ExecutionState = 2
  1265. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1266. advice.PatientId = patientInfo.ID
  1267. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1268. advice.IsSettle = 2
  1269. //创建步骤表
  1270. finish := models.XtDialysisFinish{
  1271. IsFinish: 1,
  1272. UserOrgId: adminUserInfo.CurrentOrgId,
  1273. Status: 1,
  1274. Ctime: time.Now().Unix(),
  1275. Mtime: 0,
  1276. Module: 4,
  1277. RecordDate: advice.RecordDate,
  1278. Sourse: 1,
  1279. PatientId: patient,
  1280. }
  1281. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
  1282. if dialysisFinish.ID == 0 {
  1283. service.CreateDialysisFinish(finish)
  1284. }
  1285. // 查询信息规挡的设置天数
  1286. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1287. if infor.ID > 0 && infor.WeekDay > 0 {
  1288. var cha_time int64
  1289. timeNowStr := time.Now().Format("2006-01-02")
  1290. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1291. //今日的日期减去设置的日期
  1292. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1293. if cha_time >= advice.AdviceDate {
  1294. //查询审核是否允许
  1295. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1296. //申请状态不允许的情况 拒绝修改
  1297. if infor.ApplicationStatus != 1 {
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1299. return
  1300. }
  1301. }
  1302. }
  1303. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1304. utils.ErrorLog("advice_name")
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. adviceName, _ := adviceNameM["advice_name"].(string)
  1309. if len(adviceName) == 0 {
  1310. utils.ErrorLog("len(advice_name) == 0")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. advice.AdviceName = adviceName
  1315. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1316. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1317. advice.DrugSpec = drugSpec
  1318. }
  1319. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1320. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1321. advice.AdviceDesc = adviceDesc
  1322. }
  1323. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1324. template_id, _ := adviceNameM["template_id"].(string)
  1325. advice.TemplateId = template_id
  1326. }
  1327. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1328. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1329. advice.DrugSpecUnit = drugSpecUnit
  1330. }
  1331. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1332. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1333. advice.SingleDose = singleDose
  1334. }
  1335. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1336. singleDose := adviceNameM["single_dose"].(float64)
  1337. advice.SingleDose = singleDose
  1338. }
  1339. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1340. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1341. advice.SingleDoseUnit = singleDoseUnit
  1342. }
  1343. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1344. tmp := adviceNameM["single_dose_unit"].(float64)
  1345. singleDoseUnit := service.TypeConversion(tmp)
  1346. advice.SingleDoseUnit = singleDoseUnit
  1347. }
  1348. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1349. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1350. advice.PrescribingNumber = prescribingNumber
  1351. }
  1352. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1353. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1354. advice.PrescribingNumber = prescribingNumber
  1355. }
  1356. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1357. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1358. advice.PrescribingNumberUnit = prescribingNumberUnit
  1359. }
  1360. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1361. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1362. advice.DeliveryWay = deliveryWay
  1363. }
  1364. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1365. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1366. advice.ExecutionFrequency = executionFrequency
  1367. }
  1368. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1369. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1370. advice.Way = int64(way)
  1371. }
  1372. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1373. way := int64(adviceNameM["way"].(float64))
  1374. advice.Way = way
  1375. }
  1376. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1377. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1378. advice.DrugId = int64(drug_id)
  1379. }
  1380. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1381. drug_id := int64(adviceNameM["drug_id"].(float64))
  1382. advice.DrugId = drug_id
  1383. }
  1384. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1385. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1386. advice.DrugNameId = drug_name_id
  1387. }
  1388. remark, _ := adviceNameM["remark"].(string)
  1389. advice.Remark = remark
  1390. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1391. if advice.PrescribingNumber == 0 {
  1392. advice.PrescribingNumber = 1
  1393. }
  1394. //查询该患者今日有没有双人核对
  1395. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1396. fmt.Println("chek", check)
  1397. if check.ID > 0 {
  1398. advice.Checker = check.Modifier
  1399. advice.CheckState = 1
  1400. advice.CheckTime = time.Now().Unix()
  1401. }
  1402. }
  1403. if adviceType == 1 {
  1404. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1405. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1406. advice.FrequencyType = frequency_type
  1407. }
  1408. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1409. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1410. advice.DayCount = day_count
  1411. }
  1412. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1413. week_day, _ := adviceNameM["week_days"].(string)
  1414. advice.WeekDay = week_day
  1415. }
  1416. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1417. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1418. var startTime int64
  1419. if len(push_start_time) > 0 {
  1420. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1421. startTime = theTime.Unix()
  1422. }
  1423. advice.PushStartTime = startTime
  1424. }
  1425. }
  1426. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1427. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1428. advice.ExecutionFrequency = executionFrequency
  1429. }
  1430. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1431. children := adviceNameM["children"].([]interface{})
  1432. if len(children) > 0 {
  1433. for _, childrenMap := range children {
  1434. childMap := childrenMap.(map[string]interface{})
  1435. var child models.GroupAdvice
  1436. child.Remark = Remark
  1437. child.AdviceType = adviceType
  1438. child.StartTime = StartTime
  1439. child.AdviceDate = AdviceDate
  1440. child.RecordDate = RecordDate
  1441. child.Status = 1
  1442. child.CreatedTime = time.Now().Unix()
  1443. child.UpdatedTime = time.Now().Unix()
  1444. child.StopState = 2
  1445. child.ExecutionState = 2
  1446. child.UserOrgId = adminUserInfo.CurrentOrgId
  1447. child.PatientId = patientInfo.ID
  1448. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1449. child.IsSettle = 2
  1450. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1451. utils.ErrorLog("child advice_name")
  1452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1453. return
  1454. }
  1455. childAdviceName, _ := childMap["advice_name"].(string)
  1456. if len(childAdviceName) == 0 {
  1457. utils.ErrorLog("len(child advice_name) == 0")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. child.AdviceName = childAdviceName
  1462. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1463. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1464. child.AdviceDesc = childAdviceDesc
  1465. }
  1466. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1467. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1468. child.DrugSpec = childDrugSpec
  1469. }
  1470. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1471. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1472. child.DrugSpecUnit = childDrugSpecUnit
  1473. }
  1474. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1475. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1476. child.SingleDose = childSingleDose
  1477. }
  1478. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1479. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1480. child.SingleDoseUnit = childSingleDoseUnit
  1481. }
  1482. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1483. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1484. child.PrescribingNumber = childPrescribingNumber
  1485. }
  1486. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1487. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1488. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1489. }
  1490. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1491. drug_id := int64(childMap["drug_id"].(float64))
  1492. child.DrugId = drug_id
  1493. }
  1494. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1495. way := int64(childMap["way"].(float64))
  1496. child.Way = way
  1497. }
  1498. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1499. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1500. child.DrugNameId = drug_name_id
  1501. }
  1502. child.DeliveryWay = advice.DeliveryWay
  1503. child.ExecutionFrequency = advice.ExecutionFrequency
  1504. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1505. if child.PrescribingNumber == 0 {
  1506. child.PrescribingNumber = 1
  1507. }
  1508. //查询该患者今日有没有双人核对
  1509. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1510. if check.ID > 0 {
  1511. child.Checker = check.Modifier
  1512. child.CheckState = 1
  1513. child.CheckTime = time.Now().Unix()
  1514. }
  1515. }
  1516. advice.Children = append(advice.Children, &child)
  1517. }
  1518. }
  1519. }
  1520. advices = append(advices, &advice)
  1521. }
  1522. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1523. for _, item := range advices {
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(item)
  1526. adviceLog := models.XtDoctorAdviceLog{
  1527. UserOrgId: item.UserOrgId,
  1528. PatientId: item.PatientId,
  1529. AdminUserId: adminUserInfo.AdminUser.Id,
  1530. Module: 1,
  1531. ErrLog: string(byterequest),
  1532. Status: 1,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "电导端批量插入医嘱",
  1536. RecordDate: item.AdviceDate,
  1537. }
  1538. service.CreateDoctorAdviceLog(adviceLog)
  1539. }
  1540. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1541. redis := service.RedisClient()
  1542. defer redis.Close()
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err != nil {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1548. return
  1549. }
  1550. c.ServeSuccessJSON(map[string]interface{}{
  1551. "msg": "ok",
  1552. "advices": list,
  1553. })
  1554. return
  1555. }
  1556. func (c *PatientApiController) CreateDoctorAdvice() {
  1557. patient, _ := c.GetInt64("id", 0)
  1558. if patient <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetAdminUserInfo()
  1563. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1564. if patientInfo.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1569. if appRole.UserType == 3 {
  1570. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1571. if getPermissionErr != nil {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1573. return
  1574. } else if headNursePermission == nil {
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1576. return
  1577. }
  1578. }
  1579. var advice models.DoctorAdvice
  1580. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1581. if code > 0 {
  1582. c.ServeFailJSONWithSGJErrorCode(code)
  1583. return
  1584. }
  1585. if advice.ParentId > 0 {
  1586. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1587. if old.ID == 0 || old.PatientId != patient {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1589. return
  1590. }
  1591. if old.StopState == 1 || old.ExecutionState == 1 {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1593. return
  1594. }
  1595. if old.ParentId > 0 {
  1596. advice.ParentId = old.ParentId
  1597. }
  1598. advice.StartTime = old.StartTime
  1599. advice.AdviceDoctor = old.AdviceDoctor
  1600. advice.DeliveryWay = old.DeliveryWay
  1601. advice.ExecutionFrequency = old.ExecutionFrequency
  1602. advice.GroupNo = old.GroupNo
  1603. }
  1604. advice.Status = 1
  1605. advice.CreatedTime = time.Now().Unix()
  1606. advice.UpdatedTime = time.Now().Unix()
  1607. advice.StopState = 2
  1608. advice.ExecutionState = 2
  1609. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1610. advice.PatientId = patient
  1611. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1612. // 查询信息规挡的设置天数
  1613. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1614. if infor.ID > 0 && infor.WeekDay > 0 {
  1615. var cha_time int64
  1616. timeNowStr := time.Now().Format("2006-01-02")
  1617. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1618. //今日的日期减去设置的日期
  1619. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1620. if cha_time >= advice.AdviceDate {
  1621. //查询审核是否允许
  1622. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1623. //申请状态不允许的情况 拒绝修改
  1624. if infor.ApplicationStatus != 1 {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1626. return
  1627. }
  1628. }
  1629. }
  1630. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1631. if advice.PrescribingNumber == 0 {
  1632. advice.PrescribingNumber = 1
  1633. }
  1634. //查询该患者今日有没有双人核对
  1635. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1636. if check.ID > 0 {
  1637. advice.Checker = check.Modifier
  1638. advice.CheckState = 1
  1639. advice.CheckTime = time.Now().Unix()
  1640. }
  1641. }
  1642. err := service.CreateDoctorAdvice(&advice)
  1643. //记录日志
  1644. byterequest, _ := json.Marshal(advice)
  1645. adviceLog := models.XtDoctorAdviceLog{
  1646. UserOrgId: advice.UserOrgId,
  1647. PatientId: advice.PatientId,
  1648. AdminUserId: adminUserInfo.AdminUser.Id,
  1649. Module: 1,
  1650. ErrLog: string(byterequest),
  1651. Status: 1,
  1652. Ctime: time.Now().Unix(),
  1653. Mtime: 0,
  1654. Source: "电脑新增医嘱",
  1655. RecordDate: advice.RecordDate,
  1656. }
  1657. service.CreateDoctorAdviceLog(adviceLog)
  1658. //创建步骤表
  1659. finish := models.XtDialysisFinish{
  1660. IsFinish: 1,
  1661. UserOrgId: adminUserInfo.CurrentOrgId,
  1662. Status: 1,
  1663. Ctime: time.Now().Unix(),
  1664. Mtime: 0,
  1665. Module: 4,
  1666. RecordDate: advice.AdviceDate,
  1667. Sourse: 1,
  1668. PatientId: patient,
  1669. }
  1670. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1671. if dialysisFinish.ID == 0 {
  1672. service.CreateDialysisFinish(finish)
  1673. }
  1674. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1675. redis := service.RedisClient()
  1676. defer redis.Close()
  1677. redis.Set(key, "", time.Second)
  1678. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1679. redis.Set(keyOne, "", time.Second)
  1680. if err != nil {
  1681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1682. return
  1683. }
  1684. c.ServeSuccessJSON(map[string]interface{}{
  1685. "msg": "ok",
  1686. "advice": advice,
  1687. })
  1688. return
  1689. }
  1690. func (c *PatientApiController) ExecGroupAdvice() {
  1691. groupNo, _ := c.GetInt64("groupno", 0)
  1692. executionTime := c.GetString("execution_time")
  1693. if groupNo <= 0 {
  1694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1695. return
  1696. }
  1697. if len(executionTime) <= 0 {
  1698. utils.ErrorLog("execution_time")
  1699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1700. return
  1701. }
  1702. adminUserInfo := c.GetAdminUserInfo()
  1703. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1704. if advice.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1706. return
  1707. }
  1708. if advice.ExecutionState == 1 {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1710. return
  1711. }
  1712. executionStaff := adminUserInfo.AdminUser.Id
  1713. // checker := adminUserInfo.AdminUser.Id
  1714. timeLayout := "2006-01-02 15:04:05"
  1715. loc, _ := time.LoadLocation("Local")
  1716. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1717. if err != nil {
  1718. utils.ErrorLog(err.Error())
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1720. return
  1721. }
  1722. if advice.StartTime > theTime.Unix() {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1724. return
  1725. }
  1726. exceAdvice := models.DoctorAdvice{
  1727. ExecutionStaff: executionStaff,
  1728. ExecutionTime: theTime.Unix(),
  1729. UpdatedTime: time.Now().Unix(),
  1730. }
  1731. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1732. if err != nil {
  1733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1734. return
  1735. }
  1736. //查询自动扣减是否开启
  1737. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1738. //查询已经执行的医嘱
  1739. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1740. if drugStockConfig.IsOpen == 1 {
  1741. for _, item := range advicelist {
  1742. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1743. //查询这个患者这个患者这个药已经出库的所有数量
  1744. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1745. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1746. var total_count int64
  1747. var drug_count int64
  1748. for _, it := range advicelist {
  1749. if it.PrescribingNumberUnit == medical.MaxUnit {
  1750. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1751. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1752. total_count += prenumber * medical.MinNumber
  1753. }
  1754. if it.PrescribingNumberUnit == medical.MinUnit {
  1755. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1756. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1757. total_count += prenumber
  1758. }
  1759. }
  1760. for _, its := range drugoutlist {
  1761. if its.CountUnit == medical.MaxUnit {
  1762. drug_count += its.Count * medical.MinNumber
  1763. }
  1764. if its.CountUnit == medical.MinUnit {
  1765. drug_count += its.Count
  1766. }
  1767. }
  1768. if total_count == drug_count {
  1769. c.ServeSuccessJSON(map[string]interface{}{
  1770. "msg": "1",
  1771. "advice": advice,
  1772. })
  1773. return
  1774. }
  1775. var total int64
  1776. var prescribing_number_total int64
  1777. //查询默认出库仓库
  1778. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1779. //查询该药品在默认仓库是否有库存
  1780. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1781. //判断单位是否相等
  1782. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1783. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1784. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1785. //转化为最小单位
  1786. total = list.Count*medical.MinNumber + list.StockMinNumber
  1787. prescribing_number_total = count * medical.MinNumber
  1788. }
  1789. if medical.MinUnit == advice.PrescribingNumberUnit {
  1790. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1791. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1792. total = list.Count*medical.MinNumber + list.StockMinNumber
  1793. prescribing_number_total = count
  1794. }
  1795. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1796. c.ServeSuccessJSON(map[string]interface{}{
  1797. "msg": "3",
  1798. "advice": advice,
  1799. })
  1800. return
  1801. }
  1802. if prescribing_number_total > total {
  1803. c.ServeSuccessJSON(map[string]interface{}{
  1804. "msg": "2",
  1805. "advice": advice,
  1806. })
  1807. return
  1808. }
  1809. if prescribing_number_total <= total {
  1810. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1811. if medical.IsUse == 2 {
  1812. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1813. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1814. if drugOutInfo.ID == 0 {
  1815. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1816. }
  1817. }
  1818. if pharmacyConfig.IsOpen != 1 {
  1819. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1820. if drugOutInfo.ID == 0 {
  1821. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1822. }
  1823. }
  1824. //查询默认仓库
  1825. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1826. //查询默认仓库剩余多少库存
  1827. var sum_count int64
  1828. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1829. for _, its := range stockInfo {
  1830. if its.MaxUnit == medical.MaxUnit {
  1831. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1832. }
  1833. sum_count += its.StockMaxNumber + its.StockMinNumber
  1834. }
  1835. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1836. break
  1837. c.ServeSuccessJSON(map[string]interface{}{
  1838. "msg": "1",
  1839. "advice": advice,
  1840. })
  1841. return
  1842. }
  1843. if medical.IsUse == 1 {
  1844. c.ServeSuccessJSON(map[string]interface{}{
  1845. "msg": "1",
  1846. "advice": advice,
  1847. })
  1848. return
  1849. }
  1850. }
  1851. }
  1852. }
  1853. advice.ExecutionStaff = executionStaff
  1854. advice.ExecutionTime = theTime.Unix()
  1855. c.ServeSuccessJSON(map[string]interface{}{
  1856. "msg": "ok",
  1857. "advice": advice,
  1858. })
  1859. return
  1860. }
  1861. func (c *PatientApiController) ExecDoctorAdvice() {
  1862. origin, _ := c.GetInt64("origin", 0)
  1863. patient, _ := c.GetInt64("patient", 0)
  1864. id, _ := c.GetInt64("id", 0)
  1865. executionTime := c.GetString("execution_time")
  1866. if origin != 2 {
  1867. if id <= 0 || patient <= 0 {
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1869. return
  1870. }
  1871. if len(executionTime) <= 0 {
  1872. utils.ErrorLog("execution_time")
  1873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1874. return
  1875. }
  1876. adminUserInfo := c.GetAdminUserInfo()
  1877. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1878. if advice.ID == 0 || advice.PatientId != patient {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1880. return
  1881. }
  1882. //医嘱已执行
  1883. if advice.ExecutionState == 1 {
  1884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1885. return
  1886. }
  1887. executionStaff := adminUserInfo.AdminUser.Id
  1888. timeLayout := "2006-01-02 15:04:05"
  1889. loc, _ := time.LoadLocation("Local")
  1890. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1891. if err != nil {
  1892. utils.ErrorLog(err.Error())
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. if advice.StartTime > theTime.Unix() {
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. exceAdvice := models.DoctorAdvice{
  1901. ExecutionStaff: executionStaff,
  1902. ExecutionTime: theTime.Unix(),
  1903. UpdatedTime: time.Now().Unix(),
  1904. }
  1905. // 查询信息规挡的设置天数
  1906. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1907. if infor.ID > 0 && infor.WeekDay > 0 {
  1908. var cha_time int64
  1909. timeNowStr := time.Now().Format("2006-01-02")
  1910. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1911. //今日的日期减去设置的日期
  1912. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1913. if cha_time >= advice.AdviceDate {
  1914. //查询审核是否允许
  1915. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1916. //申请状态不允许的情况 拒绝修改
  1917. if infor.ApplicationStatus != 1 {
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1919. return
  1920. }
  1921. }
  1922. }
  1923. if advice.ParentId > 0 {
  1924. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1925. //记录日志
  1926. byterequest, _ := json.Marshal(exceAdvice)
  1927. doctorAdviceLog := models.XtDoctorAdviceLog{
  1928. UserOrgId: exceAdvice.UserOrgId,
  1929. PatientId: exceAdvice.PatientId,
  1930. AdminUserId: adminUserInfo.AdminUser.Id,
  1931. Module: 2,
  1932. ErrLog: string(byterequest),
  1933. Status: 1,
  1934. Ctime: time.Now().Unix(),
  1935. Mtime: 0,
  1936. Source: "电脑端执行医嘱",
  1937. RecordDate: exceAdvice.RecordDate,
  1938. }
  1939. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1940. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1941. redis := service.RedisClient()
  1942. //清空key 值
  1943. redis.Set(key, "", time.Second)
  1944. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1945. redis.Set(keyTwo, "", time.Second)
  1946. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1947. redis.Set(keyThree, "", time.Second)
  1948. theTimes := theTime.Format("2006-01-02")
  1949. fmt.Println("theTIME", theTime)
  1950. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1951. redis.Set(keyFour, "", time.Second)
  1952. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1953. redis.Set(keyFive, "", time.Second)
  1954. defer redis.Close()
  1955. } else {
  1956. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1957. //记录日志
  1958. byterequest, _ := json.Marshal(exceAdvice)
  1959. doctorAdviceLog := models.XtDoctorAdviceLog{
  1960. UserOrgId: exceAdvice.UserOrgId,
  1961. PatientId: exceAdvice.PatientId,
  1962. AdminUserId: adminUserInfo.AdminUser.Id,
  1963. Module: 2,
  1964. ErrLog: string(byterequest),
  1965. Status: 1,
  1966. Ctime: time.Now().Unix(),
  1967. Mtime: 0,
  1968. Source: "电脑端执行医嘱",
  1969. RecordDate: exceAdvice.RecordDate,
  1970. }
  1971. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1972. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1973. redis := service.RedisClient()
  1974. //清空key 值
  1975. redis.Set(key, "", time.Second)
  1976. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1977. redis.Set(keyTwo, "", time.Second)
  1978. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1979. redis.Set(keyThree, "", time.Second)
  1980. theTimes := theTime.Format("2006-01-02")
  1981. fmt.Println("theTIME", theTime)
  1982. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1983. redis.Set(keyFour, "", time.Second)
  1984. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1985. redis.Set(keyFive, "", time.Second)
  1986. defer redis.Close()
  1987. }
  1988. if err != nil {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1990. return
  1991. }
  1992. advice.ExecutionStaff = executionStaff
  1993. advice.ExecutionTime = theTime.Unix()
  1994. //处理出库相关逻辑
  1995. //1.判断是否启用药品管理和自备药出库功能
  1996. //药品管理信息
  1997. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1998. //自备药信息
  1999. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2000. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2001. if drugStockConfig.IsOpen == 1 {
  2002. var total int64
  2003. var prescribing_number_total int64
  2004. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2005. for _, item := range advices {
  2006. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2007. //查询该药品是否有库存
  2008. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2009. //查询改药品信息
  2010. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2011. //判断单位是否相等
  2012. if medical.MaxUnit == item.PrescribingNumberUnit {
  2013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2015. //转化为最小单位
  2016. total = list.Count*medical.MinNumber + list.StockMinNumber
  2017. prescribing_number_total = count * medical.MinNumber
  2018. }
  2019. if medical.MinUnit == item.PrescribingNumberUnit {
  2020. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2021. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2022. total = list.Count*medical.MinNumber + list.StockMinNumber
  2023. prescribing_number_total = count
  2024. }
  2025. if medical.IsUse != 1 {
  2026. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2027. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2028. advice.ExecutionState = 2
  2029. advice.ExecutionStaff = 0
  2030. advice.ExecutionTime = 0
  2031. c.ServeSuccessJSON(map[string]interface{}{
  2032. "msg": "3",
  2033. "advice": advice,
  2034. })
  2035. return
  2036. }
  2037. if prescribing_number_total > total {
  2038. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2039. advice.ExecutionState = 2
  2040. advice.ExecutionStaff = 0
  2041. advice.ExecutionTime = 0
  2042. c.ServeSuccessJSON(map[string]interface{}{
  2043. "msg": "2",
  2044. "advice": advice,
  2045. })
  2046. return
  2047. }
  2048. }
  2049. if medical.IsUse == 1 {
  2050. c.ServeSuccessJSON(map[string]interface{}{
  2051. "msg": "1",
  2052. "advice": advice,
  2053. })
  2054. return
  2055. }
  2056. if prescribing_number_total <= total {
  2057. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2058. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2059. if adviceSetting.IsAdviceOpen == 1 {
  2060. //查询是否出库按钮开启
  2061. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2062. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2063. if prescriptionConfig.IsOpen == 1 {
  2064. if medical.IsUse == 2 {
  2065. //是通过药房发药
  2066. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2067. //执行出库
  2068. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2069. if drugOutInfo.ID == 0 {
  2070. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2071. }
  2072. }
  2073. //不通过药房发药
  2074. if pharmacyConfig.IsOpen != 1 {
  2075. //执行出库
  2076. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2077. if drugOutInfo.ID == 0 {
  2078. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2079. }
  2080. }
  2081. //查询默认仓库
  2082. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2083. //查询默认仓库剩余多少库存
  2084. var sum_count int64
  2085. //更新字典里面的库存
  2086. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2087. for _, its := range stockInfo {
  2088. if its.MaxUnit == medical.MaxUnit {
  2089. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2090. }
  2091. sum_count += its.StockMaxNumber + its.StockMinNumber
  2092. }
  2093. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2094. //剩余库存
  2095. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2096. break
  2097. c.ServeSuccessJSON(map[string]interface{}{
  2098. "msg": "1",
  2099. "advice": advice,
  2100. })
  2101. return
  2102. }
  2103. if medical.IsUse == 1 {
  2104. c.ServeSuccessJSON(map[string]interface{}{
  2105. "msg": "1",
  2106. "advice": advice,
  2107. })
  2108. return
  2109. }
  2110. } else {
  2111. if medical.IsUse == 1 {
  2112. c.ServeSuccessJSON(map[string]interface{}{
  2113. "msg": "1",
  2114. "advice": advice,
  2115. })
  2116. return
  2117. }
  2118. }
  2119. } else {
  2120. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2121. if medical.IsUse == 2 {
  2122. //是通过药房发药
  2123. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2124. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2125. if drugOutInfo.ID == 0 {
  2126. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2127. }
  2128. }
  2129. //不通过药房发药
  2130. if pharmacyConfig.IsOpen != 1 {
  2131. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2132. if drugOutInfo.ID == 0 {
  2133. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2134. }
  2135. }
  2136. //更新字典里面的库存
  2137. var sum_count int64
  2138. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2139. for _, its := range stockInfo {
  2140. if its.MaxUnit == medical.MaxUnit {
  2141. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2142. }
  2143. sum_count += its.StockMaxNumber + its.StockMinNumber
  2144. }
  2145. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2146. //剩余库存
  2147. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2148. break
  2149. c.ServeSuccessJSON(map[string]interface{}{
  2150. "msg": "1",
  2151. "advice": advice,
  2152. })
  2153. return
  2154. }
  2155. if medical.IsUse == 1 {
  2156. c.ServeSuccessJSON(map[string]interface{}{
  2157. "msg": "1",
  2158. "advice": advice,
  2159. })
  2160. return
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2167. for _, item := range advices {
  2168. if item.Way == 2 {
  2169. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2170. if item.ExecutionState == 1 {
  2171. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2172. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2173. timeStr := time.Now().Format("2006-01-02")
  2174. timeArr := strings.Split(timeStr, "-")
  2175. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2176. total = total + 1
  2177. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2178. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2179. number = number + total
  2180. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2181. //插入自备药出库单
  2182. outStock := models.XtSelfOutStock{
  2183. DrugName: item.AdviceName,
  2184. DrugNameId: item.DrugId,
  2185. DrugSpec: item.AdviceDesc,
  2186. OutstoreNumber: count,
  2187. AdminUserId: adminUserInfo.AdminUser.Id,
  2188. StorckTime: item.RecordDate,
  2189. UserOrgId: adminUserInfo.CurrentOrgId,
  2190. CreatedTime: time.Now().Unix(),
  2191. Status: 1,
  2192. PatientId: item.PatientId,
  2193. ExitMode: 2,
  2194. MedicId: item.DrugId,
  2195. StockOutNumber: warehousing_out_order,
  2196. }
  2197. service.CreateOutStock(&outStock)
  2198. }
  2199. }
  2200. }
  2201. }
  2202. c.ServeSuccessJSON(map[string]interface{}{
  2203. "msg": "1",
  2204. "advice": advice,
  2205. })
  2206. return
  2207. } else {
  2208. if id <= 0 || patient <= 0 {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2210. return
  2211. }
  2212. if len(executionTime) <= 0 {
  2213. utils.ErrorLog("execution_time")
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. adminUserInfo := c.GetAdminUserInfo()
  2218. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2219. if advice.ID == 0 || advice.PatientId != patient {
  2220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2221. return
  2222. }
  2223. //医嘱已执行
  2224. if advice.ExecutionState == 1 {
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2226. return
  2227. }
  2228. executionStaff := adminUserInfo.AdminUser.Id
  2229. timeLayout := "2006-01-02 15:04:05"
  2230. loc, _ := time.LoadLocation("Local")
  2231. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2232. if err != nil {
  2233. utils.ErrorLog(err.Error())
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2235. return
  2236. }
  2237. if advice.StartTime > theTime.Unix() {
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. exceAdvice := models.HisDoctorAdviceInfo{
  2242. ExecutionStaff: executionStaff,
  2243. ExecutionTime: theTime.Unix(),
  2244. UpdatedTime: time.Now().Unix(),
  2245. }
  2246. if advice.ParentId > 0 {
  2247. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2248. //记录日志
  2249. byterequest, _ := json.Marshal(exceAdvice)
  2250. doctorAdviceLog := models.XtDoctorAdviceLog{
  2251. UserOrgId: exceAdvice.UserOrgId,
  2252. PatientId: exceAdvice.PatientId,
  2253. AdminUserId: adminUserInfo.AdminUser.Id,
  2254. Module: 2,
  2255. ErrLog: string(byterequest),
  2256. Status: 1,
  2257. Ctime: time.Now().Unix(),
  2258. Mtime: 0,
  2259. Source: "电脑端执行His医嘱",
  2260. RecordDate: exceAdvice.RecordDate,
  2261. }
  2262. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2263. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2264. redis := service.RedisClient()
  2265. //清空key 值
  2266. redis.Set(key, "", time.Second)
  2267. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2268. redis.Set(keyTwo, "", time.Second)
  2269. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2270. redis.Set(keyThree, "", time.Second)
  2271. theTimes := theTime.Format("2006-01-02")
  2272. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2273. redis.Set(keyFour, "", time.Second)
  2274. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2275. redis.Set(keyFive, "", time.Second)
  2276. defer redis.Close()
  2277. } else {
  2278. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2279. //记录日志
  2280. byterequest, _ := json.Marshal(exceAdvice)
  2281. doctorAdviceLog := models.XtDoctorAdviceLog{
  2282. UserOrgId: exceAdvice.UserOrgId,
  2283. PatientId: exceAdvice.PatientId,
  2284. AdminUserId: adminUserInfo.AdminUser.Id,
  2285. Module: 2,
  2286. ErrLog: string(byterequest),
  2287. Status: 1,
  2288. Ctime: time.Now().Unix(),
  2289. Mtime: 0,
  2290. Source: "电脑端执行His医嘱",
  2291. RecordDate: exceAdvice.RecordDate,
  2292. }
  2293. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2294. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2295. redis := service.RedisClient()
  2296. //清空key 值
  2297. redis.Set(key, "", time.Second)
  2298. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2299. redis.Set(keyTwo, "", time.Second)
  2300. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2301. redis.Set(keyThree, "", time.Second)
  2302. theTimes := theTime.Format("2006-01-02")
  2303. fmt.Println("theTIME", theTime)
  2304. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2305. redis.Set(keyFour, "", time.Second)
  2306. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2307. redis.Set(keyFive, "", time.Second)
  2308. defer redis.Close()
  2309. }
  2310. if err != nil {
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2312. return
  2313. }
  2314. advice.ExecutionStaff = executionStaff
  2315. advice.ExecutionTime = theTime.Unix()
  2316. //处理出库相关逻辑
  2317. //1.判断是否启用药品管理和自备药出库功能
  2318. //药品管理信息
  2319. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2320. if drugStockConfig.IsOpen == 1 {
  2321. //查询已经执行的医嘱
  2322. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2323. for _, item := range advices {
  2324. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2325. //查询这个患者这个患者这个药已经出库的所有数量
  2326. //advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2327. //drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2328. //var total_count int64 // 现在出库的
  2329. //var drug_count int64 // 已经出库的
  2330. //for _, it := range advicelist {
  2331. // if it.PrescribingNumberUnit == medical.MaxUnit {
  2332. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2333. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2334. // total_count += prenumber * medical.MinNumber
  2335. // }
  2336. // if it.PrescribingNumberUnit == medical.MinUnit {
  2337. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2338. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2339. // total_count += prenumber
  2340. // }
  2341. //
  2342. //}
  2343. //
  2344. //
  2345. //for _, its := range drugoutlist {
  2346. // if its.CountUnit == medical.MaxUnit {
  2347. // drug_count += its.Count * medical.MinNumber
  2348. // }
  2349. // if its.CountUnit == medical.MinUnit {
  2350. // drug_count += its.Count
  2351. // }
  2352. //}
  2353. //fmt.Println("total_count23232323232323232wode",total_count)
  2354. //fmt.Println("total_count23232323232323232wode",drug_count)
  2355. //if total_count == drug_count {
  2356. // c.ServeSuccessJSON(map[string]interface{}{
  2357. // "msg": "1",
  2358. // "advice": advice,
  2359. // })
  2360. // return
  2361. //}
  2362. var total int64
  2363. var prescribing_number_total int64
  2364. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2365. if config.IsOpen != 1 {
  2366. //查询默认出库仓库
  2367. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2368. //查询该药品在默认仓库是否有库存
  2369. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2370. //判断单位是否相等
  2371. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2372. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2373. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2374. //转化为最小单位
  2375. total = list.Count*medical.MinNumber + list.StockMinNumber
  2376. prescribing_number_total = count * medical.MinNumber
  2377. }
  2378. if medical.MinUnit == advice.PrescribingNumberUnit {
  2379. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2380. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2381. total = list.Count*medical.MinNumber + list.StockMinNumber
  2382. prescribing_number_total = count
  2383. }
  2384. if medical.IsUse == 1 {
  2385. drugError := models.XtDrugError{
  2386. UserOrgId: item.UserOrgId,
  2387. DrugId: item.DrugId,
  2388. RecordDate: item.AdviceDate,
  2389. PatientId: item.PatientId,
  2390. Remark: "电脑端零用药品",
  2391. Status: 1,
  2392. Ctime: time.Now().Unix(),
  2393. Mtime: 0,
  2394. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2395. Prescribingnumber: item.PrescribingNumber,
  2396. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2397. }
  2398. service.CreateDrugError(drugError)
  2399. c.ServeSuccessJSON(map[string]interface{}{
  2400. "msg": "1",
  2401. "advice": advice,
  2402. })
  2403. return
  2404. }
  2405. if medical.IsUse != 1 {
  2406. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2407. drugError := models.XtDrugError{
  2408. UserOrgId: item.UserOrgId,
  2409. DrugId: item.DrugId,
  2410. RecordDate: item.AdviceDate,
  2411. PatientId: item.PatientId,
  2412. Remark: "电脑端药品库存不足",
  2413. Status: 1,
  2414. Ctime: time.Now().Unix(),
  2415. Mtime: 0,
  2416. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2417. Prescribingnumber: item.PrescribingNumber,
  2418. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2419. }
  2420. service.CreateDrugError(drugError)
  2421. c.ServeSuccessJSON(map[string]interface{}{
  2422. "msg": "3",
  2423. "advice": advice,
  2424. })
  2425. return
  2426. }
  2427. if prescribing_number_total > total {
  2428. drugError := models.XtDrugError{
  2429. UserOrgId: item.UserOrgId,
  2430. DrugId: item.DrugId,
  2431. RecordDate: item.AdviceDate,
  2432. PatientId: item.PatientId,
  2433. Remark: "电脑端出库数量大于总库存",
  2434. Status: 1,
  2435. Ctime: time.Now().Unix(),
  2436. Mtime: 0,
  2437. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2438. Prescribingnumber: item.PrescribingNumber,
  2439. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2440. }
  2441. service.CreateDrugError(drugError)
  2442. c.ServeSuccessJSON(map[string]interface{}{
  2443. "msg": "2",
  2444. "advice": advice,
  2445. })
  2446. return
  2447. }
  2448. }
  2449. if prescribing_number_total <= total {
  2450. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2451. if medical.IsUse == 2 {
  2452. if config.IsOpen != 1 {
  2453. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2454. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2455. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2456. //查询该药品是否有出库记录
  2457. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2458. if len(flowMap) == 0 {
  2459. errs := service.UpdateHisAdviceById(item.ID)
  2460. if errs != nil {
  2461. drugError := models.XtDrugError{
  2462. UserOrgId: item.UserOrgId,
  2463. DrugId: item.DrugId,
  2464. RecordDate: item.AdviceDate,
  2465. PatientId: item.PatientId,
  2466. Remark: "出库记录为空,更新执行人失败",
  2467. Status: 1,
  2468. Ctime: time.Now().Unix(),
  2469. Mtime: 0,
  2470. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2471. Prescribingnumber: item.PrescribingNumber,
  2472. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2473. }
  2474. service.CreateDrugError(drugError)
  2475. }
  2476. c.ServeSuccessJSON(map[string]interface{}{
  2477. "msg": "6",
  2478. "advice": advice,
  2479. })
  2480. return
  2481. }
  2482. }
  2483. }
  2484. //不通过药房发药
  2485. if pharmacyConfig.IsOpen != 1 {
  2486. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2487. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2488. //查询该药品是否有出库记录
  2489. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2490. if len(flowMap) == 0 {
  2491. errs := service.UpdateHisAdviceById(item.ID)
  2492. if errs != nil {
  2493. drugError := models.XtDrugError{
  2494. UserOrgId: item.UserOrgId,
  2495. DrugId: item.DrugId,
  2496. RecordDate: item.AdviceDate,
  2497. PatientId: item.PatientId,
  2498. Remark: "出库记录为空,更新执行人失败",
  2499. Status: 1,
  2500. Ctime: time.Now().Unix(),
  2501. Mtime: 0,
  2502. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2503. Prescribingnumber: item.PrescribingNumber,
  2504. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2505. }
  2506. service.CreateDrugError(drugError)
  2507. }
  2508. c.ServeSuccessJSON(map[string]interface{}{
  2509. "msg": "6",
  2510. "advice": advice,
  2511. })
  2512. return
  2513. }
  2514. }
  2515. }
  2516. //查询默认仓库
  2517. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2518. //查询默认仓库剩余多少库存
  2519. var sum_count int64
  2520. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2521. for _, its := range stockInfo {
  2522. if its.MaxUnit == medical.MaxUnit {
  2523. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2524. }
  2525. sum_count += its.StockMaxNumber + its.StockMinNumber
  2526. }
  2527. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2528. //出库数量累加
  2529. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2530. //剩余库存
  2531. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2532. break
  2533. c.ServeSuccessJSON(map[string]interface{}{
  2534. "msg": "1",
  2535. "advice": advice,
  2536. })
  2537. return
  2538. }
  2539. }
  2540. if medical.IsUse == 1 {
  2541. c.ServeSuccessJSON(map[string]interface{}{
  2542. "msg": "1",
  2543. "advice": advice,
  2544. })
  2545. return
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. c.ServeSuccessJSON(map[string]interface{}{
  2552. "msg": "1",
  2553. "advice": advice,
  2554. })
  2555. return
  2556. }
  2557. }
  2558. func (c *PatientApiController) CheckGroupAdvice() {
  2559. groupno, _ := c.GetInt64("groupno", 0)
  2560. if groupno <= 0 {
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2562. return
  2563. }
  2564. adminUserInfo := c.GetAdminUserInfo()
  2565. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2566. if advice.ID == 0 {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2568. return
  2569. }
  2570. if advice.CheckState == 1 {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2572. return
  2573. }
  2574. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2576. return
  2577. }
  2578. checker := adminUserInfo.AdminUser.Id
  2579. theTime := time.Now()
  2580. exceAdvice := models.DoctorAdvice{
  2581. Checker: checker,
  2582. CheckTime: theTime.Unix(),
  2583. UpdatedTime: time.Now().Unix(),
  2584. }
  2585. var err error
  2586. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2587. if err != nil {
  2588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2589. return
  2590. }
  2591. advice.Checker = checker
  2592. advice.CheckTime = theTime.Unix()
  2593. c.ServeSuccessJSON(map[string]interface{}{
  2594. "msg": "ok",
  2595. "advice": advice,
  2596. })
  2597. return
  2598. }
  2599. func (c *PatientApiController) CheckDoctorAdvice() {
  2600. patient, _ := c.GetInt64("patient", 0)
  2601. id, _ := c.GetInt64("id", 0)
  2602. origin, _ := c.GetInt64("origin", 0)
  2603. if origin != 2 {
  2604. // executionTime := c.GetString("execution_time")
  2605. if id <= 0 || patient <= 0 {
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2607. return
  2608. }
  2609. adminUserInfo := c.GetAdminUserInfo()
  2610. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2611. if advice.ID == 0 || advice.PatientId != patient {
  2612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2613. return
  2614. }
  2615. if advice.CheckState == 1 {
  2616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2617. return
  2618. }
  2619. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2621. return
  2622. }
  2623. // executionStaff := adminUserInfo.AdminUser.Id
  2624. checker := adminUserInfo.AdminUser.Id
  2625. // timeLayout := "2006-01-02 15:04:05"
  2626. // loc, _ := time.LoadLocation("Local")
  2627. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2628. // if err != nil {
  2629. // utils.ErrorLog(err.Error())
  2630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2631. // return
  2632. // }
  2633. theTime := time.Now()
  2634. if advice.ExecutionTime > theTime.Unix() {
  2635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2636. return
  2637. }
  2638. exceAdvice := models.DoctorAdvice{
  2639. Checker: checker,
  2640. CheckTime: theTime.Unix(),
  2641. UpdatedTime: time.Now().Unix(),
  2642. }
  2643. var err error
  2644. // 查询信息规挡的设置天数
  2645. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2646. if infor.ID > 0 && infor.WeekDay > 0 {
  2647. var cha_time int64
  2648. timeNowStr := time.Now().Format("2006-01-02")
  2649. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2650. //今日的日期减去设置的日期
  2651. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2652. if cha_time >= advice.AdviceDate {
  2653. //查询审核是否允许
  2654. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2655. //申请状态不允许的情况 拒绝修改
  2656. if infor.ApplicationStatus != 1 {
  2657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2658. return
  2659. }
  2660. }
  2661. }
  2662. if advice.ParentId > 0 {
  2663. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2664. //记录日志
  2665. byterequest, _ := json.Marshal(exceAdvice)
  2666. adviceLog := models.XtDoctorAdviceLog{
  2667. UserOrgId: exceAdvice.UserOrgId,
  2668. PatientId: exceAdvice.PatientId,
  2669. AdminUserId: adminUserInfo.AdminUser.Id,
  2670. Module: 3,
  2671. ErrLog: string(byterequest),
  2672. Status: 1,
  2673. Ctime: time.Now().Unix(),
  2674. Mtime: 0,
  2675. Source: "核对医嘱",
  2676. RecordDate: exceAdvice.AdviceDate,
  2677. }
  2678. service.CreateDoctorAdviceLog(adviceLog)
  2679. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2680. redis := service.RedisClient()
  2681. //清空key 值
  2682. redis.Set(key, "", time.Second)
  2683. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2684. redis.Set(keyTwo, "", time.Second)
  2685. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2686. redis.Set(keyThree, "", time.Second)
  2687. recordDate := theTime.Format("2006-01-02")
  2688. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2689. redis.Set(keyFour, "", time.Second)
  2690. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2691. redis.Set(keyFive, "", time.Second)
  2692. } else {
  2693. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2694. //记录日志
  2695. byterequest, _ := json.Marshal(exceAdvice)
  2696. adviceLog := models.XtDoctorAdviceLog{
  2697. UserOrgId: exceAdvice.UserOrgId,
  2698. PatientId: exceAdvice.PatientId,
  2699. AdminUserId: adminUserInfo.AdminUser.Id,
  2700. Module: 3,
  2701. ErrLog: string(byterequest),
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Source: "核对医嘱",
  2706. RecordDate: exceAdvice.AdviceDate,
  2707. }
  2708. service.CreateDoctorAdviceLog(adviceLog)
  2709. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2710. redis := service.RedisClient()
  2711. //清空key 值
  2712. redis.Set(key, "", time.Second)
  2713. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2714. redis.Set(keyTwo, "", time.Second)
  2715. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2716. redis.Set(keyThree, "", time.Second)
  2717. recordDate := theTime.Format("2006-01-02")
  2718. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2719. redis.Set(keyFour, "", time.Second)
  2720. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2721. redis.Set(keyFive, "", time.Second)
  2722. }
  2723. if err != nil {
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2725. return
  2726. }
  2727. // advice.ExecutionStaff = executionStaff
  2728. // advice.ExecutionTime = theTime.Unix()
  2729. advice.Checker = checker
  2730. advice.CheckTime = theTime.Unix()
  2731. c.ServeSuccessJSON(map[string]interface{}{
  2732. "msg": "ok",
  2733. "advice": advice,
  2734. })
  2735. return
  2736. } else {
  2737. if id <= 0 || patient <= 0 {
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. return
  2740. }
  2741. adminUserInfo := c.GetAdminUserInfo()
  2742. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2743. if advice.ID == 0 || advice.PatientId != patient {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2745. return
  2746. }
  2747. if advice.CheckState == 1 {
  2748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2749. return
  2750. }
  2751. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2753. return
  2754. }
  2755. checker := adminUserInfo.AdminUser.Id
  2756. theTime := time.Now()
  2757. if advice.ExecutionTime > theTime.Unix() {
  2758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2759. return
  2760. }
  2761. exceAdvice := models.HisDoctorAdviceInfo{
  2762. Checker: checker,
  2763. CheckTime: theTime.Unix(),
  2764. UpdatedTime: time.Now().Unix(),
  2765. }
  2766. var err error
  2767. if advice.ParentId > 0 {
  2768. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2769. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2770. redis := service.RedisClient()
  2771. //清空key 值
  2772. redis.Set(key, "", time.Second)
  2773. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2774. redis.Set(keyTwo, "", time.Second)
  2775. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2776. redis.Set(keyThree, "", time.Second)
  2777. recordDate := theTime.Format("2006-01-02")
  2778. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2779. redis.Set(keyFour, "", time.Second)
  2780. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2781. redis.Set(keyFive, "", time.Second)
  2782. } else {
  2783. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2784. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2785. redis := service.RedisClient()
  2786. //清空key 值
  2787. redis.Set(key, "", time.Second)
  2788. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2789. redis.Set(keyTwo, "", time.Second)
  2790. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2791. redis.Set(keyThree, "", time.Second)
  2792. recordDate := theTime.Format("2006-01-02")
  2793. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2794. redis.Set(keyFour, "", time.Second)
  2795. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2796. redis.Set(keyFive, "", time.Second)
  2797. }
  2798. if err != nil {
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2800. return
  2801. }
  2802. // advice.ExecutionStaff = executionStaff
  2803. // advice.ExecutionTime = theTime.Unix()
  2804. advice.Checker = checker
  2805. advice.CheckTime = theTime.Unix()
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "msg": "ok",
  2808. "advice": advice,
  2809. })
  2810. return
  2811. }
  2812. }
  2813. func (c *PatientApiController) UpdateDoctorAdvice() {
  2814. patient, _ := c.GetInt64("patient", 0)
  2815. id, _ := c.GetInt64("id", 0)
  2816. if id <= 0 || patient <= 0 {
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2818. return
  2819. }
  2820. adminUserInfo := c.GetAdminUserInfo()
  2821. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2822. if advice.ID == 0 || advice.PatientId != patient {
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2824. return
  2825. }
  2826. //if advice.AdviceType == 1 {
  2827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2828. // return
  2829. //}
  2830. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  2831. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2833. return
  2834. }
  2835. }
  2836. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2837. //if appRole.UserType == 3 {
  2838. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2839. // if getPermissionErr != nil {
  2840. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2841. // return
  2842. // } else if headNursePermission == nil {
  2843. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2844. // return
  2845. // }
  2846. //}
  2847. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2848. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2849. // return
  2850. //}
  2851. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2852. if code > 0 {
  2853. c.ServeFailJSONWithSGJErrorCode(code)
  2854. return
  2855. }
  2856. advice.UpdatedTime = time.Now().Unix()
  2857. advice.Modifier = adminUserInfo.AdminUser.Id
  2858. // 查询信息规挡的设置天数
  2859. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2860. if infor.ID > 0 && infor.WeekDay > 0 {
  2861. var cha_time int64
  2862. timeNowStr := time.Now().Format("2006-01-02")
  2863. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2864. //今日的日期减去设置的日期
  2865. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2866. if cha_time >= advice.AdviceDate {
  2867. //查询审核是否允许
  2868. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2869. //申请状态不允许的情况 拒绝修改
  2870. if infor.ApplicationStatus != 1 {
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2872. return
  2873. }
  2874. }
  2875. }
  2876. err := service.UpdateDoctorAdvice(&advice)
  2877. //记录日志
  2878. byterequest, _ := json.Marshal(advice)
  2879. doctorAdviceLog := models.XtDoctorAdviceLog{
  2880. UserOrgId: advice.UserOrgId,
  2881. PatientId: advice.PatientId,
  2882. AdminUserId: adminUserInfo.AdminUser.Id,
  2883. Module: 1,
  2884. ErrLog: string(byterequest),
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Source: "电脑端修改医嘱",
  2889. RecordDate: advice.AdviceDate,
  2890. }
  2891. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2892. redis := service.RedisClient()
  2893. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2894. redis.Set(key, "", time.Second)
  2895. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2896. redis.Set(keyOne, "", time.Second)
  2897. defer redis.Close()
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2900. return
  2901. }
  2902. c.ServeSuccessJSON(map[string]interface{}{
  2903. "msg": "ok",
  2904. "advice": advice,
  2905. })
  2906. return
  2907. }
  2908. func (c *PatientApiController) StopGroupAdvice() {
  2909. groupNo, _ := c.GetInt64("groupno", 0)
  2910. if groupNo <= 0 {
  2911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2912. return
  2913. }
  2914. adminUserInfo := c.GetAdminUserInfo()
  2915. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2916. if advice.ID == 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2918. return
  2919. }
  2920. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2922. return
  2923. }
  2924. dataBody := make(map[string]interface{}, 0)
  2925. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2926. if err != nil {
  2927. utils.ErrorLog(err.Error())
  2928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2929. return
  2930. }
  2931. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2932. utils.ErrorLog("stop_time")
  2933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2934. return
  2935. }
  2936. stopTime, _ := dataBody["stop_time"].(string)
  2937. if len(stopTime) == 0 {
  2938. utils.ErrorLog("len(stop_time) == 0")
  2939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2940. return
  2941. }
  2942. timeLayout := "2006-01-02"
  2943. loc, _ := time.LoadLocation("Local")
  2944. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2945. if err != nil {
  2946. utils.ErrorLog(err.Error())
  2947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2948. return
  2949. }
  2950. advice.StopTime = theTime.Unix()
  2951. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2952. stopReason, _ := dataBody["stop_reason"].(string)
  2953. advice.StopReason = stopReason
  2954. }
  2955. advice.UpdatedTime = time.Now().Unix()
  2956. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2957. advice.StopState = 1
  2958. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2959. if err != nil {
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2961. return
  2962. }
  2963. c.ServeSuccessJSON(map[string]interface{}{
  2964. "msg": "ok",
  2965. })
  2966. return
  2967. }
  2968. func (c *PatientApiController) StopDoctorAdvice() {
  2969. id, _ := c.GetInt64("id", 0)
  2970. if id <= 0 {
  2971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2972. return
  2973. }
  2974. adminUserInfo := c.GetAdminUserInfo()
  2975. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2976. //
  2977. //if appRole.UserType == 3 {
  2978. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2979. // if getPermissionErr != nil {
  2980. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2981. // return
  2982. // } else if headNursePermission == nil {
  2983. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2984. // return
  2985. // }
  2986. //}
  2987. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2988. if advice.ID == 0 {
  2989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2990. return
  2991. }
  2992. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2994. return
  2995. }
  2996. dataBody := make(map[string]interface{}, 0)
  2997. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2998. if err != nil {
  2999. utils.ErrorLog(err.Error())
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3001. return
  3002. }
  3003. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3004. utils.ErrorLog("stop_time")
  3005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3006. return
  3007. }
  3008. stopTime, _ := dataBody["stop_time"].(string)
  3009. if len(stopTime) == 0 {
  3010. utils.ErrorLog("len(stop_time) == 0")
  3011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3012. return
  3013. }
  3014. timeLayout := "2006-01-02"
  3015. loc, _ := time.LoadLocation("Local")
  3016. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3017. if err != nil {
  3018. utils.ErrorLog(err.Error())
  3019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3020. return
  3021. }
  3022. advice.StopTime = theTime.Unix()
  3023. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3024. stopReason, _ := dataBody["stop_reason"].(string)
  3025. advice.StopReason = stopReason
  3026. }
  3027. advice.UpdatedTime = time.Now().Unix()
  3028. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3029. advice.StopState = 1
  3030. err = service.StopDoctorAdvice(&advice)
  3031. if err != nil {
  3032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3033. return
  3034. }
  3035. c.ServeSuccessJSON(map[string]interface{}{
  3036. "msg": "ok",
  3037. "advice": advice,
  3038. })
  3039. return
  3040. }
  3041. func (c *PatientApiController) DeleteDoctorAdvice() {
  3042. id, _ := c.GetInt64("id", 0)
  3043. if id <= 0 {
  3044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3045. return
  3046. }
  3047. adminUserInfo := c.GetAdminUserInfo()
  3048. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3049. if advice.ID == 0 {
  3050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3051. return
  3052. }
  3053. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3054. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3055. // return
  3056. //}
  3057. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3058. //
  3059. //if appRole.UserType == 3 {
  3060. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3061. // if getPermissionErr != nil {
  3062. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3063. // return
  3064. // } else if headNursePermission == nil {
  3065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3066. // return
  3067. // }
  3068. //}
  3069. advice.UpdatedTime = time.Now().Unix()
  3070. advice.Status = 0
  3071. advice.Modifier = adminUserInfo.AdminUser.Id
  3072. // 查询信息规挡的设置天数
  3073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3074. if infor.ID > 0 && infor.WeekDay > 0 {
  3075. var cha_time int64
  3076. timeNowStr := time.Now().Format("2006-01-02")
  3077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3078. //今日的日期减去设置的日期
  3079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3080. if cha_time >= advice.AdviceDate {
  3081. //查询审核是否允许
  3082. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3083. //申请状态不允许的情况 拒绝修改
  3084. if infor.ApplicationStatus != 1 {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3086. return
  3087. }
  3088. }
  3089. }
  3090. err := service.DeleteDoctorAdvice(&advice)
  3091. //记录日志
  3092. byterequest, _ := json.Marshal(advice)
  3093. doctorAdviceLog := models.XtDoctorAdviceLog{
  3094. UserOrgId: advice.UserOrgId,
  3095. PatientId: advice.PatientId,
  3096. AdminUserId: adminUserInfo.AdminUser.Id,
  3097. Module: 4,
  3098. ErrLog: string(byterequest),
  3099. Status: 1,
  3100. Ctime: time.Now().Unix(),
  3101. Mtime: 0,
  3102. Source: "电脑端删除医嘱",
  3103. RecordDate: advice.RecordDate,
  3104. }
  3105. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3106. redis := service.RedisClient()
  3107. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3108. redis.Set(keyOne, "", time.Second)
  3109. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3110. redis.Set(key, "", time.Second)
  3111. redis.Close()
  3112. if err != nil {
  3113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3114. return
  3115. }
  3116. c.ServeSuccessJSON(map[string]interface{}{
  3117. "msg": "ok",
  3118. })
  3119. return
  3120. }
  3121. func (c *PatientApiController) DeleteGroupAdvice() {
  3122. groupNo, _ := c.GetInt64("groupno", 0)
  3123. if groupNo <= 0 {
  3124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3125. return
  3126. }
  3127. adminUserInfo := c.GetAdminUserInfo()
  3128. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3129. if advice.ID == 0 {
  3130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3131. return
  3132. }
  3133. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3134. //if appRole.UserType == 3 {
  3135. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3136. // if getPermissionErr != nil {
  3137. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3138. // return
  3139. // } else if headNursePermission == nil {
  3140. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3141. // return
  3142. // }
  3143. //}
  3144. // 查询信息规挡的设置天数
  3145. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3146. if infor.ID > 0 && infor.WeekDay > 0 {
  3147. var cha_time int64
  3148. timeNowStr := time.Now().Format("2006-01-02")
  3149. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3150. //今日的日期减去设置的日期
  3151. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3152. if cha_time >= advice.AdviceDate {
  3153. //查询审核是否允许
  3154. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3155. //申请状态不允许的情况 拒绝修改
  3156. if infor.ApplicationStatus != 1 {
  3157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3158. return
  3159. }
  3160. }
  3161. }
  3162. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3163. byterequest, _ := json.Marshal(advice)
  3164. doctorAdviceLog := models.XtDoctorAdviceLog{
  3165. UserOrgId: advice.UserOrgId,
  3166. PatientId: advice.PatientId,
  3167. AdminUserId: adminUserInfo.AdminUser.Id,
  3168. Module: 4,
  3169. ErrLog: string(byterequest),
  3170. Status: 1,
  3171. Ctime: time.Now().Unix(),
  3172. Mtime: 0,
  3173. Source: "电脑端批量删除医嘱",
  3174. RecordDate: advice.RecordDate,
  3175. }
  3176. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3177. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3178. redis := service.RedisClient()
  3179. redis.Set(key, "", time.Second)
  3180. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3181. redis.Set(keyOne, "", time.Second)
  3182. defer redis.Close()
  3183. if err != nil {
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3185. return
  3186. }
  3187. c.ServeSuccessJSON(map[string]interface{}{
  3188. "msg": "ok",
  3189. })
  3190. return
  3191. }
  3192. // GetDoctorAdvices 医嘱列表
  3193. func (c *PatientApiController) GetDoctorAdvices() {
  3194. id, _ := c.GetInt64("id", 0)
  3195. adviceType, _ := c.GetInt64("advice_type", 0)
  3196. stopType, _ := c.GetInt64("stop_state", 0)
  3197. startTime := c.GetString("start_time", "")
  3198. endTime := c.GetString("end_time", "")
  3199. keywords := c.GetString("keywords", "")
  3200. page, _ := c.GetInt64("page")
  3201. fmt.Println("page", page)
  3202. limit, _ := c.GetInt64("limit")
  3203. fmt.Println("limit", limit)
  3204. adminUserInfo := c.GetAdminUserInfo()
  3205. operatorIDs := make([]int64, 0)
  3206. timeLayout := "2006-01-02"
  3207. loc, _ := time.LoadLocation("Local")
  3208. var theStartTIme int64
  3209. if len(startTime) > 0 {
  3210. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3211. if err != nil {
  3212. utils.ErrorLog(err.Error())
  3213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3214. return
  3215. }
  3216. theStartTIme = theTime.Unix()
  3217. }
  3218. var theEndtTIme int64
  3219. if len(endTime) > 0 {
  3220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3221. if err != nil {
  3222. utils.ErrorLog(err.Error())
  3223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3224. return
  3225. }
  3226. theEndtTIme = theTime.Unix()
  3227. }
  3228. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3229. if hisconfig.IsOpen == 1 {
  3230. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3231. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3232. if len(advices) > 0 {
  3233. for _, item := range advices {
  3234. if item.AdviceDoctor > 0 {
  3235. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3236. }
  3237. if item.ExecutionStaff > 0 {
  3238. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3239. }
  3240. if item.Checker > 0 {
  3241. operatorIDs = append(operatorIDs, item.Checker)
  3242. }
  3243. if item.StopDoctor > 0 {
  3244. operatorIDs = append(operatorIDs, item.StopDoctor)
  3245. }
  3246. }
  3247. }
  3248. //相关操作对应的操作人
  3249. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3250. //获取长期医嘱
  3251. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3252. c.ServeSuccessJSON(map[string]interface{}{
  3253. "advices": advices,
  3254. "operators": operators,
  3255. "total": total,
  3256. "advicetwo": advicestwo,
  3257. "longAdvice": longAdvice,
  3258. "is_open": hisconfig.IsOpen,
  3259. })
  3260. return
  3261. } else {
  3262. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3263. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3264. if len(advices) > 0 {
  3265. for _, item := range advices {
  3266. if item.AdviceDoctor > 0 {
  3267. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3268. }
  3269. if item.ExecutionStaff > 0 {
  3270. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3271. }
  3272. if item.Checker > 0 {
  3273. operatorIDs = append(operatorIDs, item.Checker)
  3274. }
  3275. if item.StopDoctor > 0 {
  3276. operatorIDs = append(operatorIDs, item.StopDoctor)
  3277. }
  3278. }
  3279. }
  3280. //相关操作对应的操作人
  3281. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3282. c.ServeSuccessJSON(map[string]interface{}{
  3283. "advices": advices,
  3284. "operators": operators,
  3285. "total": total,
  3286. "advicetwo": advicestwo,
  3287. "is_open": hisconfig.IsOpen,
  3288. })
  3289. return
  3290. }
  3291. }
  3292. func (c *PatientApiController) GetPatientSchedules() {
  3293. id, _ := c.GetInt64("id", 0)
  3294. if id <= 0 {
  3295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3296. return
  3297. }
  3298. adminUserInfo := c.GetAdminUserInfo()
  3299. todayTime := time.Now().Format("2006-01-02")
  3300. timeLayout := "2006-01-02 15:04:05"
  3301. loc, _ := time.LoadLocation("Local")
  3302. var theStartTime int64
  3303. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3304. theStartTime = theTime.Unix()
  3305. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3306. if len(schedules) > 0 {
  3307. for index, item := range schedules {
  3308. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3309. schedules[index].Week = int64(week)
  3310. }
  3311. }
  3312. c.ServeSuccessJSON(map[string]interface{}{
  3313. "schedules": schedules,
  3314. })
  3315. return
  3316. }
  3317. func (c *PatientApiController) GetPatientDialysisRecords() {
  3318. patientID, _ := c.GetInt64("patient_id", 0)
  3319. page, _ := c.GetInt64("page", 0)
  3320. limit, _ := c.GetInt64("limit", 0)
  3321. startTime := c.GetString("start_time", "")
  3322. endTime := c.GetString("end_time", "")
  3323. mode_id, _ := c.GetInt64("mode_id", 0)
  3324. if page <= 0 {
  3325. page = 1
  3326. }
  3327. if limit <= 0 {
  3328. limit = 10
  3329. }
  3330. if patientID <= 0 {
  3331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3332. return
  3333. }
  3334. timeLayout := "2006-01-02"
  3335. loc, _ := time.LoadLocation("Local")
  3336. var theStartTIme int64
  3337. if len(startTime) > 0 {
  3338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3339. if err != nil {
  3340. theStartTIme = 0
  3341. }
  3342. theStartTIme = theTime.Unix()
  3343. }
  3344. var theEndtTIme int64
  3345. if len(endTime) > 0 {
  3346. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3347. if err != nil {
  3348. theEndtTIme = 0
  3349. }
  3350. theEndtTIme = theTime.Unix()
  3351. }
  3352. adminInfo := c.GetAdminUserInfo()
  3353. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3354. c.ServeSuccessJSON(map[string]interface{}{
  3355. "total": total,
  3356. "records": records,
  3357. })
  3358. return
  3359. }
  3360. func (c *PatientApiController) ProEducation() {
  3361. patientID, _ := c.GetInt64("patient_id", 0)
  3362. page, _ := c.GetInt64("page", 0)
  3363. limit, _ := c.GetInt64("limit", 0)
  3364. startTime := c.GetString("start_time", "")
  3365. endTime := c.GetString("end_time", "")
  3366. if page <= 0 {
  3367. page = 1
  3368. }
  3369. if limit <= 0 {
  3370. limit = 10
  3371. }
  3372. if patientID <= 0 {
  3373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3374. return
  3375. }
  3376. timeLayout := "2006-01-02"
  3377. loc, _ := time.LoadLocation("Local")
  3378. var theStartTIme int64
  3379. if len(startTime) > 0 {
  3380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3381. if err != nil {
  3382. theStartTIme = 0
  3383. }
  3384. theStartTIme = theTime.Unix()
  3385. }
  3386. var theEndtTIme int64
  3387. if len(endTime) > 0 {
  3388. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3389. if err != nil {
  3390. theEndtTIme = 0
  3391. }
  3392. theEndtTIme = theTime.Unix()
  3393. }
  3394. adminInfo := c.GetAdminUserInfo()
  3395. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3396. c.ServeSuccessJSON(map[string]interface{}{
  3397. "total": total,
  3398. "edus": edus,
  3399. })
  3400. return
  3401. }
  3402. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3403. dataBody := make(map[string]interface{}, 0)
  3404. err := json.Unmarshal(data, &dataBody)
  3405. if err != nil {
  3406. utils.ErrorLog(err.Error())
  3407. code = enums.ErrorCodeParamWrong
  3408. return
  3409. }
  3410. timeLayout := "2006-01-02"
  3411. loc, _ := time.LoadLocation("Local")
  3412. isChild := false
  3413. if action == "create" {
  3414. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3415. utils.ErrorLog("advice_type")
  3416. code = enums.ErrorCodeParamWrong
  3417. return
  3418. }
  3419. adviceType := int64(dataBody["advice_type"].(float64))
  3420. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3421. utils.ErrorLog("advice_type != 1&&2")
  3422. code = enums.ErrorCodeParamWrong
  3423. return
  3424. }
  3425. advice.AdviceType = adviceType
  3426. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3427. utils.ErrorLog("advice_date")
  3428. code = enums.ErrorCodeParamWrong
  3429. return
  3430. }
  3431. adviceDate, _ := dataBody["advice_date"].(string)
  3432. if len(adviceDate) == 0 {
  3433. utils.ErrorLog("len(adviceDate) == 0")
  3434. code = enums.ErrorCodeParamWrong
  3435. return
  3436. }
  3437. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3438. if err != nil {
  3439. utils.ErrorLog(err.Error())
  3440. code = enums.ErrorCodeParamWrong
  3441. return
  3442. }
  3443. advice.AdviceDate = theTime.Unix()
  3444. advice.RecordDate = theTime.Unix()
  3445. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3446. parentId := int64(dataBody["parent_id"].(float64))
  3447. advice.ParentId = parentId
  3448. if parentId > 0 {
  3449. isChild = true
  3450. }
  3451. }
  3452. }
  3453. if !isChild {
  3454. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3455. utils.ErrorLog("start_time")
  3456. code = enums.ErrorCodeParamWrong
  3457. return
  3458. }
  3459. startTime, _ := dataBody["start_time"].(string)
  3460. if len(startTime) == 0 {
  3461. utils.ErrorLog("len(start_time) == 0")
  3462. code = enums.ErrorCodeParamWrong
  3463. return
  3464. }
  3465. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3466. if err != nil {
  3467. utils.ErrorLog(err.Error())
  3468. code = enums.ErrorCodeParamWrong
  3469. return
  3470. }
  3471. advice.StartTime = theTime.Unix()
  3472. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3473. // utils.ErrorLog("advice_doctor")
  3474. // code = enums.ErrorCodeParamWrong
  3475. // return
  3476. // }
  3477. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3478. // if adviceDoctor <= 0 {
  3479. // utils.ErrorLog("advice_doctor <=0")
  3480. // code = enums.ErrorCodeParamWrong
  3481. // return
  3482. // }
  3483. // advice.AdviceDoctor = adviceDoctor
  3484. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3485. deliveryWay, _ := dataBody["delivery_way"].(string)
  3486. advice.DeliveryWay = deliveryWay
  3487. }
  3488. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3489. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3490. advice.ExecutionFrequency = executionFrequency
  3491. }
  3492. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3493. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3494. frequency_type := int64(dataBody["frequency_type"].(float64))
  3495. advice.FrequencyType = frequency_type
  3496. }
  3497. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3498. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3499. advice.DayCount = day_count
  3500. }
  3501. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3502. week_day, _ := dataBody["week_days"].(string)
  3503. advice.WeekDay = week_day
  3504. }
  3505. }
  3506. }
  3507. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3508. utils.ErrorLog("advice_name")
  3509. code = enums.ErrorCodeParamWrong
  3510. return
  3511. }
  3512. adviceName, _ := dataBody["advice_name"].(string)
  3513. if len(adviceName) == 0 {
  3514. utils.ErrorLog("len(advice_name) == 0")
  3515. code = enums.ErrorCodeParamWrong
  3516. return
  3517. }
  3518. advice.AdviceName = adviceName
  3519. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3520. adviceDsc, _ := dataBody["advice_desc"].(string)
  3521. advice.AdviceDesc = adviceDsc
  3522. }
  3523. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3524. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3525. advice.DialysisOrderId = int64(dialysisOrderId)
  3526. }
  3527. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3528. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3529. advice.SingleDose = singleDose
  3530. }
  3531. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3532. singleDose := dataBody["single_dose"].(float64)
  3533. advice.SingleDose = singleDose
  3534. }
  3535. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3536. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3537. advice.SingleDoseUnit = singleDoseUnit
  3538. }
  3539. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3540. tmp := dataBody["single_dose_unit"].(float64)
  3541. singleDoseUnit := service.TypeConversion(tmp)
  3542. advice.SingleDoseUnit = singleDoseUnit
  3543. }
  3544. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3545. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3546. advice.DrugSpec = drugSpec
  3547. }
  3548. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3549. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3550. advice.DrugSpecUnit = drugSpecUnit
  3551. }
  3552. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3553. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3554. advice.PrescribingNumber = prescribingNumber
  3555. }
  3556. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3557. prescribingNumber := dataBody["prescribing_number"].(float64)
  3558. advice.PrescribingNumber = prescribingNumber
  3559. }
  3560. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3561. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3562. advice.PrescribingNumberUnit = prescribingNumberUnit
  3563. }
  3564. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3565. remark, _ := dataBody["remark"].(string)
  3566. advice.Remark = remark
  3567. }
  3568. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3569. drug_id, _ := dataBody["drug_id"].(string)
  3570. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3571. advice.DrugId = tmpDrugId
  3572. }
  3573. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3574. drug_id, _ := dataBody["drug_id"].(float64)
  3575. advice.DrugId = int64(drug_id)
  3576. }
  3577. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3578. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3579. advice.DrugNameId = int64(drug_name_id)
  3580. }
  3581. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3582. way, _ := dataBody["way"].(float64)
  3583. advice.Way = int64(way)
  3584. }
  3585. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3586. push_start_time, _ := dataBody["push_start_time"].(string)
  3587. var startTime int64
  3588. if len(push_start_time) > 0 {
  3589. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3590. startTime = theTime.Unix()
  3591. }
  3592. advice.PushStartTime = startTime
  3593. }
  3594. return
  3595. }
  3596. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3597. dataBody := make(map[string]interface{}, 0)
  3598. err := json.Unmarshal(data, &dataBody)
  3599. utils.InfoLog(string(data))
  3600. if err != nil {
  3601. utils.ErrorLog(err.Error())
  3602. code = enums.ErrorCodeParamWrong
  3603. return
  3604. }
  3605. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3606. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3607. solution.DialysisDuration = dialysisDuration
  3608. }
  3609. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3610. replacementWay := int64(dataBody["replacement_way"].(float64))
  3611. solution.ReplacementWay = replacementWay
  3612. }
  3613. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3614. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3615. solution.BloodFlowVolume = bloodFlowVolume
  3616. }
  3617. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3618. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3619. solution.HemodialysisMachine = hemodialysisMachine
  3620. }
  3621. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3622. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3623. solution.BloodFilter = bloodFilter
  3624. }
  3625. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3626. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3627. solution.PerfusionApparatus = perfusionApparatus
  3628. }
  3629. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3630. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3631. solution.DialysateFlow = dialysateFlow
  3632. }
  3633. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3634. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3635. solution.Kalium = kalium
  3636. }
  3637. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3638. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3639. solution.Sodium = sodium
  3640. }
  3641. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3642. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3643. solution.Calcium = calcium
  3644. }
  3645. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3646. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3647. solution.Bicarbonate = bicarbonate
  3648. }
  3649. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3650. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3651. solution.Anticoagulant = anticoagulant
  3652. }
  3653. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3654. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3655. solution.AnticoagulantShouji = anticoagulantShouji
  3656. }
  3657. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3658. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3659. solution.AnticoagulantWeichi = anticoagulantWeichi
  3660. }
  3661. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3662. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3663. solution.AnticoagulantZongliang = anticoagulantZongliang
  3664. }
  3665. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3666. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3667. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3668. }
  3669. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3670. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3671. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3672. }
  3673. return
  3674. }
  3675. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3676. dataBody := make(map[string]interface{}, 0)
  3677. err := json.Unmarshal(data, &dataBody)
  3678. utils.InfoLog(string(data))
  3679. if err != nil {
  3680. utils.ErrorLog(err.Error())
  3681. code = enums.ErrorCodeParamWrong
  3682. return
  3683. }
  3684. if method == "create" {
  3685. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3686. utils.ErrorLog("mode")
  3687. code = enums.ErrorCodeParamWrong
  3688. return
  3689. }
  3690. mode := int64(dataBody["mode"].(float64))
  3691. if mode <= 0 {
  3692. utils.ErrorLog("mode <= 0")
  3693. code = enums.ErrorCodeParamWrong
  3694. return
  3695. }
  3696. solution.ModeId = mode
  3697. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3698. utils.ErrorLog("mode_name")
  3699. code = enums.ErrorCodeParamWrong
  3700. return
  3701. }
  3702. modeName, _ := dataBody["mode_name"].(string)
  3703. if len(modeName) == 0 {
  3704. utils.ErrorLog("len(mode_name) == 0")
  3705. code = enums.ErrorCodeParamWrong
  3706. return
  3707. }
  3708. solution.ModeName = modeName
  3709. solution.Name = modeName
  3710. }
  3711. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3712. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3713. solution.DialysisDuration = dialysisDuration
  3714. }
  3715. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3716. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3717. solution.TargetUltrafiltration = targetUltrafiltration
  3718. }
  3719. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3720. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3721. solution.DialysateFormulation = dialysateFormulation
  3722. }
  3723. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3724. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3725. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3726. }
  3727. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3728. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3729. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3730. }
  3731. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3732. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3733. solution.HemodialysisMachine = hemodialysisMachine
  3734. }
  3735. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3736. dialyzer := int64(dataBody["dialyzer"].(float64))
  3737. solution.Dialyzer = dialyzer
  3738. }
  3739. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3740. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3741. solution.PerfusionApparatus = perfusionApparatus
  3742. }
  3743. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3744. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3745. solution.BloodFlowVolume = bloodFlowVolume
  3746. }
  3747. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3748. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3749. solution.Dewater = dewater
  3750. }
  3751. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3752. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3753. solution.DisplaceLiqui = displaceLiqui
  3754. }
  3755. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3756. replacementWay := int64(dataBody["replacement_way"].(float64))
  3757. solution.ReplacementWay = replacementWay
  3758. }
  3759. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3760. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3761. solution.Anticoagulant = anticoagulant
  3762. }
  3763. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3764. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3765. solution.AnticoagulantShouji = anticoagulantShouji
  3766. }
  3767. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3768. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3769. solution.AnticoagulantWeichi = anticoagulantWeichi
  3770. }
  3771. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3772. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3773. solution.AnticoagulantZongliang = anticoagulantZongliang
  3774. }
  3775. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3776. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3777. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3778. }
  3779. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3780. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3781. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3782. }
  3783. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3784. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3785. solution.Kalium = kalium
  3786. }
  3787. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3788. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3789. solution.Sodium = sodium
  3790. }
  3791. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3792. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3793. solution.Calcium = calcium
  3794. }
  3795. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3796. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3797. solution.Bicarbonate = bicarbonate
  3798. }
  3799. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3800. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3801. solution.Glucose = glucose
  3802. }
  3803. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3804. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3805. // solution.DryWeight = dryWeight
  3806. // }
  3807. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3808. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3809. solution.DialysateFlow = dialysateFlow
  3810. }
  3811. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3812. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3813. solution.DialysateTemperature = dialysateTemperature
  3814. }
  3815. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3816. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3817. solution.Conductivity = conductivity
  3818. }
  3819. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3820. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3821. solution.ReplacementTotal = replacementTotal
  3822. }
  3823. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3824. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3825. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3826. }
  3827. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3828. body_fluid := int64(dataBody["body_fluid"].(float64))
  3829. solution.BodyFluid = body_fluid
  3830. }
  3831. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3832. body_fluid_other := dataBody["body_fluid_other"].(string)
  3833. solution.BodyFluidOther = body_fluid_other
  3834. }
  3835. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3836. special_medicine := int64(dataBody["special_medicine"].(float64))
  3837. solution.SpecialMedicine = special_medicine
  3838. }
  3839. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3840. special_medicine_other := dataBody["special_medicine_other"].(string)
  3841. solution.SpecialMedicineOther = special_medicine_other
  3842. }
  3843. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3844. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3845. solution.DisplaceLiquiPart = displace_liqui_part
  3846. }
  3847. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3848. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3849. solution.DisplaceLiquiValue = displace_liqui_value
  3850. }
  3851. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3852. blood_access := int64(dataBody["blood_access"].(float64))
  3853. solution.BloodAccess = blood_access
  3854. }
  3855. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3856. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3857. solution.Ultrafiltration = ultrafiltration
  3858. }
  3859. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3860. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3861. solution.TargetKtv = target_ktv
  3862. }
  3863. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3864. remark := dataBody["remark"].(string)
  3865. solution.Remark = remark
  3866. }
  3867. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3868. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3869. solution.HemodialysisPipelines = hemodialysis_pipelines
  3870. }
  3871. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3872. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3873. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3874. }
  3875. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3876. puncture_needle := dataBody["puncture_needle"].(string)
  3877. solution.PunctureNeedle = puncture_needle
  3878. }
  3879. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3880. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3881. solution.PunctureNeedleCount = puncture_needle_count
  3882. }
  3883. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3884. epo := dataBody["epo"].(string)
  3885. solution.Epo = epo
  3886. }
  3887. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3888. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3889. solution.EpoCount = epo_count
  3890. }
  3891. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3892. created_time := int64(dataBody["created_time"].(float64))
  3893. solution.CreatedTime = created_time
  3894. }
  3895. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3896. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3897. solution.DialysisDialyszers = dialysisDialyszers
  3898. }
  3899. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3900. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3901. solution.DialysisIrrigation = dialysisIrrigation
  3902. }
  3903. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3904. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3905. solution.DialysisStrainer = dialysis_strainer
  3906. }
  3907. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3908. plasmaSeparator := dataBody["plasma_separator"].(string)
  3909. solution.PlasmaSeparator = plasmaSeparator
  3910. }
  3911. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3912. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3913. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3914. }
  3915. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3916. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3917. solution.OxygenUptake = oxygen_uptake
  3918. }
  3919. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3920. oxygen_flow := dataBody["oxygen_flow"].(string)
  3921. solution.OxygenFlow = oxygen_flow
  3922. }
  3923. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3924. oxygen_time := dataBody["oxygen_time"].(string)
  3925. solution.OxygenTime = oxygen_time
  3926. }
  3927. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3928. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3929. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3930. }
  3931. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3932. amylaceum := dataBody["amylaceum"].(string)
  3933. solution.Amylaceum = amylaceum
  3934. }
  3935. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  3936. chaptalization := dataBody["chaptalization"].(string)
  3937. solution.Chaptalization = chaptalization
  3938. }
  3939. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3940. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3941. solution.BloodAccessPartId = blood_access_part_id
  3942. }
  3943. return
  3944. }
  3945. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3946. dataBody := make(map[string]interface{}, 0)
  3947. err := json.Unmarshal(data, &dataBody)
  3948. utils.InfoLog(string(data))
  3949. if err != nil {
  3950. utils.ErrorLog(err.Error())
  3951. code = enums.ErrorCodeParamWrong
  3952. return
  3953. }
  3954. if method == "create" {
  3955. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3956. utils.ErrorLog("parent_id")
  3957. code = enums.ErrorCodeParamWrong
  3958. return
  3959. }
  3960. parentID := int64(dataBody["parent_id"].(float64))
  3961. if parentID <= 0 {
  3962. utils.ErrorLog("parentID <= 0")
  3963. code = enums.ErrorCodeParamWrong
  3964. return
  3965. }
  3966. solution.ParentId = parentID
  3967. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3968. utils.ErrorLog("sub_name")
  3969. code = enums.ErrorCodeParamWrong
  3970. return
  3971. }
  3972. subName, _ := dataBody["sub_name"].(string)
  3973. if len(subName) == 0 {
  3974. utils.ErrorLog("len(sub_name) == 0")
  3975. code = enums.ErrorCodeParamWrong
  3976. return
  3977. }
  3978. solution.SubName = subName
  3979. }
  3980. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  3981. utils.ErrorLog("initiate_mode")
  3982. code = enums.ErrorCodeParamWrong
  3983. return
  3984. }
  3985. initiateMode := int64(dataBody["initiate_mode"].(float64))
  3986. if initiateMode != 1 && initiateMode != 2 {
  3987. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  3988. code = enums.ErrorCodeParamWrong
  3989. return
  3990. }
  3991. solution.InitiateMode = initiateMode
  3992. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3993. utils.ErrorLog("doctor")
  3994. code = enums.ErrorCodeParamWrong
  3995. return
  3996. }
  3997. doctor := int64(dataBody["doctor"].(float64))
  3998. if doctor <= 0 {
  3999. utils.ErrorLog("doctor <= 0")
  4000. code = enums.ErrorCodeParamWrong
  4001. return
  4002. }
  4003. solution.Doctor = doctor
  4004. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4005. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4006. solution.BloodAccessPartId = blood_access_part_id
  4007. }
  4008. return
  4009. }
  4010. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4011. patientBody := make(map[string]interface{}, 0)
  4012. err := json.Unmarshal(data, &patientBody)
  4013. if err != nil {
  4014. utils.ErrorLog(err.Error())
  4015. code = enums.ErrorCodeParamWrong
  4016. return
  4017. }
  4018. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4019. formItem, _ := patientBody["formItem"].([]interface{})
  4020. if len(formItem) > 0 {
  4021. for _, item := range formItem {
  4022. items := item.(map[string]interface{})
  4023. project_name, _ := items["project_name"].(string)
  4024. fmt.Println(project_name)
  4025. range_type := int64(items["range_type"].(float64))
  4026. fmt.Println(range_type)
  4027. project_id := int64(items["project_id"].(float64))
  4028. fmt.Println(project_id)
  4029. item_id := int64(items["item_id"].(float64))
  4030. fmt.Println(item_id)
  4031. item, _ := items["item"].(string)
  4032. fmt.Println(items["item"].(string))
  4033. item_name, _ := items["item_name"].(string)
  4034. fmt.Println(item_name)
  4035. value, _ := items["value"].(string)
  4036. fmt.Println(items["value"].(string))
  4037. var form models.FormItem
  4038. form.ProjectName = project_name
  4039. form.RangeType = range_type
  4040. form.ProjectId = project_id
  4041. form.ItemId = item_id
  4042. form.Item = item
  4043. form.ItemName = item_name
  4044. form.Value = value
  4045. formItems = append(formItems, &form)
  4046. }
  4047. }
  4048. }
  4049. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4050. utils.ErrorLog("avatar")
  4051. code = enums.ErrorCodeParamWrong
  4052. return
  4053. }
  4054. avatar, _ := patientBody["avatar"].(string)
  4055. if len(avatar) == 0 {
  4056. utils.ErrorLog("len(avatar) == 0")
  4057. code = enums.ErrorCodeParamWrong
  4058. return
  4059. }
  4060. patient.Avatar = avatar
  4061. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4062. utils.ErrorLog("name")
  4063. code = enums.ErrorCodeParamWrong
  4064. return
  4065. }
  4066. name, _ := patientBody["name"].(string)
  4067. if len(name) == 0 {
  4068. utils.ErrorLog("len(name) == 0")
  4069. code = enums.ErrorCodeParamWrong
  4070. return
  4071. }
  4072. patient.Name = name
  4073. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4074. alias := patientBody["alias"].(string)
  4075. patient.Alias = alias
  4076. }
  4077. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4078. nation := patientBody["nation"].(string)
  4079. patient.Nation = nation
  4080. }
  4081. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4082. native_place := patientBody["native_place"].(string)
  4083. patient.NativePlace = native_place
  4084. }
  4085. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4086. utils.ErrorLog("idCardNo")
  4087. code = enums.ErrorCodeParamWrong
  4088. return
  4089. }
  4090. idCardNo, _ := patientBody["idCardNo"].(string)
  4091. if len(idCardNo) == 0 {
  4092. utils.ErrorLog("len(idCardNo) == 0")
  4093. code = enums.ErrorCodeParamWrong
  4094. return
  4095. }
  4096. patient.IdCardNo = idCardNo
  4097. patient.PatientType = 1
  4098. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4099. utils.ErrorLog("dialysisNo")
  4100. code = enums.ErrorCodeParamWrong
  4101. return
  4102. }
  4103. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4104. if len(dialysisNo) == 0 {
  4105. utils.ErrorLog("len(dialysisNo) == 0")
  4106. code = enums.ErrorCodeParamWrong
  4107. return
  4108. }
  4109. patient.DialysisNo = dialysisNo
  4110. // }
  4111. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4112. utils.ErrorLog("lapseto")
  4113. code = enums.ErrorCodeParamWrong
  4114. return
  4115. }
  4116. lapseto := int64(patientBody["lapseto"].(float64))
  4117. if lapseto <= 0 {
  4118. utils.ErrorLog("lapseto == 0")
  4119. code = enums.ErrorCodeParamWrong
  4120. return
  4121. }
  4122. patient.Lapseto = lapseto
  4123. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4124. utils.ErrorLog("gender")
  4125. code = enums.ErrorCodeParamWrong
  4126. return
  4127. }
  4128. gender := int64(patientBody["gender"].(float64))
  4129. if gender <= 0 {
  4130. utils.ErrorLog("gender <= 0")
  4131. code = enums.ErrorCodeParamWrong
  4132. return
  4133. }
  4134. patient.Gender = gender
  4135. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4136. response_result := patientBody["response_result"].(string)
  4137. patient.ResponseResult = response_result
  4138. }
  4139. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4140. utils.ErrorLog("age")
  4141. code = enums.ErrorCodeParamWrong
  4142. return
  4143. }
  4144. age := int64(patientBody["age"].(float64))
  4145. patient.Age = age
  4146. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4147. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4148. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4149. patient.UserSysBeforeCount = count
  4150. }
  4151. timeLayout := "2006-01-02"
  4152. loc, _ := time.LoadLocation("Local")
  4153. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4154. utils.ErrorLog("birth")
  4155. code = enums.ErrorCodeParamWrong
  4156. return
  4157. }
  4158. birth, _ := patientBody["birth"].(string)
  4159. if len(birth) == 0 {
  4160. utils.ErrorLog("len(birth) == 0")
  4161. code = enums.ErrorCodeParamWrong
  4162. return
  4163. }
  4164. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4165. if err != nil {
  4166. utils.ErrorLog("birthTime")
  4167. code = enums.ErrorCodeParamWrong
  4168. return
  4169. }
  4170. patient.Birthday = birthTime.Unix()
  4171. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4172. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4173. patient.Height = height
  4174. }
  4175. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4176. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4177. patient.MaritalStatus = maritalStatus
  4178. }
  4179. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4180. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4181. patient.Children = children
  4182. }
  4183. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4184. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4185. patient.AdmissionNumber = admissionNumber
  4186. }
  4187. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4188. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4189. patient.ReimbursementWayId = reimbursementWayID
  4190. }
  4191. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4192. healthCareNo := patientBody["healthCareNo"].(string)
  4193. patient.HealthCareNo = healthCareNo
  4194. }
  4195. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4196. utils.ErrorLog("phone")
  4197. code = enums.ErrorCodeParamWrong
  4198. return
  4199. }
  4200. phone := patientBody["phone"].(string)
  4201. if len(phone) == 0 {
  4202. utils.ErrorLog("len(phone) == 0")
  4203. code = enums.ErrorCodeParamWrong
  4204. return
  4205. }
  4206. if !utils.CheckMobile(phone) {
  4207. utils.ErrorLog("!phone")
  4208. code = enums.ErrorCodeMobileFormat
  4209. return
  4210. }
  4211. patient.Phone = phone
  4212. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4213. homeTelephone := patientBody["homeTelephone"].(string)
  4214. patient.HomeTelephone = homeTelephone
  4215. }
  4216. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4217. relativePhone := patientBody["relative_phone"].(string)
  4218. patient.RelativePhone = relativePhone
  4219. }
  4220. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4221. relativeRelations := patientBody["relative_relations"].(string)
  4222. patient.RelativeRelations = relativeRelations
  4223. }
  4224. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4225. homeAddress := patientBody["homeAddress"].(string)
  4226. patient.HomeAddress = homeAddress
  4227. }
  4228. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4229. work := patientBody["work"].(string)
  4230. patient.WorkUnit = work
  4231. }
  4232. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4233. unitAddress := patientBody["unit_address"].(string)
  4234. patient.UnitAddress = unitAddress
  4235. }
  4236. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4237. profession := int64(patientBody["profession"].(float64))
  4238. patient.Profession = profession
  4239. }
  4240. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4241. education := int64(patientBody["education"].(float64))
  4242. patient.EducationLevel = education
  4243. }
  4244. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4245. utils.ErrorLog("source")
  4246. code = enums.ErrorCodeParamWrong
  4247. return
  4248. }
  4249. source := int64(patientBody["source"].(float64))
  4250. if source <= 0 {
  4251. utils.ErrorLog("source <= 0")
  4252. code = enums.ErrorCodeParamWrong
  4253. return
  4254. }
  4255. patient.Source = source
  4256. zb_patient_id := patientBody["zb_patient_id"].(string)
  4257. patient.ZbPatientId = zb_patient_id
  4258. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4259. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4260. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4261. }
  4262. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4263. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4264. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4265. if err == nil {
  4266. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4267. }
  4268. }
  4269. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4270. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4271. patient.FirstDialysisHospital = firstDialysisHospital
  4272. }
  4273. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4274. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4275. if len(thePredialysisCondition) > 0 {
  4276. conditions := make([]string, 0)
  4277. for _, item := range thePredialysisCondition {
  4278. if reflect.TypeOf(item).String() != "string" {
  4279. continue
  4280. }
  4281. condition := item.(string)
  4282. if len(condition) > 0 {
  4283. conditions = append(conditions, condition)
  4284. }
  4285. }
  4286. patient.PredialysisCondition = strings.Join(conditions, ",")
  4287. }
  4288. }
  4289. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4290. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4291. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4292. }
  4293. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4294. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4295. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4296. }
  4297. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4298. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4299. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4300. if err == nil {
  4301. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4302. }
  4303. }
  4304. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4305. partition := int64(patientBody["partition"].(float64))
  4306. patient.PartitionId = partition
  4307. }
  4308. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4309. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4310. patient.BedId = bed
  4311. }
  4312. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4313. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4314. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4315. if err == nil {
  4316. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4317. }
  4318. }
  4319. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4320. blood := int64(patientBody["blood"].(float64))
  4321. patient.BloodType = blood
  4322. }
  4323. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4324. rh := int64(patientBody["rh"].(float64))
  4325. patient.Rh = rh
  4326. }
  4327. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4328. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4329. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4330. if err == nil {
  4331. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4332. }
  4333. }
  4334. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4335. receivingDate := patientBody["receivingDate"].(string)
  4336. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4337. if err == nil {
  4338. patient.ReceivingDate = receivingDateTime.Unix()
  4339. }
  4340. }
  4341. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4342. induction := int64(patientBody["induction"].(float64))
  4343. patient.InductionPeriod = induction
  4344. }
  4345. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4346. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4347. patient.InitialDialysis = initial
  4348. }
  4349. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4350. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4351. patient.TotalDialysis = dialysisTotal
  4352. }
  4353. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4354. thisContagions, _ := patientBody["contagions"].([]interface{})
  4355. if len(thisContagions) > 0 {
  4356. for _, item := range thisContagions {
  4357. if reflect.TypeOf(item).String() != "float64" {
  4358. continue
  4359. }
  4360. contagion := int64(item.(float64))
  4361. if contagion > 0 {
  4362. contagions = append(contagions, contagion)
  4363. }
  4364. }
  4365. }
  4366. }
  4367. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4368. doctor := int64(patientBody["doctor"].(float64))
  4369. patient.AttendingDoctorId = doctor
  4370. }
  4371. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4372. nurse := int64(patientBody["nurse"].(float64))
  4373. patient.HeadNurseId = nurse
  4374. }
  4375. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4376. assessment := patientBody["assessment"].(string)
  4377. patient.Evaluate = assessment
  4378. }
  4379. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4380. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4381. if len(thisDiseases) > 0 {
  4382. for _, item := range thisDiseases {
  4383. if reflect.TypeOf(item).String() != "float64" {
  4384. continue
  4385. }
  4386. disease := int64(item.(float64))
  4387. if disease > 0 {
  4388. diseases = append(diseases, disease)
  4389. }
  4390. }
  4391. }
  4392. }
  4393. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4394. diagnose := patientBody["diagnose"].(string)
  4395. patient.Diagnose = diagnose
  4396. }
  4397. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4398. remark := patientBody["remark"].(string)
  4399. patient.Remark = remark
  4400. }
  4401. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4402. sch_remark := patientBody["sch_remark"].(string)
  4403. patient.SchRemark = sch_remark
  4404. }
  4405. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4406. patient_complains := patientBody["patient_complains"].(string)
  4407. patient.PatientComplains = patient_complains
  4408. }
  4409. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4410. present_history := patientBody["present_history"].(string)
  4411. patient.PresentHistory = present_history
  4412. }
  4413. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4414. past_history := patientBody["past_history"].(string)
  4415. patient.PastHistory = past_history
  4416. }
  4417. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4418. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4419. patient.Temperature = temperature
  4420. }
  4421. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4422. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4423. patient.Pulse = pulse
  4424. }
  4425. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4426. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4427. patient.Respiratory = respiratory
  4428. }
  4429. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4430. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4431. patient.SBP = sbp
  4432. }
  4433. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4434. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4435. patient.DBP = dbp
  4436. }
  4437. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4438. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4439. patient.DialysisAge = dialysis_age
  4440. }
  4441. fmt.Println(patient.DialysisAge)
  4442. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4443. first_treatment_date := patientBody["first_treatment_date"].(string)
  4444. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4445. if err == nil {
  4446. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4447. }
  4448. }
  4449. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4450. expense_kind := int64(patientBody["expense_kind"].(float64))
  4451. patient.ExpenseKind = expense_kind
  4452. }
  4453. fmt.Println(patient.ExpenseKind)
  4454. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4455. tell_phone := patientBody["tell_phone"].(string)
  4456. patient.TellPhone = tell_phone
  4457. }
  4458. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4459. contact_name := patientBody["contact_name"].(string)
  4460. patient.ContactName = contact_name
  4461. }
  4462. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4463. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4464. patient.TrobleShoot = troble_shoot
  4465. }
  4466. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4467. treatment_plan := patientBody["treatment_plan"].(string)
  4468. patient.TreatmentPlan = treatment_plan
  4469. }
  4470. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4471. doctor := int64(patientBody["doctor"].(float64))
  4472. patient.Doctor = doctor
  4473. }
  4474. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4475. record_number := patientBody["record_number"].(string)
  4476. patient.RecordNumber = record_number
  4477. }
  4478. patient_source := int64(patientBody["patient_source"].(float64))
  4479. if patient_source <= 0 {
  4480. utils.ErrorLog("patient_source <= 0")
  4481. code = enums.ErrorCodeParamWrong
  4482. return
  4483. }
  4484. patient.PatientSource = patient_source
  4485. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4486. patient_start_time := patientBody["patient_start_time"].(string)
  4487. var startTime int64
  4488. if len(patient_start_time) > 0 {
  4489. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4490. startTime = theTime.Unix()
  4491. }
  4492. patient.PatientStartTime = startTime
  4493. }
  4494. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4495. patient_end_time := patientBody["patient_end_time"].(string)
  4496. var endTime int64
  4497. if len(patient_end_time) > 0 {
  4498. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4499. endTime = theTime.Unix()
  4500. }
  4501. patient.PatientEndTime = endTime
  4502. }
  4503. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4504. record_number := patientBody["infectious_remark"].(string)
  4505. patient.InfectiousRemark = record_number
  4506. }
  4507. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4508. allergic_history := patientBody["allergic_history"].(string)
  4509. patient.AllergicHistory = allergic_history
  4510. }
  4511. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4512. patient_address := patientBody["patient_address"].(string)
  4513. patient.PatientAddress = patient_address
  4514. }
  4515. return
  4516. }
  4517. func (c *PatientApiController) GetPatientsByKeyWord() {
  4518. keyWord := c.GetString("keyword")
  4519. adminUserInfo := c.GetAdminUserInfo()
  4520. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4521. if err != nil {
  4522. utils.ErrorLog(err.Error())
  4523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4524. return
  4525. }
  4526. c.ServeSuccessJSON(map[string]interface{}{
  4527. "patient": patient,
  4528. })
  4529. }
  4530. func (c *PatientApiController) QueryPatientById() {
  4531. id, _ := c.GetInt64("id")
  4532. fmt.Println(id)
  4533. patientInfo := service.QueryPatientById(id)
  4534. c.ServeSuccessJSON(map[string]interface{}{
  4535. "patient": patientInfo,
  4536. })
  4537. return
  4538. }
  4539. func (c *PatientApiController) GetRemindPatientList() {
  4540. page, _ := c.GetInt64("page", 1)
  4541. limit, _ := c.GetInt64("limit", 10)
  4542. adminUserInfo := c.GetAdminUserInfo()
  4543. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4544. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4545. if errcode == gorm.ErrRecordNotFound {
  4546. information, err := service.GetAdminUserRoleInformation(0)
  4547. if err != nil {
  4548. utils.ErrorLog(err.Error())
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4550. return
  4551. }
  4552. c.ServeSuccessJSON(map[string]interface{}{
  4553. "total": total,
  4554. "patients": patients,
  4555. "information": information,
  4556. })
  4557. } else if errcode == nil {
  4558. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4559. if err != nil {
  4560. utils.ErrorLog(err.Error())
  4561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4562. return
  4563. }
  4564. c.ServeSuccessJSON(map[string]interface{}{
  4565. "total": total,
  4566. "patients": patients,
  4567. "information": information,
  4568. })
  4569. }
  4570. }
  4571. func (c *PatientApiController) PostIsOpenRemind() {
  4572. patient_id, _ := c.GetInt64("id", 1)
  4573. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4574. adminUserInfo := c.GetAdminUserInfo()
  4575. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4576. if err == nil {
  4577. c.ServeSuccessJSON(map[string]interface{}{
  4578. "msg": "成功",
  4579. "is_open_remind": is_open_remind,
  4580. })
  4581. } else if err != nil {
  4582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4583. }
  4584. }
  4585. func (c *PatientApiController) GetPatientScheduleOne() {
  4586. id, _ := c.GetInt64("id")
  4587. //查询该病人是否当天是排班
  4588. nowDateTime := time.Now()
  4589. nowDate := nowDateTime.Format("2006-01-02")
  4590. nowDate += " 00:00:00"
  4591. timeLayout := "2006-01-02"
  4592. loc, _ := time.LoadLocation("Local")
  4593. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4594. nowdate := theTime.Unix()
  4595. fmt.Println("nowdate", nowdate)
  4596. adminUser := c.GetAdminUserInfo()
  4597. orgId := adminUser.CurrentOrgId
  4598. fmt.Println("orgid", orgId)
  4599. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4600. if err != nil {
  4601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4602. return
  4603. }
  4604. c.ServeSuccessJSON(map[string]interface{}{
  4605. "scheduls": scheduls,
  4606. })
  4607. }
  4608. func (c *PatientApiController) ExportPatients() {
  4609. dataBody := make(map[string]interface{}, 0)
  4610. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4611. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4612. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4613. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4614. if err != nil {
  4615. utils.ErrorLog(err.Error())
  4616. return
  4617. }
  4618. utils.ErrorLog("%v", dataBody)
  4619. export_time := time.Now().Unix()
  4620. var patients []*models.Patients
  4621. var total_patients []interface{}
  4622. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4623. tempPatients := dataBody["patients"].([]interface{})
  4624. total_patients = tempPatients
  4625. for index, patientMap := range tempPatients {
  4626. patientNameM := patientMap.(map[string]interface{})
  4627. var patient models.Patients
  4628. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4629. utils.ErrorLog("name")
  4630. return
  4631. }
  4632. name, _ := patientNameM["name"].(string)
  4633. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4634. err_log := models.ExportErrLog{
  4635. LogType: 1,
  4636. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4637. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4638. Status: 1,
  4639. CreateTime: time.Now().Unix(),
  4640. UpdateTime: time.Now().Unix(),
  4641. ExportTime: export_time,
  4642. }
  4643. service.CreateExportErrLog(&err_log)
  4644. continue
  4645. }
  4646. patient.Name = name
  4647. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4648. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4649. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4650. err_log := models.ExportErrLog{
  4651. LogType: 1,
  4652. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4653. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4654. Status: 1,
  4655. CreateTime: time.Now().Unix(),
  4656. UpdateTime: time.Now().Unix(),
  4657. ExportTime: export_time,
  4658. }
  4659. service.CreateExportErrLog(&err_log)
  4660. continue
  4661. } else {
  4662. patient.Gender = gender
  4663. }
  4664. }
  4665. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4666. phone, _ := patientNameM["phone"].(string)
  4667. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4668. if len(phone) == 0 {
  4669. err_log := models.ExportErrLog{
  4670. LogType: 1,
  4671. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4672. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4673. Status: 1,
  4674. CreateTime: time.Now().Unix(),
  4675. UpdateTime: time.Now().Unix(),
  4676. ExportTime: export_time,
  4677. }
  4678. service.CreateExportErrLog(&err_log)
  4679. continue
  4680. } else {
  4681. err_log := models.ExportErrLog{
  4682. LogType: 1,
  4683. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4684. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4685. Status: 1,
  4686. CreateTime: time.Now().Unix(),
  4687. UpdateTime: time.Now().Unix(),
  4688. ExportTime: export_time,
  4689. }
  4690. service.CreateExportErrLog(&err_log)
  4691. continue
  4692. }
  4693. } else {
  4694. //var tempPatient *models.Patients
  4695. //for _, item := range all_patient {
  4696. // if item.Phone == phone {
  4697. // tempPatient = item
  4698. // }
  4699. //}
  4700. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4701. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4702. if count >= 1 {
  4703. err_log := models.ExportErrLog{
  4704. LogType: 1,
  4705. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4706. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4707. Status: 1,
  4708. CreateTime: time.Now().Unix(),
  4709. UpdateTime: time.Now().Unix(),
  4710. ExportTime: export_time,
  4711. }
  4712. service.CreateExportErrLog(&err_log)
  4713. continue
  4714. }
  4715. patient.Phone = phone
  4716. }
  4717. }
  4718. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4719. id_card_no, _ := patientNameM["id_card_no"].(string)
  4720. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4721. if len(id_card_no) == 0 {
  4722. err_log := models.ExportErrLog{
  4723. LogType: 1,
  4724. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4725. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4726. Status: 1,
  4727. CreateTime: time.Now().Unix(),
  4728. UpdateTime: time.Now().Unix(),
  4729. ExportTime: export_time,
  4730. }
  4731. service.CreateExportErrLog(&err_log)
  4732. continue
  4733. } else {
  4734. err_log := models.ExportErrLog{
  4735. LogType: 1,
  4736. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4737. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4738. Status: 1,
  4739. CreateTime: time.Now().Unix(),
  4740. UpdateTime: time.Now().Unix(),
  4741. ExportTime: export_time,
  4742. }
  4743. service.CreateExportErrLog(&err_log)
  4744. continue
  4745. }
  4746. } else {
  4747. //var tempPatient *models.Patients
  4748. //for _, item := range all_patient {
  4749. // if item.IdCardNo == id_card_no {
  4750. // tempPatient = item
  4751. // }
  4752. //}
  4753. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4754. if count >= 1 {
  4755. //if tempPatient != nil && tempPatient.ID > 0 {
  4756. err_log := models.ExportErrLog{
  4757. LogType: 1,
  4758. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4759. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4760. Status: 1,
  4761. CreateTime: time.Now().Unix(),
  4762. UpdateTime: time.Now().Unix(),
  4763. ExportTime: export_time,
  4764. }
  4765. service.CreateExportErrLog(&err_log)
  4766. continue
  4767. }
  4768. //}
  4769. patient.IdCardNo = id_card_no
  4770. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4771. if GetBirthDay(id_card_no) == nil {
  4772. patient.Birthday = 0
  4773. } else {
  4774. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4775. }
  4776. }
  4777. }
  4778. fmt.Println("111112222")
  4779. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4780. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4781. timeLayout := "2006/01/02"
  4782. loc, _ := time.LoadLocation("Local")
  4783. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4784. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4785. if len(first_treatment_date) == 0 {
  4786. err_log := models.ExportErrLog{
  4787. LogType: 1,
  4788. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4789. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4790. Status: 1,
  4791. CreateTime: time.Now().Unix(),
  4792. UpdateTime: time.Now().Unix(),
  4793. ExportTime: export_time,
  4794. }
  4795. service.CreateExportErrLog(&err_log)
  4796. continue
  4797. } else {
  4798. err_log := models.ExportErrLog{
  4799. LogType: 1,
  4800. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4801. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4802. Status: 1,
  4803. CreateTime: time.Now().Unix(),
  4804. UpdateTime: time.Now().Unix(),
  4805. ExportTime: export_time,
  4806. }
  4807. service.CreateExportErrLog(&err_log)
  4808. continue
  4809. }
  4810. } else {
  4811. if len(first_treatment_date) == 0 {
  4812. err_log := models.ExportErrLog{
  4813. LogType: 1,
  4814. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4815. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4816. Status: 1,
  4817. CreateTime: time.Now().Unix(),
  4818. UpdateTime: time.Now().Unix(),
  4819. ExportTime: export_time,
  4820. }
  4821. service.CreateExportErrLog(&err_log)
  4822. continue
  4823. } else {
  4824. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4825. err_log := models.ExportErrLog{
  4826. LogType: 1,
  4827. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4828. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4829. Status: 1,
  4830. CreateTime: time.Now().Unix(),
  4831. UpdateTime: time.Now().Unix(),
  4832. ExportTime: export_time,
  4833. }
  4834. service.CreateExportErrLog(&err_log)
  4835. continue
  4836. } else {
  4837. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4838. }
  4839. }
  4840. }
  4841. }
  4842. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4843. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4844. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4845. err_log := models.ExportErrLog{
  4846. LogType: 1,
  4847. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4848. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4849. Status: 1,
  4850. CreateTime: time.Now().Unix(),
  4851. UpdateTime: time.Now().Unix(),
  4852. ExportTime: export_time,
  4853. }
  4854. service.CreateExportErrLog(&err_log)
  4855. continue
  4856. } else if source == 3 {
  4857. err_log := models.ExportErrLog{
  4858. LogType: 1,
  4859. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4860. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4861. Status: 1,
  4862. CreateTime: time.Now().Unix(),
  4863. UpdateTime: time.Now().Unix(),
  4864. ExportTime: export_time,
  4865. }
  4866. service.CreateExportErrLog(&err_log)
  4867. continue
  4868. } else {
  4869. patient.Source = source
  4870. }
  4871. }
  4872. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4873. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4874. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4875. err_log := models.ExportErrLog{
  4876. LogType: 1,
  4877. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4878. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4879. Status: 1,
  4880. CreateTime: time.Now().Unix(),
  4881. UpdateTime: time.Now().Unix(),
  4882. ExportTime: export_time,
  4883. }
  4884. service.CreateExportErrLog(&err_log)
  4885. continue
  4886. } else if lapseto == 3 {
  4887. err_log := models.ExportErrLog{
  4888. LogType: 1,
  4889. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4890. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4891. Status: 1,
  4892. CreateTime: time.Now().Unix(),
  4893. UpdateTime: time.Now().Unix(),
  4894. ExportTime: export_time,
  4895. }
  4896. service.CreateExportErrLog(&err_log)
  4897. continue
  4898. } else {
  4899. patient.Lapseto = lapseto
  4900. }
  4901. }
  4902. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4903. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4904. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4905. err_log := models.ExportErrLog{
  4906. LogType: 1,
  4907. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4908. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4909. Status: 1,
  4910. CreateTime: time.Now().Unix(),
  4911. UpdateTime: time.Now().Unix(),
  4912. ExportTime: export_time,
  4913. }
  4914. service.CreateExportErrLog(&err_log)
  4915. continue
  4916. } else if is_infectious == 3 {
  4917. err_log := models.ExportErrLog{
  4918. LogType: 1,
  4919. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4920. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4921. Status: 1,
  4922. CreateTime: time.Now().Unix(),
  4923. UpdateTime: time.Now().Unix(),
  4924. ExportTime: export_time,
  4925. }
  4926. service.CreateExportErrLog(&err_log)
  4927. continue
  4928. } else {
  4929. patient.IsInfectious = is_infectious
  4930. }
  4931. }
  4932. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4933. var contagions []int64
  4934. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4935. if len(thisContagions) > 0 {
  4936. for _, item := range thisContagions {
  4937. if reflect.TypeOf(item).String() != "float64" {
  4938. continue
  4939. }
  4940. contagion := int64(item.(float64))
  4941. if contagion > 0 {
  4942. contagions = append(contagions, contagion)
  4943. }
  4944. }
  4945. }
  4946. patient.ContagionIds = contagions
  4947. }
  4948. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4949. diagnose, _ := patientNameM["diagnose"].(string)
  4950. patient.Diagnose = diagnose
  4951. }
  4952. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4953. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4954. var tempPatient *models.Patients
  4955. for _, item := range all_patient {
  4956. if item.DialysisNo == dialysis_no {
  4957. tempPatient = item
  4958. }
  4959. }
  4960. if tempPatient != nil && tempPatient.ID > 0 {
  4961. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4962. } else {
  4963. patient.DialysisNo = dialysis_no
  4964. }
  4965. }
  4966. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4967. height, _ := patientNameM["height"].(string)
  4968. heights, _ := strconv.ParseFloat(height, 64)
  4969. patient.Height = int64(heights)
  4970. }
  4971. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4972. home_address, _ := patientNameM["home_address"].(string)
  4973. patient.HomeAddress = home_address
  4974. }
  4975. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  4976. dry_weight, _ := patientNameM["dry_weight"].(string)
  4977. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  4978. patient.DryWeight = dry_weights
  4979. }
  4980. patient.CreatedTime = time.Now().Unix()
  4981. patient.UpdatedTime = time.Now().Unix()
  4982. patient.Status = 1
  4983. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  4984. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  4985. patient.IsExcelExport = 1
  4986. patient.PatientType = 1
  4987. patients = append(patients, &patient)
  4988. }
  4989. }
  4990. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4991. if len(patients) > 0 {
  4992. for _, item := range patients {
  4993. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  4994. }
  4995. log := models.ExportLog{
  4996. LogType: 1,
  4997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4998. TotalNum: int64(len(total_patients)),
  4999. FailNum: int64(len(errLogs)),
  5000. SuccessNum: int64(len(patients)),
  5001. CreateTime: time.Now().Unix(),
  5002. UpdateTime: time.Now().Unix(),
  5003. ExportTime: export_time,
  5004. Status: 1,
  5005. }
  5006. service.CreateExportLog(&log)
  5007. c.ServeSuccessJSON(map[string]interface{}{
  5008. "msg": "导入成功",
  5009. "total_num": len(total_patients),
  5010. "success_num": len(patients),
  5011. "fail_num": int64(len(errLogs)),
  5012. })
  5013. } else {
  5014. log := models.ExportLog{
  5015. LogType: 1,
  5016. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5017. TotalNum: int64(len(total_patients)),
  5018. FailNum: int64(len(errLogs)),
  5019. SuccessNum: int64(len(patients)),
  5020. CreateTime: time.Now().Unix(),
  5021. UpdateTime: time.Now().Unix(),
  5022. ExportTime: export_time,
  5023. Status: 1,
  5024. }
  5025. service.CreateExportLog(&log)
  5026. c.ServeSuccessJSON(map[string]interface{}{
  5027. "msg": "导入成功",
  5028. "total_num": len(total_patients),
  5029. "success_num": len(patients),
  5030. "fail_num": int64(len(errLogs)),
  5031. })
  5032. }
  5033. }
  5034. func GetBirthDay(IDCardNo string) *time.Time {
  5035. dayStr := IDCardNo[6:14]
  5036. birthDay, err := time.Parse("20060102", dayStr)
  5037. if err != nil {
  5038. fmt.Println(err)
  5039. return nil
  5040. }
  5041. return &birthDay
  5042. }
  5043. func IsIdCard(id string) (res bool) {
  5044. id = strings.ToUpper(id)
  5045. if len(id) != 15 && len(id) != 18 {
  5046. fmt.Println("1111111")
  5047. return false
  5048. }
  5049. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5050. if !r.MatchString(id) {
  5051. fmt.Println("222222")
  5052. return false
  5053. }
  5054. if len(id) == 15 {
  5055. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5056. if tm2.Unix() == 0 {
  5057. fmt.Println("44444443333")
  5058. return false
  5059. }
  5060. return true
  5061. } else {
  5062. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5063. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5064. fmt.Println(tm2.Unix())
  5065. if tm2.Unix() == 0 {
  5066. fmt.Println("44445555555")
  5067. return false
  5068. }
  5069. //检验18位身份证的校验码是否正确。
  5070. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5071. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5072. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5073. sign := 0
  5074. for k, v := range arr_int {
  5075. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5076. sign += int_temp * v
  5077. }
  5078. n := sign % 11
  5079. val_num := arr_ch[n]
  5080. if val_num != string([]byte(id)[17:18]) {
  5081. fmt.Println("5556666666")
  5082. return false
  5083. }
  5084. return true
  5085. }
  5086. }
  5087. func (c *PatientApiController) SaveEditAdvices() {
  5088. adminInfo := c.GetAdminUserInfo()
  5089. orgid := adminInfo.CurrentOrgId
  5090. startTime := c.GetString("start_time")
  5091. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5092. groupno, _ := c.GetInt64("groupno")
  5093. fmt.Println("组", groupno)
  5094. date, _ := c.GetInt64("date")
  5095. fmt.Println("date", date)
  5096. patient_id, _ := c.GetInt64("patient_id")
  5097. fmt.Println("paitent_id", patient_id)
  5098. advice := models.XtDoctorAdvice{
  5099. StartTime: theTime.Unix(),
  5100. }
  5101. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5102. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5103. redis := service.RedisClient()
  5104. redis.Set(key, "", time.Second)
  5105. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5106. redis.Set(keyOne, "", time.Second)
  5107. scheduleTime := theTime.Format("2006-01-02")
  5108. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5109. fmt.Println("keyFour323223323232323232", keyFour)
  5110. redis.Set(keyFour, "", time.Second)
  5111. defer redis.Close()
  5112. if err != nil {
  5113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5114. return
  5115. }
  5116. c.ServeSuccessJSON(map[string]interface{}{
  5117. "advice": advice,
  5118. })
  5119. }
  5120. func (c *PatientApiController) GetMaxDialysisNo() {
  5121. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5122. c.ServeSuccessJSON(map[string]interface{}{
  5123. "dialysis_no": dialysisNo,
  5124. })
  5125. }
  5126. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5127. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5128. var tempPatient *models.Patients
  5129. for _, item := range patients {
  5130. if item.DialysisNo == dialysisNo2 {
  5131. tempPatient = item
  5132. }
  5133. }
  5134. if tempPatient == nil || tempPatient.ID == 0 {
  5135. return dialysisNo2
  5136. }
  5137. return GenerateDialysisNoTwo(patients)
  5138. }
  5139. func (c *PatientApiController) GetBanner() {
  5140. orgId := c.GetAdminUserInfo().CurrentOrgId
  5141. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5142. if errcodes == gorm.ErrRecordNotFound {
  5143. information, err := service.GetAdminUserRoleInformation(0)
  5144. if err != nil {
  5145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5146. return
  5147. }
  5148. c.ServeSuccessJSON(map[string]interface{}{
  5149. "information": information,
  5150. })
  5151. } else if errcodes == nil {
  5152. information, err := service.GetAdminUserRoleInformation(orgId)
  5153. if err != nil {
  5154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5155. return
  5156. }
  5157. c.ServeSuccessJSON(map[string]interface{}{
  5158. "information": information,
  5159. })
  5160. }
  5161. }
  5162. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5163. patient_id, _ := c.GetInt64("id", 0)
  5164. page, _ := c.GetInt64("page", 0)
  5165. limit, _ := c.GetInt64("limit", 0)
  5166. if patient_id <= 0 {
  5167. c.ServeSuccessJSON(map[string]interface{}{
  5168. "solutions": nil,
  5169. })
  5170. return
  5171. }
  5172. if page <= 0 {
  5173. page = 1
  5174. }
  5175. if limit <= 0 {
  5176. limit = 10
  5177. }
  5178. adminUserInfo := c.GetAdminUserInfo()
  5179. //获取该患者分组的透析模式
  5180. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5181. for _, item := range list {
  5182. //获取该模式最新的1条数据
  5183. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5184. //更新状态值
  5185. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5186. }
  5187. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5188. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5189. if err != nil {
  5190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5191. return
  5192. }
  5193. c.ServeSuccessJSON(map[string]interface{}{
  5194. "solutions": solution,
  5195. "total": total,
  5196. "stockType": stockType,
  5197. })
  5198. }
  5199. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5200. patient_id, _ := c.GetInt64("patient_id")
  5201. mode_id, _ := c.GetInt64("mode_id")
  5202. page, _ := c.GetInt64("page")
  5203. limit, _ := c.GetInt64("limit")
  5204. orgId := c.GetAdminUserInfo().CurrentOrgId
  5205. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5206. if err != nil {
  5207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5208. return
  5209. }
  5210. c.ServeSuccessJSON(map[string]interface{}{
  5211. "list": list,
  5212. "total": total,
  5213. })
  5214. }