patient_api_controller.go 198KB

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