patient_api_controller.go 192KB

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