patient_api_controller.go 194KB

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