patient_api_controller.go 207KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060
  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 advice.StopState == 1 || advice.ExecutionState == 1 {
  2831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2832. return
  2833. }
  2834. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2835. //if appRole.UserType == 3 {
  2836. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2837. // if getPermissionErr != nil {
  2838. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2839. // return
  2840. // } else if headNursePermission == nil {
  2841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2842. // return
  2843. // }
  2844. //}
  2845. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2846. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2847. // return
  2848. //}
  2849. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2850. if code > 0 {
  2851. c.ServeFailJSONWithSGJErrorCode(code)
  2852. return
  2853. }
  2854. advice.UpdatedTime = time.Now().Unix()
  2855. advice.Modifier = adminUserInfo.AdminUser.Id
  2856. // 查询信息规挡的设置天数
  2857. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2858. if infor.ID > 0 && infor.WeekDay > 0 {
  2859. var cha_time int64
  2860. timeNowStr := time.Now().Format("2006-01-02")
  2861. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2862. //今日的日期减去设置的日期
  2863. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2864. if cha_time >= advice.AdviceDate {
  2865. //查询审核是否允许
  2866. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2867. //申请状态不允许的情况 拒绝修改
  2868. if infor.ApplicationStatus != 1 {
  2869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2870. return
  2871. }
  2872. }
  2873. }
  2874. err := service.UpdateDoctorAdvice(&advice)
  2875. //记录日志
  2876. byterequest, _ := json.Marshal(advice)
  2877. doctorAdviceLog := models.XtDoctorAdviceLog{
  2878. UserOrgId: advice.UserOrgId,
  2879. PatientId: advice.PatientId,
  2880. AdminUserId: adminUserInfo.AdminUser.Id,
  2881. Module: 1,
  2882. ErrLog: string(byterequest),
  2883. Status: 1,
  2884. Ctime: time.Now().Unix(),
  2885. Mtime: 0,
  2886. Source: "电脑端修改医嘱",
  2887. RecordDate: advice.AdviceDate,
  2888. }
  2889. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2890. redis := service.RedisClient()
  2891. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2892. redis.Set(key, "", time.Second)
  2893. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2894. redis.Set(keyOne, "", time.Second)
  2895. defer redis.Close()
  2896. if err != nil {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2898. return
  2899. }
  2900. c.ServeSuccessJSON(map[string]interface{}{
  2901. "msg": "ok",
  2902. "advice": advice,
  2903. })
  2904. return
  2905. }
  2906. func (c *PatientApiController) StopGroupAdvice() {
  2907. groupNo, _ := c.GetInt64("groupno", 0)
  2908. if groupNo <= 0 {
  2909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2910. return
  2911. }
  2912. adminUserInfo := c.GetAdminUserInfo()
  2913. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2914. if advice.ID == 0 {
  2915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2916. return
  2917. }
  2918. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2920. return
  2921. }
  2922. dataBody := make(map[string]interface{}, 0)
  2923. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2924. if err != nil {
  2925. utils.ErrorLog(err.Error())
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2927. return
  2928. }
  2929. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2930. utils.ErrorLog("stop_time")
  2931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2932. return
  2933. }
  2934. stopTime, _ := dataBody["stop_time"].(string)
  2935. if len(stopTime) == 0 {
  2936. utils.ErrorLog("len(stop_time) == 0")
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2938. return
  2939. }
  2940. timeLayout := "2006-01-02"
  2941. loc, _ := time.LoadLocation("Local")
  2942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2943. if err != nil {
  2944. utils.ErrorLog(err.Error())
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. advice.StopTime = theTime.Unix()
  2949. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2950. stopReason, _ := dataBody["stop_reason"].(string)
  2951. advice.StopReason = stopReason
  2952. }
  2953. advice.UpdatedTime = time.Now().Unix()
  2954. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2955. advice.StopState = 1
  2956. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2957. if err != nil {
  2958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2959. return
  2960. }
  2961. c.ServeSuccessJSON(map[string]interface{}{
  2962. "msg": "ok",
  2963. })
  2964. return
  2965. }
  2966. func (c *PatientApiController) StopDoctorAdvice() {
  2967. id, _ := c.GetInt64("id", 0)
  2968. if id <= 0 {
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2970. return
  2971. }
  2972. adminUserInfo := c.GetAdminUserInfo()
  2973. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2974. //
  2975. //if appRole.UserType == 3 {
  2976. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2977. // if getPermissionErr != nil {
  2978. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // } else if headNursePermission == nil {
  2981. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2982. // return
  2983. // }
  2984. //}
  2985. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2986. if advice.ID == 0 {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2988. return
  2989. }
  2990. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2992. return
  2993. }
  2994. dataBody := make(map[string]interface{}, 0)
  2995. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2996. if err != nil {
  2997. utils.ErrorLog(err.Error())
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2999. return
  3000. }
  3001. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3002. utils.ErrorLog("stop_time")
  3003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3004. return
  3005. }
  3006. stopTime, _ := dataBody["stop_time"].(string)
  3007. if len(stopTime) == 0 {
  3008. utils.ErrorLog("len(stop_time) == 0")
  3009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3010. return
  3011. }
  3012. timeLayout := "2006-01-02"
  3013. loc, _ := time.LoadLocation("Local")
  3014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3015. if err != nil {
  3016. utils.ErrorLog(err.Error())
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. advice.StopTime = theTime.Unix()
  3021. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3022. stopReason, _ := dataBody["stop_reason"].(string)
  3023. advice.StopReason = stopReason
  3024. }
  3025. advice.UpdatedTime = time.Now().Unix()
  3026. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3027. advice.StopState = 1
  3028. err = service.StopDoctorAdvice(&advice)
  3029. if err != nil {
  3030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3031. return
  3032. }
  3033. c.ServeSuccessJSON(map[string]interface{}{
  3034. "msg": "ok",
  3035. "advice": advice,
  3036. })
  3037. return
  3038. }
  3039. func (c *PatientApiController) DeleteDoctorAdvice() {
  3040. id, _ := c.GetInt64("id", 0)
  3041. if id <= 0 {
  3042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. adminUserInfo := c.GetAdminUserInfo()
  3046. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3047. if advice.ID == 0 {
  3048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3049. return
  3050. }
  3051. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3052. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3053. // return
  3054. //}
  3055. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3056. //
  3057. //if appRole.UserType == 3 {
  3058. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3059. // if getPermissionErr != nil {
  3060. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3061. // return
  3062. // } else if headNursePermission == nil {
  3063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3064. // return
  3065. // }
  3066. //}
  3067. advice.UpdatedTime = time.Now().Unix()
  3068. advice.Status = 0
  3069. advice.Modifier = adminUserInfo.AdminUser.Id
  3070. // 查询信息规挡的设置天数
  3071. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3072. if infor.ID > 0 && infor.WeekDay > 0 {
  3073. var cha_time int64
  3074. timeNowStr := time.Now().Format("2006-01-02")
  3075. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3076. //今日的日期减去设置的日期
  3077. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3078. if cha_time >= advice.AdviceDate {
  3079. //查询审核是否允许
  3080. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3081. //申请状态不允许的情况 拒绝修改
  3082. if infor.ApplicationStatus != 1 {
  3083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3084. return
  3085. }
  3086. }
  3087. }
  3088. err := service.DeleteDoctorAdvice(&advice)
  3089. //记录日志
  3090. byterequest, _ := json.Marshal(advice)
  3091. doctorAdviceLog := models.XtDoctorAdviceLog{
  3092. UserOrgId: advice.UserOrgId,
  3093. PatientId: advice.PatientId,
  3094. AdminUserId: adminUserInfo.AdminUser.Id,
  3095. Module: 4,
  3096. ErrLog: string(byterequest),
  3097. Status: 1,
  3098. Ctime: time.Now().Unix(),
  3099. Mtime: 0,
  3100. Source: "电脑端删除医嘱",
  3101. RecordDate: advice.RecordDate,
  3102. }
  3103. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3104. redis := service.RedisClient()
  3105. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3106. redis.Set(keyOne, "", time.Second)
  3107. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3108. redis.Set(key, "", time.Second)
  3109. redis.Close()
  3110. if err != nil {
  3111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3112. return
  3113. }
  3114. c.ServeSuccessJSON(map[string]interface{}{
  3115. "msg": "ok",
  3116. })
  3117. return
  3118. }
  3119. func (c *PatientApiController) DeleteGroupAdvice() {
  3120. groupNo, _ := c.GetInt64("groupno", 0)
  3121. if groupNo <= 0 {
  3122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3123. return
  3124. }
  3125. adminUserInfo := c.GetAdminUserInfo()
  3126. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3127. if advice.ID == 0 {
  3128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3129. return
  3130. }
  3131. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3132. //if appRole.UserType == 3 {
  3133. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3134. // if getPermissionErr != nil {
  3135. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3136. // return
  3137. // } else if headNursePermission == nil {
  3138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3139. // return
  3140. // }
  3141. //}
  3142. // 查询信息规挡的设置天数
  3143. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3144. if infor.ID > 0 && infor.WeekDay > 0 {
  3145. var cha_time int64
  3146. timeNowStr := time.Now().Format("2006-01-02")
  3147. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3148. //今日的日期减去设置的日期
  3149. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3150. if cha_time >= advice.AdviceDate {
  3151. //查询审核是否允许
  3152. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3153. //申请状态不允许的情况 拒绝修改
  3154. if infor.ApplicationStatus != 1 {
  3155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3156. return
  3157. }
  3158. }
  3159. }
  3160. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3161. byterequest, _ := json.Marshal(advice)
  3162. doctorAdviceLog := models.XtDoctorAdviceLog{
  3163. UserOrgId: advice.UserOrgId,
  3164. PatientId: advice.PatientId,
  3165. AdminUserId: adminUserInfo.AdminUser.Id,
  3166. Module: 4,
  3167. ErrLog: string(byterequest),
  3168. Status: 1,
  3169. Ctime: time.Now().Unix(),
  3170. Mtime: 0,
  3171. Source: "电脑端批量删除医嘱",
  3172. RecordDate: advice.RecordDate,
  3173. }
  3174. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3175. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3176. redis := service.RedisClient()
  3177. redis.Set(key, "", time.Second)
  3178. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3179. redis.Set(keyOne, "", time.Second)
  3180. defer redis.Close()
  3181. if err != nil {
  3182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3183. return
  3184. }
  3185. c.ServeSuccessJSON(map[string]interface{}{
  3186. "msg": "ok",
  3187. })
  3188. return
  3189. }
  3190. // GetDoctorAdvices 医嘱列表
  3191. func (c *PatientApiController) GetDoctorAdvices() {
  3192. id, _ := c.GetInt64("id", 0)
  3193. adviceType, _ := c.GetInt64("advice_type", 0)
  3194. stopType, _ := c.GetInt64("stop_state", 0)
  3195. startTime := c.GetString("start_time", "")
  3196. endTime := c.GetString("end_time", "")
  3197. keywords := c.GetString("keywords", "")
  3198. page, _ := c.GetInt64("page")
  3199. fmt.Println("page", page)
  3200. limit, _ := c.GetInt64("limit")
  3201. fmt.Println("limit", limit)
  3202. adminUserInfo := c.GetAdminUserInfo()
  3203. operatorIDs := make([]int64, 0)
  3204. timeLayout := "2006-01-02"
  3205. loc, _ := time.LoadLocation("Local")
  3206. var theStartTIme int64
  3207. if len(startTime) > 0 {
  3208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3209. if err != nil {
  3210. utils.ErrorLog(err.Error())
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3212. return
  3213. }
  3214. theStartTIme = theTime.Unix()
  3215. }
  3216. var theEndtTIme int64
  3217. if len(endTime) > 0 {
  3218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3219. if err != nil {
  3220. utils.ErrorLog(err.Error())
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3222. return
  3223. }
  3224. theEndtTIme = theTime.Unix()
  3225. }
  3226. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3227. if hisconfig.IsOpen == 1 {
  3228. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3229. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3230. if len(advices) > 0 {
  3231. for _, item := range advices {
  3232. if item.AdviceDoctor > 0 {
  3233. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3234. }
  3235. if item.ExecutionStaff > 0 {
  3236. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3237. }
  3238. if item.Checker > 0 {
  3239. operatorIDs = append(operatorIDs, item.Checker)
  3240. }
  3241. if item.StopDoctor > 0 {
  3242. operatorIDs = append(operatorIDs, item.StopDoctor)
  3243. }
  3244. }
  3245. }
  3246. //相关操作对应的操作人
  3247. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3248. //获取长期医嘱
  3249. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3250. c.ServeSuccessJSON(map[string]interface{}{
  3251. "advices": advices,
  3252. "operators": operators,
  3253. "total": total,
  3254. "advicetwo": advicestwo,
  3255. "longAdvice": longAdvice,
  3256. "is_open": hisconfig.IsOpen,
  3257. })
  3258. return
  3259. } else {
  3260. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3261. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3262. if len(advices) > 0 {
  3263. for _, item := range advices {
  3264. if item.AdviceDoctor > 0 {
  3265. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3266. }
  3267. if item.ExecutionStaff > 0 {
  3268. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3269. }
  3270. if item.Checker > 0 {
  3271. operatorIDs = append(operatorIDs, item.Checker)
  3272. }
  3273. if item.StopDoctor > 0 {
  3274. operatorIDs = append(operatorIDs, item.StopDoctor)
  3275. }
  3276. }
  3277. }
  3278. //相关操作对应的操作人
  3279. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3280. c.ServeSuccessJSON(map[string]interface{}{
  3281. "advices": advices,
  3282. "operators": operators,
  3283. "total": total,
  3284. "advicetwo": advicestwo,
  3285. "is_open": hisconfig.IsOpen,
  3286. })
  3287. return
  3288. }
  3289. }
  3290. func (c *PatientApiController) GetPatientSchedules() {
  3291. id, _ := c.GetInt64("id", 0)
  3292. if id <= 0 {
  3293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3294. return
  3295. }
  3296. adminUserInfo := c.GetAdminUserInfo()
  3297. todayTime := time.Now().Format("2006-01-02")
  3298. timeLayout := "2006-01-02 15:04:05"
  3299. loc, _ := time.LoadLocation("Local")
  3300. var theStartTime int64
  3301. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3302. theStartTime = theTime.Unix()
  3303. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3304. if len(schedules) > 0 {
  3305. for index, item := range schedules {
  3306. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3307. schedules[index].Week = int64(week)
  3308. }
  3309. }
  3310. c.ServeSuccessJSON(map[string]interface{}{
  3311. "schedules": schedules,
  3312. })
  3313. return
  3314. }
  3315. func (c *PatientApiController) GetPatientDialysisRecords() {
  3316. patientID, _ := c.GetInt64("patient_id", 0)
  3317. page, _ := c.GetInt64("page", 0)
  3318. limit, _ := c.GetInt64("limit", 0)
  3319. startTime := c.GetString("start_time", "")
  3320. endTime := c.GetString("end_time", "")
  3321. mode_id, _ := c.GetInt64("mode_id", 0)
  3322. if page <= 0 {
  3323. page = 1
  3324. }
  3325. if limit <= 0 {
  3326. limit = 10
  3327. }
  3328. if patientID <= 0 {
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3330. return
  3331. }
  3332. timeLayout := "2006-01-02"
  3333. loc, _ := time.LoadLocation("Local")
  3334. var theStartTIme int64
  3335. if len(startTime) > 0 {
  3336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3337. if err != nil {
  3338. theStartTIme = 0
  3339. }
  3340. theStartTIme = theTime.Unix()
  3341. }
  3342. var theEndtTIme int64
  3343. if len(endTime) > 0 {
  3344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3345. if err != nil {
  3346. theEndtTIme = 0
  3347. }
  3348. theEndtTIme = theTime.Unix()
  3349. }
  3350. adminInfo := c.GetAdminUserInfo()
  3351. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3352. c.ServeSuccessJSON(map[string]interface{}{
  3353. "total": total,
  3354. "records": records,
  3355. })
  3356. return
  3357. }
  3358. func (c *PatientApiController) ProEducation() {
  3359. patientID, _ := c.GetInt64("patient_id", 0)
  3360. page, _ := c.GetInt64("page", 0)
  3361. limit, _ := c.GetInt64("limit", 0)
  3362. startTime := c.GetString("start_time", "")
  3363. endTime := c.GetString("end_time", "")
  3364. if page <= 0 {
  3365. page = 1
  3366. }
  3367. if limit <= 0 {
  3368. limit = 10
  3369. }
  3370. if patientID <= 0 {
  3371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. return
  3373. }
  3374. timeLayout := "2006-01-02"
  3375. loc, _ := time.LoadLocation("Local")
  3376. var theStartTIme int64
  3377. if len(startTime) > 0 {
  3378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3379. if err != nil {
  3380. theStartTIme = 0
  3381. }
  3382. theStartTIme = theTime.Unix()
  3383. }
  3384. var theEndtTIme int64
  3385. if len(endTime) > 0 {
  3386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3387. if err != nil {
  3388. theEndtTIme = 0
  3389. }
  3390. theEndtTIme = theTime.Unix()
  3391. }
  3392. adminInfo := c.GetAdminUserInfo()
  3393. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3394. c.ServeSuccessJSON(map[string]interface{}{
  3395. "total": total,
  3396. "edus": edus,
  3397. })
  3398. return
  3399. }
  3400. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3401. dataBody := make(map[string]interface{}, 0)
  3402. err := json.Unmarshal(data, &dataBody)
  3403. if err != nil {
  3404. utils.ErrorLog(err.Error())
  3405. code = enums.ErrorCodeParamWrong
  3406. return
  3407. }
  3408. timeLayout := "2006-01-02"
  3409. loc, _ := time.LoadLocation("Local")
  3410. isChild := false
  3411. if action == "create" {
  3412. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3413. utils.ErrorLog("advice_type")
  3414. code = enums.ErrorCodeParamWrong
  3415. return
  3416. }
  3417. adviceType := int64(dataBody["advice_type"].(float64))
  3418. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3419. utils.ErrorLog("advice_type != 1&&2")
  3420. code = enums.ErrorCodeParamWrong
  3421. return
  3422. }
  3423. advice.AdviceType = adviceType
  3424. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3425. utils.ErrorLog("advice_date")
  3426. code = enums.ErrorCodeParamWrong
  3427. return
  3428. }
  3429. adviceDate, _ := dataBody["advice_date"].(string)
  3430. if len(adviceDate) == 0 {
  3431. utils.ErrorLog("len(adviceDate) == 0")
  3432. code = enums.ErrorCodeParamWrong
  3433. return
  3434. }
  3435. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3436. if err != nil {
  3437. utils.ErrorLog(err.Error())
  3438. code = enums.ErrorCodeParamWrong
  3439. return
  3440. }
  3441. advice.AdviceDate = theTime.Unix()
  3442. advice.RecordDate = theTime.Unix()
  3443. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3444. parentId := int64(dataBody["parent_id"].(float64))
  3445. advice.ParentId = parentId
  3446. if parentId > 0 {
  3447. isChild = true
  3448. }
  3449. }
  3450. }
  3451. if !isChild {
  3452. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3453. utils.ErrorLog("start_time")
  3454. code = enums.ErrorCodeParamWrong
  3455. return
  3456. }
  3457. startTime, _ := dataBody["start_time"].(string)
  3458. if len(startTime) == 0 {
  3459. utils.ErrorLog("len(start_time) == 0")
  3460. code = enums.ErrorCodeParamWrong
  3461. return
  3462. }
  3463. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3464. if err != nil {
  3465. utils.ErrorLog(err.Error())
  3466. code = enums.ErrorCodeParamWrong
  3467. return
  3468. }
  3469. advice.StartTime = theTime.Unix()
  3470. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3471. // utils.ErrorLog("advice_doctor")
  3472. // code = enums.ErrorCodeParamWrong
  3473. // return
  3474. // }
  3475. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3476. // if adviceDoctor <= 0 {
  3477. // utils.ErrorLog("advice_doctor <=0")
  3478. // code = enums.ErrorCodeParamWrong
  3479. // return
  3480. // }
  3481. // advice.AdviceDoctor = adviceDoctor
  3482. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3483. deliveryWay, _ := dataBody["delivery_way"].(string)
  3484. advice.DeliveryWay = deliveryWay
  3485. }
  3486. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3487. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3488. advice.ExecutionFrequency = executionFrequency
  3489. }
  3490. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3491. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3492. frequency_type := int64(dataBody["frequency_type"].(float64))
  3493. advice.FrequencyType = frequency_type
  3494. }
  3495. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3496. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3497. advice.DayCount = day_count
  3498. }
  3499. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3500. week_day, _ := dataBody["week_days"].(string)
  3501. advice.WeekDay = week_day
  3502. }
  3503. }
  3504. }
  3505. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3506. utils.ErrorLog("advice_name")
  3507. code = enums.ErrorCodeParamWrong
  3508. return
  3509. }
  3510. adviceName, _ := dataBody["advice_name"].(string)
  3511. if len(adviceName) == 0 {
  3512. utils.ErrorLog("len(advice_name) == 0")
  3513. code = enums.ErrorCodeParamWrong
  3514. return
  3515. }
  3516. advice.AdviceName = adviceName
  3517. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3518. adviceDsc, _ := dataBody["advice_desc"].(string)
  3519. advice.AdviceDesc = adviceDsc
  3520. }
  3521. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3522. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3523. advice.DialysisOrderId = int64(dialysisOrderId)
  3524. }
  3525. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3526. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3527. advice.SingleDose = singleDose
  3528. }
  3529. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3530. singleDose := dataBody["single_dose"].(float64)
  3531. advice.SingleDose = singleDose
  3532. }
  3533. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3534. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3535. advice.SingleDoseUnit = singleDoseUnit
  3536. }
  3537. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3538. tmp := dataBody["single_dose_unit"].(float64)
  3539. singleDoseUnit := service.TypeConversion(tmp)
  3540. advice.SingleDoseUnit = singleDoseUnit
  3541. }
  3542. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3543. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3544. advice.DrugSpec = drugSpec
  3545. }
  3546. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3547. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3548. advice.DrugSpecUnit = drugSpecUnit
  3549. }
  3550. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3551. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3552. advice.PrescribingNumber = prescribingNumber
  3553. }
  3554. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3555. prescribingNumber := dataBody["prescribing_number"].(float64)
  3556. advice.PrescribingNumber = prescribingNumber
  3557. }
  3558. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3559. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3560. advice.PrescribingNumberUnit = prescribingNumberUnit
  3561. }
  3562. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3563. remark, _ := dataBody["remark"].(string)
  3564. advice.Remark = remark
  3565. }
  3566. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3567. drug_id, _ := dataBody["drug_id"].(string)
  3568. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3569. advice.DrugId = tmpDrugId
  3570. }
  3571. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3572. drug_id, _ := dataBody["drug_id"].(float64)
  3573. advice.DrugId = int64(drug_id)
  3574. }
  3575. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3576. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3577. advice.DrugNameId = int64(drug_name_id)
  3578. }
  3579. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3580. way, _ := dataBody["way"].(float64)
  3581. advice.Way = int64(way)
  3582. }
  3583. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3584. push_start_time, _ := dataBody["push_start_time"].(string)
  3585. var startTime int64
  3586. if len(push_start_time) > 0 {
  3587. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3588. startTime = theTime.Unix()
  3589. }
  3590. advice.PushStartTime = startTime
  3591. }
  3592. return
  3593. }
  3594. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3595. dataBody := make(map[string]interface{}, 0)
  3596. err := json.Unmarshal(data, &dataBody)
  3597. utils.InfoLog(string(data))
  3598. if err != nil {
  3599. utils.ErrorLog(err.Error())
  3600. code = enums.ErrorCodeParamWrong
  3601. return
  3602. }
  3603. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3604. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3605. solution.DialysisDuration = dialysisDuration
  3606. }
  3607. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3608. replacementWay := int64(dataBody["replacement_way"].(float64))
  3609. solution.ReplacementWay = replacementWay
  3610. }
  3611. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3612. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3613. solution.BloodFlowVolume = bloodFlowVolume
  3614. }
  3615. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3616. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3617. solution.HemodialysisMachine = hemodialysisMachine
  3618. }
  3619. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3620. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3621. solution.BloodFilter = bloodFilter
  3622. }
  3623. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3624. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3625. solution.PerfusionApparatus = perfusionApparatus
  3626. }
  3627. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3628. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3629. solution.DialysateFlow = dialysateFlow
  3630. }
  3631. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3632. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3633. solution.Kalium = kalium
  3634. }
  3635. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3636. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3637. solution.Sodium = sodium
  3638. }
  3639. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3640. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3641. solution.Calcium = calcium
  3642. }
  3643. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3644. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3645. solution.Bicarbonate = bicarbonate
  3646. }
  3647. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3648. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3649. solution.Anticoagulant = anticoagulant
  3650. }
  3651. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3652. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3653. solution.AnticoagulantShouji = anticoagulantShouji
  3654. }
  3655. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3656. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3657. solution.AnticoagulantWeichi = anticoagulantWeichi
  3658. }
  3659. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3660. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3661. solution.AnticoagulantZongliang = anticoagulantZongliang
  3662. }
  3663. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3664. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3665. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3666. }
  3667. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3668. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3669. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3670. }
  3671. return
  3672. }
  3673. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3674. dataBody := make(map[string]interface{}, 0)
  3675. err := json.Unmarshal(data, &dataBody)
  3676. utils.InfoLog(string(data))
  3677. if err != nil {
  3678. utils.ErrorLog(err.Error())
  3679. code = enums.ErrorCodeParamWrong
  3680. return
  3681. }
  3682. if method == "create" {
  3683. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3684. utils.ErrorLog("mode")
  3685. code = enums.ErrorCodeParamWrong
  3686. return
  3687. }
  3688. mode := int64(dataBody["mode"].(float64))
  3689. if mode <= 0 {
  3690. utils.ErrorLog("mode <= 0")
  3691. code = enums.ErrorCodeParamWrong
  3692. return
  3693. }
  3694. solution.ModeId = mode
  3695. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3696. utils.ErrorLog("mode_name")
  3697. code = enums.ErrorCodeParamWrong
  3698. return
  3699. }
  3700. modeName, _ := dataBody["mode_name"].(string)
  3701. if len(modeName) == 0 {
  3702. utils.ErrorLog("len(mode_name) == 0")
  3703. code = enums.ErrorCodeParamWrong
  3704. return
  3705. }
  3706. solution.ModeName = modeName
  3707. solution.Name = modeName
  3708. }
  3709. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3710. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3711. solution.DialysisDuration = dialysisDuration
  3712. }
  3713. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3714. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3715. solution.TargetUltrafiltration = targetUltrafiltration
  3716. }
  3717. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3718. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3719. solution.DialysateFormulation = dialysateFormulation
  3720. }
  3721. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3722. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3723. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3724. }
  3725. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3726. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3727. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3728. }
  3729. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3730. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3731. solution.HemodialysisMachine = hemodialysisMachine
  3732. }
  3733. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3734. dialyzer := int64(dataBody["dialyzer"].(float64))
  3735. solution.Dialyzer = dialyzer
  3736. }
  3737. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3738. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3739. solution.PerfusionApparatus = perfusionApparatus
  3740. }
  3741. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3742. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3743. solution.BloodFlowVolume = bloodFlowVolume
  3744. }
  3745. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3746. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3747. solution.Dewater = dewater
  3748. }
  3749. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3750. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3751. solution.DisplaceLiqui = displaceLiqui
  3752. }
  3753. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3754. replacementWay := int64(dataBody["replacement_way"].(float64))
  3755. solution.ReplacementWay = replacementWay
  3756. }
  3757. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3758. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3759. solution.Anticoagulant = anticoagulant
  3760. }
  3761. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3762. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3763. solution.AnticoagulantShouji = anticoagulantShouji
  3764. }
  3765. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3766. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3767. solution.AnticoagulantWeichi = anticoagulantWeichi
  3768. }
  3769. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3770. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3771. solution.AnticoagulantZongliang = anticoagulantZongliang
  3772. }
  3773. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3774. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3775. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3776. }
  3777. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3778. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3779. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3780. }
  3781. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3782. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3783. solution.Kalium = kalium
  3784. }
  3785. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3786. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3787. solution.Sodium = sodium
  3788. }
  3789. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3790. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3791. solution.Calcium = calcium
  3792. }
  3793. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3794. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3795. solution.Bicarbonate = bicarbonate
  3796. }
  3797. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3798. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3799. solution.Glucose = glucose
  3800. }
  3801. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3802. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3803. // solution.DryWeight = dryWeight
  3804. // }
  3805. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3806. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3807. solution.DialysateFlow = dialysateFlow
  3808. }
  3809. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3810. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3811. solution.DialysateTemperature = dialysateTemperature
  3812. }
  3813. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3814. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3815. solution.Conductivity = conductivity
  3816. }
  3817. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3818. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3819. solution.ReplacementTotal = replacementTotal
  3820. }
  3821. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3822. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3823. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3824. }
  3825. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3826. body_fluid := int64(dataBody["body_fluid"].(float64))
  3827. solution.BodyFluid = body_fluid
  3828. }
  3829. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3830. body_fluid_other := dataBody["body_fluid_other"].(string)
  3831. solution.BodyFluidOther = body_fluid_other
  3832. }
  3833. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3834. special_medicine := int64(dataBody["special_medicine"].(float64))
  3835. solution.SpecialMedicine = special_medicine
  3836. }
  3837. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3838. special_medicine_other := dataBody["special_medicine_other"].(string)
  3839. solution.SpecialMedicineOther = special_medicine_other
  3840. }
  3841. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3842. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3843. solution.DisplaceLiquiPart = displace_liqui_part
  3844. }
  3845. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3846. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3847. solution.DisplaceLiquiValue = displace_liqui_value
  3848. }
  3849. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3850. blood_access := int64(dataBody["blood_access"].(float64))
  3851. solution.BloodAccess = blood_access
  3852. }
  3853. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3854. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3855. solution.Ultrafiltration = ultrafiltration
  3856. }
  3857. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3858. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3859. solution.TargetKtv = target_ktv
  3860. }
  3861. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3862. remark := dataBody["remark"].(string)
  3863. solution.Remark = remark
  3864. }
  3865. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3866. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3867. solution.HemodialysisPipelines = hemodialysis_pipelines
  3868. }
  3869. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3870. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3871. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3872. }
  3873. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3874. puncture_needle := dataBody["puncture_needle"].(string)
  3875. solution.PunctureNeedle = puncture_needle
  3876. }
  3877. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3878. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3879. solution.PunctureNeedleCount = puncture_needle_count
  3880. }
  3881. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3882. epo := dataBody["epo"].(string)
  3883. solution.Epo = epo
  3884. }
  3885. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3886. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3887. solution.EpoCount = epo_count
  3888. }
  3889. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3890. created_time := int64(dataBody["created_time"].(float64))
  3891. solution.CreatedTime = created_time
  3892. }
  3893. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3894. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3895. solution.DialysisDialyszers = dialysisDialyszers
  3896. }
  3897. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3898. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3899. solution.DialysisIrrigation = dialysisIrrigation
  3900. }
  3901. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3902. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3903. solution.DialysisStrainer = dialysis_strainer
  3904. }
  3905. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3906. plasmaSeparator := dataBody["plasma_separator"].(string)
  3907. solution.PlasmaSeparator = plasmaSeparator
  3908. }
  3909. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3910. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3911. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3912. }
  3913. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3914. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3915. solution.OxygenUptake = oxygen_uptake
  3916. }
  3917. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3918. oxygen_flow := dataBody["oxygen_flow"].(string)
  3919. solution.OxygenFlow = oxygen_flow
  3920. }
  3921. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3922. oxygen_time := dataBody["oxygen_time"].(string)
  3923. solution.OxygenTime = oxygen_time
  3924. }
  3925. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3926. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3927. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3928. }
  3929. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3930. amylaceum := dataBody["amylaceum"].(string)
  3931. solution.Amylaceum = amylaceum
  3932. }
  3933. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  3934. chaptalization := dataBody["chaptalization"].(string)
  3935. solution.Chaptalization = chaptalization
  3936. }
  3937. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3938. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3939. solution.BloodAccessPartId = blood_access_part_id
  3940. }
  3941. return
  3942. }
  3943. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3944. dataBody := make(map[string]interface{}, 0)
  3945. err := json.Unmarshal(data, &dataBody)
  3946. utils.InfoLog(string(data))
  3947. if err != nil {
  3948. utils.ErrorLog(err.Error())
  3949. code = enums.ErrorCodeParamWrong
  3950. return
  3951. }
  3952. if method == "create" {
  3953. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3954. utils.ErrorLog("parent_id")
  3955. code = enums.ErrorCodeParamWrong
  3956. return
  3957. }
  3958. parentID := int64(dataBody["parent_id"].(float64))
  3959. if parentID <= 0 {
  3960. utils.ErrorLog("parentID <= 0")
  3961. code = enums.ErrorCodeParamWrong
  3962. return
  3963. }
  3964. solution.ParentId = parentID
  3965. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3966. utils.ErrorLog("sub_name")
  3967. code = enums.ErrorCodeParamWrong
  3968. return
  3969. }
  3970. subName, _ := dataBody["sub_name"].(string)
  3971. if len(subName) == 0 {
  3972. utils.ErrorLog("len(sub_name) == 0")
  3973. code = enums.ErrorCodeParamWrong
  3974. return
  3975. }
  3976. solution.SubName = subName
  3977. }
  3978. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  3979. utils.ErrorLog("initiate_mode")
  3980. code = enums.ErrorCodeParamWrong
  3981. return
  3982. }
  3983. initiateMode := int64(dataBody["initiate_mode"].(float64))
  3984. if initiateMode != 1 && initiateMode != 2 {
  3985. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  3986. code = enums.ErrorCodeParamWrong
  3987. return
  3988. }
  3989. solution.InitiateMode = initiateMode
  3990. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3991. utils.ErrorLog("doctor")
  3992. code = enums.ErrorCodeParamWrong
  3993. return
  3994. }
  3995. doctor := int64(dataBody["doctor"].(float64))
  3996. if doctor <= 0 {
  3997. utils.ErrorLog("doctor <= 0")
  3998. code = enums.ErrorCodeParamWrong
  3999. return
  4000. }
  4001. solution.Doctor = doctor
  4002. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4003. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4004. solution.BloodAccessPartId = blood_access_part_id
  4005. }
  4006. return
  4007. }
  4008. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4009. patientBody := make(map[string]interface{}, 0)
  4010. err := json.Unmarshal(data, &patientBody)
  4011. if err != nil {
  4012. utils.ErrorLog(err.Error())
  4013. code = enums.ErrorCodeParamWrong
  4014. return
  4015. }
  4016. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4017. formItem, _ := patientBody["formItem"].([]interface{})
  4018. if len(formItem) > 0 {
  4019. for _, item := range formItem {
  4020. items := item.(map[string]interface{})
  4021. project_name, _ := items["project_name"].(string)
  4022. fmt.Println(project_name)
  4023. range_type := int64(items["range_type"].(float64))
  4024. fmt.Println(range_type)
  4025. project_id := int64(items["project_id"].(float64))
  4026. fmt.Println(project_id)
  4027. item_id := int64(items["item_id"].(float64))
  4028. fmt.Println(item_id)
  4029. item, _ := items["item"].(string)
  4030. fmt.Println(items["item"].(string))
  4031. item_name, _ := items["item_name"].(string)
  4032. fmt.Println(item_name)
  4033. value, _ := items["value"].(string)
  4034. fmt.Println(items["value"].(string))
  4035. var form models.FormItem
  4036. form.ProjectName = project_name
  4037. form.RangeType = range_type
  4038. form.ProjectId = project_id
  4039. form.ItemId = item_id
  4040. form.Item = item
  4041. form.ItemName = item_name
  4042. form.Value = value
  4043. formItems = append(formItems, &form)
  4044. }
  4045. }
  4046. }
  4047. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4048. utils.ErrorLog("avatar")
  4049. code = enums.ErrorCodeParamWrong
  4050. return
  4051. }
  4052. avatar, _ := patientBody["avatar"].(string)
  4053. if len(avatar) == 0 {
  4054. utils.ErrorLog("len(avatar) == 0")
  4055. code = enums.ErrorCodeParamWrong
  4056. return
  4057. }
  4058. patient.Avatar = avatar
  4059. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4060. utils.ErrorLog("name")
  4061. code = enums.ErrorCodeParamWrong
  4062. return
  4063. }
  4064. name, _ := patientBody["name"].(string)
  4065. if len(name) == 0 {
  4066. utils.ErrorLog("len(name) == 0")
  4067. code = enums.ErrorCodeParamWrong
  4068. return
  4069. }
  4070. patient.Name = name
  4071. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4072. alias := patientBody["alias"].(string)
  4073. patient.Alias = alias
  4074. }
  4075. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4076. nation := patientBody["nation"].(string)
  4077. patient.Nation = nation
  4078. }
  4079. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4080. native_place := patientBody["native_place"].(string)
  4081. patient.NativePlace = native_place
  4082. }
  4083. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4084. utils.ErrorLog("idCardNo")
  4085. code = enums.ErrorCodeParamWrong
  4086. return
  4087. }
  4088. idCardNo, _ := patientBody["idCardNo"].(string)
  4089. if len(idCardNo) == 0 {
  4090. utils.ErrorLog("len(idCardNo) == 0")
  4091. code = enums.ErrorCodeParamWrong
  4092. return
  4093. }
  4094. patient.IdCardNo = idCardNo
  4095. patient.PatientType = 1
  4096. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4097. utils.ErrorLog("dialysisNo")
  4098. code = enums.ErrorCodeParamWrong
  4099. return
  4100. }
  4101. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4102. if len(dialysisNo) == 0 {
  4103. utils.ErrorLog("len(dialysisNo) == 0")
  4104. code = enums.ErrorCodeParamWrong
  4105. return
  4106. }
  4107. patient.DialysisNo = dialysisNo
  4108. // }
  4109. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4110. utils.ErrorLog("lapseto")
  4111. code = enums.ErrorCodeParamWrong
  4112. return
  4113. }
  4114. lapseto := int64(patientBody["lapseto"].(float64))
  4115. if lapseto <= 0 {
  4116. utils.ErrorLog("lapseto == 0")
  4117. code = enums.ErrorCodeParamWrong
  4118. return
  4119. }
  4120. patient.Lapseto = lapseto
  4121. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4122. utils.ErrorLog("gender")
  4123. code = enums.ErrorCodeParamWrong
  4124. return
  4125. }
  4126. gender := int64(patientBody["gender"].(float64))
  4127. if gender <= 0 {
  4128. utils.ErrorLog("gender <= 0")
  4129. code = enums.ErrorCodeParamWrong
  4130. return
  4131. }
  4132. patient.Gender = gender
  4133. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4134. response_result := patientBody["response_result"].(string)
  4135. patient.ResponseResult = response_result
  4136. }
  4137. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4138. utils.ErrorLog("age")
  4139. code = enums.ErrorCodeParamWrong
  4140. return
  4141. }
  4142. age := int64(patientBody["age"].(float64))
  4143. patient.Age = age
  4144. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4145. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4146. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4147. patient.UserSysBeforeCount = count
  4148. }
  4149. timeLayout := "2006-01-02"
  4150. loc, _ := time.LoadLocation("Local")
  4151. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4152. utils.ErrorLog("birth")
  4153. code = enums.ErrorCodeParamWrong
  4154. return
  4155. }
  4156. birth, _ := patientBody["birth"].(string)
  4157. if len(birth) == 0 {
  4158. utils.ErrorLog("len(birth) == 0")
  4159. code = enums.ErrorCodeParamWrong
  4160. return
  4161. }
  4162. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4163. if err != nil {
  4164. utils.ErrorLog("birthTime")
  4165. code = enums.ErrorCodeParamWrong
  4166. return
  4167. }
  4168. patient.Birthday = birthTime.Unix()
  4169. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4170. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4171. patient.Height = height
  4172. }
  4173. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4174. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4175. patient.MaritalStatus = maritalStatus
  4176. }
  4177. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4178. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4179. patient.Children = children
  4180. }
  4181. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4182. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4183. patient.AdmissionNumber = admissionNumber
  4184. }
  4185. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4186. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4187. patient.ReimbursementWayId = reimbursementWayID
  4188. }
  4189. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4190. healthCareNo := patientBody["healthCareNo"].(string)
  4191. patient.HealthCareNo = healthCareNo
  4192. }
  4193. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4194. utils.ErrorLog("phone")
  4195. code = enums.ErrorCodeParamWrong
  4196. return
  4197. }
  4198. phone := patientBody["phone"].(string)
  4199. if len(phone) == 0 {
  4200. utils.ErrorLog("len(phone) == 0")
  4201. code = enums.ErrorCodeParamWrong
  4202. return
  4203. }
  4204. if !utils.CheckMobile(phone) {
  4205. utils.ErrorLog("!phone")
  4206. code = enums.ErrorCodeMobileFormat
  4207. return
  4208. }
  4209. patient.Phone = phone
  4210. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4211. homeTelephone := patientBody["homeTelephone"].(string)
  4212. patient.HomeTelephone = homeTelephone
  4213. }
  4214. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4215. relativePhone := patientBody["relative_phone"].(string)
  4216. patient.RelativePhone = relativePhone
  4217. }
  4218. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4219. relativeRelations := patientBody["relative_relations"].(string)
  4220. patient.RelativeRelations = relativeRelations
  4221. }
  4222. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4223. homeAddress := patientBody["homeAddress"].(string)
  4224. patient.HomeAddress = homeAddress
  4225. }
  4226. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4227. work := patientBody["work"].(string)
  4228. patient.WorkUnit = work
  4229. }
  4230. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4231. unitAddress := patientBody["unit_address"].(string)
  4232. patient.UnitAddress = unitAddress
  4233. }
  4234. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4235. profession := int64(patientBody["profession"].(float64))
  4236. patient.Profession = profession
  4237. }
  4238. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4239. education := int64(patientBody["education"].(float64))
  4240. patient.EducationLevel = education
  4241. }
  4242. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4243. utils.ErrorLog("source")
  4244. code = enums.ErrorCodeParamWrong
  4245. return
  4246. }
  4247. source := int64(patientBody["source"].(float64))
  4248. if source <= 0 {
  4249. utils.ErrorLog("source <= 0")
  4250. code = enums.ErrorCodeParamWrong
  4251. return
  4252. }
  4253. patient.Source = source
  4254. zb_patient_id := patientBody["zb_patient_id"].(string)
  4255. patient.ZbPatientId = zb_patient_id
  4256. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4257. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4258. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4259. }
  4260. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4261. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4262. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4263. if err == nil {
  4264. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4265. }
  4266. }
  4267. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4268. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4269. patient.FirstDialysisHospital = firstDialysisHospital
  4270. }
  4271. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4272. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4273. if len(thePredialysisCondition) > 0 {
  4274. conditions := make([]string, 0)
  4275. for _, item := range thePredialysisCondition {
  4276. if reflect.TypeOf(item).String() != "string" {
  4277. continue
  4278. }
  4279. condition := item.(string)
  4280. if len(condition) > 0 {
  4281. conditions = append(conditions, condition)
  4282. }
  4283. }
  4284. patient.PredialysisCondition = strings.Join(conditions, ",")
  4285. }
  4286. }
  4287. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4288. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4289. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4290. }
  4291. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4292. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4293. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4294. }
  4295. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4296. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4297. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4298. if err == nil {
  4299. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4300. }
  4301. }
  4302. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4303. partition := int64(patientBody["partition"].(float64))
  4304. patient.PartitionId = partition
  4305. }
  4306. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4307. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4308. patient.BedId = bed
  4309. }
  4310. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4311. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4312. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4313. if err == nil {
  4314. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4315. }
  4316. }
  4317. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4318. blood := int64(patientBody["blood"].(float64))
  4319. patient.BloodType = blood
  4320. }
  4321. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4322. rh := int64(patientBody["rh"].(float64))
  4323. patient.Rh = rh
  4324. }
  4325. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4326. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4327. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4328. if err == nil {
  4329. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4330. }
  4331. }
  4332. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4333. receivingDate := patientBody["receivingDate"].(string)
  4334. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4335. if err == nil {
  4336. patient.ReceivingDate = receivingDateTime.Unix()
  4337. }
  4338. }
  4339. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4340. induction := int64(patientBody["induction"].(float64))
  4341. patient.InductionPeriod = induction
  4342. }
  4343. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4344. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4345. patient.InitialDialysis = initial
  4346. }
  4347. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4348. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4349. patient.TotalDialysis = dialysisTotal
  4350. }
  4351. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4352. thisContagions, _ := patientBody["contagions"].([]interface{})
  4353. if len(thisContagions) > 0 {
  4354. for _, item := range thisContagions {
  4355. if reflect.TypeOf(item).String() != "float64" {
  4356. continue
  4357. }
  4358. contagion := int64(item.(float64))
  4359. if contagion > 0 {
  4360. contagions = append(contagions, contagion)
  4361. }
  4362. }
  4363. }
  4364. }
  4365. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4366. doctor := int64(patientBody["doctor"].(float64))
  4367. patient.AttendingDoctorId = doctor
  4368. }
  4369. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4370. nurse := int64(patientBody["nurse"].(float64))
  4371. patient.HeadNurseId = nurse
  4372. }
  4373. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4374. assessment := patientBody["assessment"].(string)
  4375. patient.Evaluate = assessment
  4376. }
  4377. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4378. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4379. if len(thisDiseases) > 0 {
  4380. for _, item := range thisDiseases {
  4381. if reflect.TypeOf(item).String() != "float64" {
  4382. continue
  4383. }
  4384. disease := int64(item.(float64))
  4385. if disease > 0 {
  4386. diseases = append(diseases, disease)
  4387. }
  4388. }
  4389. }
  4390. }
  4391. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4392. diagnose := patientBody["diagnose"].(string)
  4393. patient.Diagnose = diagnose
  4394. }
  4395. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4396. remark := patientBody["remark"].(string)
  4397. patient.Remark = remark
  4398. }
  4399. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4400. sch_remark := patientBody["sch_remark"].(string)
  4401. patient.SchRemark = sch_remark
  4402. }
  4403. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4404. patient_complains := patientBody["patient_complains"].(string)
  4405. patient.PatientComplains = patient_complains
  4406. }
  4407. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4408. present_history := patientBody["present_history"].(string)
  4409. patient.PresentHistory = present_history
  4410. }
  4411. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4412. past_history := patientBody["past_history"].(string)
  4413. patient.PastHistory = past_history
  4414. }
  4415. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4416. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4417. patient.Temperature = temperature
  4418. }
  4419. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4420. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4421. patient.Pulse = pulse
  4422. }
  4423. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4424. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4425. patient.Respiratory = respiratory
  4426. }
  4427. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4428. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4429. patient.SBP = sbp
  4430. }
  4431. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4432. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4433. patient.DBP = dbp
  4434. }
  4435. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4436. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4437. patient.DialysisAge = dialysis_age
  4438. }
  4439. fmt.Println(patient.DialysisAge)
  4440. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4441. first_treatment_date := patientBody["first_treatment_date"].(string)
  4442. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4443. if err == nil {
  4444. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4445. }
  4446. }
  4447. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4448. expense_kind := int64(patientBody["expense_kind"].(float64))
  4449. patient.ExpenseKind = expense_kind
  4450. }
  4451. fmt.Println(patient.ExpenseKind)
  4452. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4453. tell_phone := patientBody["tell_phone"].(string)
  4454. patient.TellPhone = tell_phone
  4455. }
  4456. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4457. contact_name := patientBody["contact_name"].(string)
  4458. patient.ContactName = contact_name
  4459. }
  4460. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4461. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4462. patient.TrobleShoot = troble_shoot
  4463. }
  4464. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4465. treatment_plan := patientBody["treatment_plan"].(string)
  4466. patient.TreatmentPlan = treatment_plan
  4467. }
  4468. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4469. doctor := int64(patientBody["doctor"].(float64))
  4470. patient.Doctor = doctor
  4471. }
  4472. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4473. record_number := patientBody["record_number"].(string)
  4474. patient.RecordNumber = record_number
  4475. }
  4476. patient_source := int64(patientBody["patient_source"].(float64))
  4477. if patient_source <= 0 {
  4478. utils.ErrorLog("patient_source <= 0")
  4479. code = enums.ErrorCodeParamWrong
  4480. return
  4481. }
  4482. patient.PatientSource = patient_source
  4483. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4484. patient_start_time := patientBody["patient_start_time"].(string)
  4485. var startTime int64
  4486. if len(patient_start_time) > 0 {
  4487. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4488. startTime = theTime.Unix()
  4489. }
  4490. patient.PatientStartTime = startTime
  4491. }
  4492. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4493. patient_end_time := patientBody["patient_end_time"].(string)
  4494. var endTime int64
  4495. if len(patient_end_time) > 0 {
  4496. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4497. endTime = theTime.Unix()
  4498. }
  4499. patient.PatientEndTime = endTime
  4500. }
  4501. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4502. record_number := patientBody["infectious_remark"].(string)
  4503. patient.InfectiousRemark = record_number
  4504. }
  4505. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4506. allergic_history := patientBody["allergic_history"].(string)
  4507. patient.AllergicHistory = allergic_history
  4508. }
  4509. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4510. patient_address := patientBody["patient_address"].(string)
  4511. patient.PatientAddress = patient_address
  4512. }
  4513. return
  4514. }
  4515. func (c *PatientApiController) GetPatientsByKeyWord() {
  4516. keyWord := c.GetString("keyword")
  4517. adminUserInfo := c.GetAdminUserInfo()
  4518. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4519. if err != nil {
  4520. utils.ErrorLog(err.Error())
  4521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4522. return
  4523. }
  4524. c.ServeSuccessJSON(map[string]interface{}{
  4525. "patient": patient,
  4526. })
  4527. }
  4528. func (c *PatientApiController) QueryPatientById() {
  4529. id, _ := c.GetInt64("id")
  4530. fmt.Println(id)
  4531. patientInfo := service.QueryPatientById(id)
  4532. c.ServeSuccessJSON(map[string]interface{}{
  4533. "patient": patientInfo,
  4534. })
  4535. return
  4536. }
  4537. func (c *PatientApiController) GetRemindPatientList() {
  4538. page, _ := c.GetInt64("page", 1)
  4539. limit, _ := c.GetInt64("limit", 10)
  4540. adminUserInfo := c.GetAdminUserInfo()
  4541. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4542. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4543. if errcode == gorm.ErrRecordNotFound {
  4544. information, err := service.GetAdminUserRoleInformation(0)
  4545. if err != nil {
  4546. utils.ErrorLog(err.Error())
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4548. return
  4549. }
  4550. c.ServeSuccessJSON(map[string]interface{}{
  4551. "total": total,
  4552. "patients": patients,
  4553. "information": information,
  4554. })
  4555. } else if errcode == nil {
  4556. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4557. if err != nil {
  4558. utils.ErrorLog(err.Error())
  4559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4560. return
  4561. }
  4562. c.ServeSuccessJSON(map[string]interface{}{
  4563. "total": total,
  4564. "patients": patients,
  4565. "information": information,
  4566. })
  4567. }
  4568. }
  4569. func (c *PatientApiController) PostIsOpenRemind() {
  4570. patient_id, _ := c.GetInt64("id", 1)
  4571. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4572. adminUserInfo := c.GetAdminUserInfo()
  4573. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4574. if err == nil {
  4575. c.ServeSuccessJSON(map[string]interface{}{
  4576. "msg": "成功",
  4577. "is_open_remind": is_open_remind,
  4578. })
  4579. } else if err != nil {
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4581. }
  4582. }
  4583. func (c *PatientApiController) GetPatientScheduleOne() {
  4584. id, _ := c.GetInt64("id")
  4585. //查询该病人是否当天是排班
  4586. nowDateTime := time.Now()
  4587. nowDate := nowDateTime.Format("2006-01-02")
  4588. nowDate += " 00:00:00"
  4589. timeLayout := "2006-01-02"
  4590. loc, _ := time.LoadLocation("Local")
  4591. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4592. nowdate := theTime.Unix()
  4593. fmt.Println("nowdate", nowdate)
  4594. adminUser := c.GetAdminUserInfo()
  4595. orgId := adminUser.CurrentOrgId
  4596. fmt.Println("orgid", orgId)
  4597. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4598. if err != nil {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4600. return
  4601. }
  4602. c.ServeSuccessJSON(map[string]interface{}{
  4603. "scheduls": scheduls,
  4604. })
  4605. }
  4606. func (c *PatientApiController) ExportPatients() {
  4607. dataBody := make(map[string]interface{}, 0)
  4608. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4609. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4610. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4611. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4612. if err != nil {
  4613. utils.ErrorLog(err.Error())
  4614. return
  4615. }
  4616. utils.ErrorLog("%v", dataBody)
  4617. export_time := time.Now().Unix()
  4618. var patients []*models.Patients
  4619. var total_patients []interface{}
  4620. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4621. tempPatients := dataBody["patients"].([]interface{})
  4622. total_patients = tempPatients
  4623. for index, patientMap := range tempPatients {
  4624. patientNameM := patientMap.(map[string]interface{})
  4625. var patient models.Patients
  4626. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4627. utils.ErrorLog("name")
  4628. return
  4629. }
  4630. name, _ := patientNameM["name"].(string)
  4631. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4632. err_log := models.ExportErrLog{
  4633. LogType: 1,
  4634. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4635. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4636. Status: 1,
  4637. CreateTime: time.Now().Unix(),
  4638. UpdateTime: time.Now().Unix(),
  4639. ExportTime: export_time,
  4640. }
  4641. service.CreateExportErrLog(&err_log)
  4642. continue
  4643. }
  4644. patient.Name = name
  4645. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4646. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4647. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4648. err_log := models.ExportErrLog{
  4649. LogType: 1,
  4650. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4651. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4652. Status: 1,
  4653. CreateTime: time.Now().Unix(),
  4654. UpdateTime: time.Now().Unix(),
  4655. ExportTime: export_time,
  4656. }
  4657. service.CreateExportErrLog(&err_log)
  4658. continue
  4659. } else {
  4660. patient.Gender = gender
  4661. }
  4662. }
  4663. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4664. phone, _ := patientNameM["phone"].(string)
  4665. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4666. if len(phone) == 0 {
  4667. err_log := models.ExportErrLog{
  4668. LogType: 1,
  4669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4670. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4671. Status: 1,
  4672. CreateTime: time.Now().Unix(),
  4673. UpdateTime: time.Now().Unix(),
  4674. ExportTime: export_time,
  4675. }
  4676. service.CreateExportErrLog(&err_log)
  4677. continue
  4678. } else {
  4679. err_log := models.ExportErrLog{
  4680. LogType: 1,
  4681. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4682. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4683. Status: 1,
  4684. CreateTime: time.Now().Unix(),
  4685. UpdateTime: time.Now().Unix(),
  4686. ExportTime: export_time,
  4687. }
  4688. service.CreateExportErrLog(&err_log)
  4689. continue
  4690. }
  4691. } else {
  4692. //var tempPatient *models.Patients
  4693. //for _, item := range all_patient {
  4694. // if item.Phone == phone {
  4695. // tempPatient = item
  4696. // }
  4697. //}
  4698. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4699. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4700. if count >= 1 {
  4701. err_log := models.ExportErrLog{
  4702. LogType: 1,
  4703. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4704. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4705. Status: 1,
  4706. CreateTime: time.Now().Unix(),
  4707. UpdateTime: time.Now().Unix(),
  4708. ExportTime: export_time,
  4709. }
  4710. service.CreateExportErrLog(&err_log)
  4711. continue
  4712. }
  4713. patient.Phone = phone
  4714. }
  4715. }
  4716. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4717. id_card_no, _ := patientNameM["id_card_no"].(string)
  4718. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4719. if len(id_card_no) == 0 {
  4720. err_log := models.ExportErrLog{
  4721. LogType: 1,
  4722. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4723. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4724. Status: 1,
  4725. CreateTime: time.Now().Unix(),
  4726. UpdateTime: time.Now().Unix(),
  4727. ExportTime: export_time,
  4728. }
  4729. service.CreateExportErrLog(&err_log)
  4730. continue
  4731. } else {
  4732. err_log := models.ExportErrLog{
  4733. LogType: 1,
  4734. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4735. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4736. Status: 1,
  4737. CreateTime: time.Now().Unix(),
  4738. UpdateTime: time.Now().Unix(),
  4739. ExportTime: export_time,
  4740. }
  4741. service.CreateExportErrLog(&err_log)
  4742. continue
  4743. }
  4744. } else {
  4745. //var tempPatient *models.Patients
  4746. //for _, item := range all_patient {
  4747. // if item.IdCardNo == id_card_no {
  4748. // tempPatient = item
  4749. // }
  4750. //}
  4751. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4752. if count >= 1 {
  4753. //if tempPatient != nil && tempPatient.ID > 0 {
  4754. err_log := models.ExportErrLog{
  4755. LogType: 1,
  4756. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4757. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4758. Status: 1,
  4759. CreateTime: time.Now().Unix(),
  4760. UpdateTime: time.Now().Unix(),
  4761. ExportTime: export_time,
  4762. }
  4763. service.CreateExportErrLog(&err_log)
  4764. continue
  4765. }
  4766. //}
  4767. patient.IdCardNo = id_card_no
  4768. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4769. if GetBirthDay(id_card_no) == nil {
  4770. patient.Birthday = 0
  4771. } else {
  4772. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4773. }
  4774. }
  4775. }
  4776. fmt.Println("111112222")
  4777. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4778. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4779. timeLayout := "2006/01/02"
  4780. loc, _ := time.LoadLocation("Local")
  4781. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4782. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4783. if len(first_treatment_date) == 0 {
  4784. err_log := models.ExportErrLog{
  4785. LogType: 1,
  4786. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4787. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4788. Status: 1,
  4789. CreateTime: time.Now().Unix(),
  4790. UpdateTime: time.Now().Unix(),
  4791. ExportTime: export_time,
  4792. }
  4793. service.CreateExportErrLog(&err_log)
  4794. continue
  4795. } else {
  4796. err_log := models.ExportErrLog{
  4797. LogType: 1,
  4798. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4799. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4800. Status: 1,
  4801. CreateTime: time.Now().Unix(),
  4802. UpdateTime: time.Now().Unix(),
  4803. ExportTime: export_time,
  4804. }
  4805. service.CreateExportErrLog(&err_log)
  4806. continue
  4807. }
  4808. } else {
  4809. if len(first_treatment_date) == 0 {
  4810. err_log := models.ExportErrLog{
  4811. LogType: 1,
  4812. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4813. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4814. Status: 1,
  4815. CreateTime: time.Now().Unix(),
  4816. UpdateTime: time.Now().Unix(),
  4817. ExportTime: export_time,
  4818. }
  4819. service.CreateExportErrLog(&err_log)
  4820. continue
  4821. } else {
  4822. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4823. err_log := models.ExportErrLog{
  4824. LogType: 1,
  4825. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4826. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4827. Status: 1,
  4828. CreateTime: time.Now().Unix(),
  4829. UpdateTime: time.Now().Unix(),
  4830. ExportTime: export_time,
  4831. }
  4832. service.CreateExportErrLog(&err_log)
  4833. continue
  4834. } else {
  4835. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4836. }
  4837. }
  4838. }
  4839. }
  4840. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4841. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4842. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4843. err_log := models.ExportErrLog{
  4844. LogType: 1,
  4845. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4846. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4847. Status: 1,
  4848. CreateTime: time.Now().Unix(),
  4849. UpdateTime: time.Now().Unix(),
  4850. ExportTime: export_time,
  4851. }
  4852. service.CreateExportErrLog(&err_log)
  4853. continue
  4854. } else if source == 3 {
  4855. err_log := models.ExportErrLog{
  4856. LogType: 1,
  4857. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4858. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4859. Status: 1,
  4860. CreateTime: time.Now().Unix(),
  4861. UpdateTime: time.Now().Unix(),
  4862. ExportTime: export_time,
  4863. }
  4864. service.CreateExportErrLog(&err_log)
  4865. continue
  4866. } else {
  4867. patient.Source = source
  4868. }
  4869. }
  4870. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4871. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4872. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4873. err_log := models.ExportErrLog{
  4874. LogType: 1,
  4875. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4876. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4877. Status: 1,
  4878. CreateTime: time.Now().Unix(),
  4879. UpdateTime: time.Now().Unix(),
  4880. ExportTime: export_time,
  4881. }
  4882. service.CreateExportErrLog(&err_log)
  4883. continue
  4884. } else if lapseto == 3 {
  4885. err_log := models.ExportErrLog{
  4886. LogType: 1,
  4887. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4888. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4889. Status: 1,
  4890. CreateTime: time.Now().Unix(),
  4891. UpdateTime: time.Now().Unix(),
  4892. ExportTime: export_time,
  4893. }
  4894. service.CreateExportErrLog(&err_log)
  4895. continue
  4896. } else {
  4897. patient.Lapseto = lapseto
  4898. }
  4899. }
  4900. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4901. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4902. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4903. err_log := models.ExportErrLog{
  4904. LogType: 1,
  4905. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4906. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4907. Status: 1,
  4908. CreateTime: time.Now().Unix(),
  4909. UpdateTime: time.Now().Unix(),
  4910. ExportTime: export_time,
  4911. }
  4912. service.CreateExportErrLog(&err_log)
  4913. continue
  4914. } else if is_infectious == 3 {
  4915. err_log := models.ExportErrLog{
  4916. LogType: 1,
  4917. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4918. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4919. Status: 1,
  4920. CreateTime: time.Now().Unix(),
  4921. UpdateTime: time.Now().Unix(),
  4922. ExportTime: export_time,
  4923. }
  4924. service.CreateExportErrLog(&err_log)
  4925. continue
  4926. } else {
  4927. patient.IsInfectious = is_infectious
  4928. }
  4929. }
  4930. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4931. var contagions []int64
  4932. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4933. if len(thisContagions) > 0 {
  4934. for _, item := range thisContagions {
  4935. if reflect.TypeOf(item).String() != "float64" {
  4936. continue
  4937. }
  4938. contagion := int64(item.(float64))
  4939. if contagion > 0 {
  4940. contagions = append(contagions, contagion)
  4941. }
  4942. }
  4943. }
  4944. patient.ContagionIds = contagions
  4945. }
  4946. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4947. diagnose, _ := patientNameM["diagnose"].(string)
  4948. patient.Diagnose = diagnose
  4949. }
  4950. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4951. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4952. var tempPatient *models.Patients
  4953. for _, item := range all_patient {
  4954. if item.DialysisNo == dialysis_no {
  4955. tempPatient = item
  4956. }
  4957. }
  4958. if tempPatient != nil && tempPatient.ID > 0 {
  4959. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4960. } else {
  4961. patient.DialysisNo = dialysis_no
  4962. }
  4963. }
  4964. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4965. height, _ := patientNameM["height"].(string)
  4966. heights, _ := strconv.ParseFloat(height, 64)
  4967. patient.Height = int64(heights)
  4968. }
  4969. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4970. home_address, _ := patientNameM["home_address"].(string)
  4971. patient.HomeAddress = home_address
  4972. }
  4973. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  4974. dry_weight, _ := patientNameM["dry_weight"].(string)
  4975. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  4976. patient.DryWeight = dry_weights
  4977. }
  4978. patient.CreatedTime = time.Now().Unix()
  4979. patient.UpdatedTime = time.Now().Unix()
  4980. patient.Status = 1
  4981. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  4982. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  4983. patient.IsExcelExport = 1
  4984. patient.PatientType = 1
  4985. patients = append(patients, &patient)
  4986. }
  4987. }
  4988. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4989. if len(patients) > 0 {
  4990. for _, item := range patients {
  4991. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  4992. }
  4993. log := models.ExportLog{
  4994. LogType: 1,
  4995. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4996. TotalNum: int64(len(total_patients)),
  4997. FailNum: int64(len(errLogs)),
  4998. SuccessNum: int64(len(patients)),
  4999. CreateTime: time.Now().Unix(),
  5000. UpdateTime: time.Now().Unix(),
  5001. ExportTime: export_time,
  5002. Status: 1,
  5003. }
  5004. service.CreateExportLog(&log)
  5005. c.ServeSuccessJSON(map[string]interface{}{
  5006. "msg": "导入成功",
  5007. "total_num": len(total_patients),
  5008. "success_num": len(patients),
  5009. "fail_num": int64(len(errLogs)),
  5010. })
  5011. } else {
  5012. log := models.ExportLog{
  5013. LogType: 1,
  5014. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5015. TotalNum: int64(len(total_patients)),
  5016. FailNum: int64(len(errLogs)),
  5017. SuccessNum: int64(len(patients)),
  5018. CreateTime: time.Now().Unix(),
  5019. UpdateTime: time.Now().Unix(),
  5020. ExportTime: export_time,
  5021. Status: 1,
  5022. }
  5023. service.CreateExportLog(&log)
  5024. c.ServeSuccessJSON(map[string]interface{}{
  5025. "msg": "导入成功",
  5026. "total_num": len(total_patients),
  5027. "success_num": len(patients),
  5028. "fail_num": int64(len(errLogs)),
  5029. })
  5030. }
  5031. }
  5032. func GetBirthDay(IDCardNo string) *time.Time {
  5033. dayStr := IDCardNo[6:14]
  5034. birthDay, err := time.Parse("20060102", dayStr)
  5035. if err != nil {
  5036. fmt.Println(err)
  5037. return nil
  5038. }
  5039. return &birthDay
  5040. }
  5041. func IsIdCard(id string) (res bool) {
  5042. id = strings.ToUpper(id)
  5043. if len(id) != 15 && len(id) != 18 {
  5044. fmt.Println("1111111")
  5045. return false
  5046. }
  5047. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5048. if !r.MatchString(id) {
  5049. fmt.Println("222222")
  5050. return false
  5051. }
  5052. if len(id) == 15 {
  5053. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5054. if tm2.Unix() == 0 {
  5055. fmt.Println("44444443333")
  5056. return false
  5057. }
  5058. return true
  5059. } else {
  5060. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5061. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5062. fmt.Println(tm2.Unix())
  5063. if tm2.Unix() == 0 {
  5064. fmt.Println("44445555555")
  5065. return false
  5066. }
  5067. //检验18位身份证的校验码是否正确。
  5068. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5069. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5070. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5071. sign := 0
  5072. for k, v := range arr_int {
  5073. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5074. sign += int_temp * v
  5075. }
  5076. n := sign % 11
  5077. val_num := arr_ch[n]
  5078. if val_num != string([]byte(id)[17:18]) {
  5079. fmt.Println("5556666666")
  5080. return false
  5081. }
  5082. return true
  5083. }
  5084. }
  5085. func (c *PatientApiController) SaveEditAdvices() {
  5086. adminInfo := c.GetAdminUserInfo()
  5087. orgid := adminInfo.CurrentOrgId
  5088. startTime := c.GetString("start_time")
  5089. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5090. groupno, _ := c.GetInt64("groupno")
  5091. fmt.Println("组", groupno)
  5092. date, _ := c.GetInt64("date")
  5093. fmt.Println("date", date)
  5094. patient_id, _ := c.GetInt64("patient_id")
  5095. fmt.Println("paitent_id", patient_id)
  5096. advice := models.XtDoctorAdvice{
  5097. StartTime: theTime.Unix(),
  5098. }
  5099. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5100. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5101. redis := service.RedisClient()
  5102. redis.Set(key, "", time.Second)
  5103. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5104. redis.Set(keyOne, "", time.Second)
  5105. scheduleTime := theTime.Format("2006-01-02")
  5106. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5107. fmt.Println("keyFour323223323232323232", keyFour)
  5108. redis.Set(keyFour, "", time.Second)
  5109. defer redis.Close()
  5110. if err != nil {
  5111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5112. return
  5113. }
  5114. c.ServeSuccessJSON(map[string]interface{}{
  5115. "advice": advice,
  5116. })
  5117. }
  5118. func (c *PatientApiController) GetMaxDialysisNo() {
  5119. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5120. c.ServeSuccessJSON(map[string]interface{}{
  5121. "dialysis_no": dialysisNo,
  5122. })
  5123. }
  5124. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5125. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5126. var tempPatient *models.Patients
  5127. for _, item := range patients {
  5128. if item.DialysisNo == dialysisNo2 {
  5129. tempPatient = item
  5130. }
  5131. }
  5132. if tempPatient == nil || tempPatient.ID == 0 {
  5133. return dialysisNo2
  5134. }
  5135. return GenerateDialysisNoTwo(patients)
  5136. }
  5137. func (c *PatientApiController) GetBanner() {
  5138. orgId := c.GetAdminUserInfo().CurrentOrgId
  5139. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5140. if errcodes == gorm.ErrRecordNotFound {
  5141. information, err := service.GetAdminUserRoleInformation(0)
  5142. if err != nil {
  5143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5144. return
  5145. }
  5146. c.ServeSuccessJSON(map[string]interface{}{
  5147. "information": information,
  5148. })
  5149. } else if errcodes == nil {
  5150. information, err := service.GetAdminUserRoleInformation(orgId)
  5151. if err != nil {
  5152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5153. return
  5154. }
  5155. c.ServeSuccessJSON(map[string]interface{}{
  5156. "information": information,
  5157. })
  5158. }
  5159. }
  5160. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5161. patient_id, _ := c.GetInt64("id", 0)
  5162. page, _ := c.GetInt64("page", 0)
  5163. limit, _ := c.GetInt64("limit", 0)
  5164. if patient_id <= 0 {
  5165. c.ServeSuccessJSON(map[string]interface{}{
  5166. "solutions": nil,
  5167. })
  5168. return
  5169. }
  5170. if page <= 0 {
  5171. page = 1
  5172. }
  5173. if limit <= 0 {
  5174. limit = 10
  5175. }
  5176. adminUserInfo := c.GetAdminUserInfo()
  5177. //获取该患者分组的透析模式
  5178. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5179. for _, item := range list {
  5180. //获取该模式最新的1条数据
  5181. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5182. //更新状态值
  5183. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5184. }
  5185. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5186. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5187. if err != nil {
  5188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5189. return
  5190. }
  5191. c.ServeSuccessJSON(map[string]interface{}{
  5192. "solutions": solution,
  5193. "total": total,
  5194. "stockType": stockType,
  5195. })
  5196. }
  5197. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5198. patient_id, _ := c.GetInt64("patient_id")
  5199. mode_id, _ := c.GetInt64("mode_id")
  5200. page, _ := c.GetInt64("page")
  5201. limit, _ := c.GetInt64("limit")
  5202. orgId := c.GetAdminUserInfo().CurrentOrgId
  5203. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5204. if err != nil {
  5205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5206. return
  5207. }
  5208. c.ServeSuccessJSON(map[string]interface{}{
  5209. "list": list,
  5210. "total": total,
  5211. })
  5212. }