patient_api_controller.go 196KB

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