patient_api_controller.go 211KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. "github.com/jinzhu/gorm"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 && infor.WeekDay > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. record_date, _ := c.GetInt64("record_date")
  530. if origin != 2 {
  531. adminUserInfo := c.GetMobileAdminUserInfo()
  532. execution_staff := adminUserInfo.AdminUser.Id
  533. var ids []string
  534. advice_ids := c.GetString("advice_id")
  535. if groupno == 0 {
  536. ids = strings.Split(advice_ids, ",")
  537. }
  538. if groupno < 0 {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if len(execution_time) <= 0 {
  543. utils.ErrorLog("execution_time")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeLayout2 := "2006-01-02 15:04:05"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  550. if errs != nil {
  551. utils.ErrorLog(errs.Error())
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. var advice models.DoctorAdvice
  556. if groupno > 0 {
  557. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  558. for _, item := range advices {
  559. //恒泰中医院
  560. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  561. if item.DrugId == 0 || item.DrugNameId == 0 {
  562. //从字典里面查找
  563. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  564. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  565. }
  566. }
  567. if item.ExecutionState == 2 {
  568. advice = item
  569. }
  570. //记录日志
  571. byterequest, _ := json.Marshal(item)
  572. adviceLog := models.XtDoctorAdviceLog{
  573. UserOrgId: item.UserOrgId,
  574. PatientId: item.PatientId,
  575. AdminUserId: adminUserInfo.AdminUser.Id,
  576. Module: 2,
  577. ErrLog: string(byterequest),
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. Source: "手机端执行医嘱",
  582. RecordDate: item.AdviceDate,
  583. }
  584. service.CreateDoctorAdviceLog(adviceLog)
  585. }
  586. } else {
  587. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  588. for _, item := range advices {
  589. //恒泰中医院
  590. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  591. if item.DrugId == 0 || item.DrugNameId == 0 {
  592. //从字典里面查找
  593. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  594. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  595. }
  596. }
  597. if item.ExecutionState == 2 {
  598. advice = item
  599. }
  600. }
  601. }
  602. if advice.ExecutionState == 1 {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  604. return
  605. }
  606. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  608. return
  609. }
  610. //针对普宁
  611. if adminUserInfo.Org.Id != 10599 {
  612. if advice.StartTime > theTime.Unix() {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  614. return
  615. }
  616. }
  617. advices := models.DoctorAdvice{
  618. ExecutionStaff: execution_staff,
  619. ExecutionTime: theTime.Unix(),
  620. UpdatedTime: time.Now().Unix(),
  621. }
  622. var err error
  623. if groupno > 0 {
  624. // 查询信息规挡的设置天数
  625. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  626. if infor.ID > 0 && infor.WeekDay > 0 {
  627. var cha_time int64
  628. timeNowStr := time.Now().Format("2006-01-02")
  629. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  630. //今日的日期减去设置的日期
  631. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  632. if cha_time >= record_date {
  633. //查询审核是否允许
  634. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  635. //申请状态不允许的情况 拒绝修改
  636. if infor.ApplicationStatus != 1 {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  638. return
  639. }
  640. }
  641. }
  642. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  643. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  644. redis := service.RedisClient()
  645. //清空key 值
  646. redis.Set(key, "", time.Second)
  647. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  648. redis.Set(keyTwo, "", time.Second)
  649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  650. redis.Set(keyThree, "", time.Second)
  651. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  652. theTime := toTime.Format("2006-01-02")
  653. fmt.Println("theTIME", theTime)
  654. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyFour, "", time.Second)
  656. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  657. redis.Set(keyFive, "", time.Second)
  658. defer redis.Close()
  659. } else {
  660. // 查询信息规挡的设置天数
  661. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  662. if infor.ID > 0 {
  663. var cha_time int64
  664. timeNowStr := time.Now().Format("2006-01-02")
  665. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  666. //今日的日期减去设置的日期
  667. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  668. if cha_time >= record_date {
  669. //查询审核是否允许
  670. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  671. //申请状态不允许的情况 拒绝修改
  672. if infor.ApplicationStatus != 1 {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  674. return
  675. }
  676. }
  677. }
  678. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  679. //记录日志
  680. byterequest, _ := json.Marshal(advice)
  681. adviceLog := models.XtDoctorAdviceLog{
  682. UserOrgId: advice.UserOrgId,
  683. PatientId: advice.PatientId,
  684. AdminUserId: adminUserInfo.AdminUser.Id,
  685. Module: 2,
  686. ErrLog: string(byterequest),
  687. Status: 1,
  688. Ctime: time.Now().Unix(),
  689. Mtime: 0,
  690. Source: "手机端执行医嘱",
  691. RecordDate: advices.RecordDate,
  692. }
  693. service.CreateDoctorAdviceLog(adviceLog)
  694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  695. redis := service.RedisClient()
  696. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  697. redis.Set(keyTwo, "", time.Second)
  698. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  699. redis.Set(keyThree, "", time.Second)
  700. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  701. theTime := toTime.Format("2006-01-02")
  702. fmt.Println("theTIME", theTime)
  703. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  704. redis.Set(keyFour, "", time.Second)
  705. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  706. redis.Set(keySix, "", time.Second)
  707. defer redis.Close()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. }
  711. if err != nil {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  713. return
  714. }
  715. advice.ExecutionStaff = execution_staff
  716. advice.ExecutionTime = theTime.Unix()
  717. advice.ExecutionState = 1
  718. advice.Modifier = adminUserInfo.AdminUser.Id
  719. //处理出库相关逻辑
  720. //1.判断是否启用药品管理和自备药出库功能
  721. //药品管理信息
  722. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  723. //自备药信息
  724. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  725. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  726. if drugStockConfig.IsOpen == 1 {
  727. if groupno > 0 {
  728. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  729. if len(advices) > 0 {
  730. var total int64
  731. var prescribing_number_total int64
  732. //出库
  733. for _, item := range advices {
  734. if item.Way == 1 {
  735. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  736. //查询该药品的剩余库存
  737. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  738. //查询改药品信息
  739. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  740. //判断单位是否相等
  741. if medical.MaxUnit == item.PrescribingNumberUnit {
  742. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  743. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  744. //转化为最小单位
  745. total = list.Count * medical.MinNumber
  746. prescribing_number_total = count * medical.MinNumber
  747. }
  748. if medical.MinUnit == item.PrescribingNumberUnit {
  749. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  750. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  751. total = list.Count*medical.MinNumber + list.StockMinNumber
  752. prescribing_number_total = count
  753. }
  754. if medical.IsUse == 1 {
  755. c.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "1",
  757. "advice": advice,
  758. "ids": ids,
  759. })
  760. return
  761. }
  762. if medical.IsUse != 1 {
  763. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  764. if advice.UserOrgId != 10278 {
  765. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  766. advice.ExecutionTime = 0
  767. advice.ExecutionState = 2
  768. advice.ExecutionStaff = 0
  769. }
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "msg": "3",
  772. "advice": advice,
  773. "ids": ids,
  774. })
  775. return
  776. }
  777. if prescribing_number_total > total {
  778. if advice.UserOrgId != 10278 {
  779. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  780. advice.ExecutionTime = 0
  781. advice.ExecutionState = 2
  782. advice.ExecutionStaff = 0
  783. }
  784. c.ServeSuccessJSON(map[string]interface{}{
  785. "msg": "2",
  786. "advice": advice,
  787. "ids": ids,
  788. })
  789. return
  790. }
  791. }
  792. //查询是否出库按钮开启
  793. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  794. if adviceSetting.IsAdviceOpen == 1 {
  795. //查询是否出库按钮开启
  796. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  797. //患者发药
  798. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  799. if prescriptionConfig.IsOpen == 1 {
  800. if medical.IsUse == 2 {
  801. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  802. //查询今日是否出库
  803. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  804. if drugOutInfo.ID == 0 {
  805. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  806. }
  807. }
  808. if pharmacyConfig.IsOpen != 1 {
  809. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  810. if drugOutInfo.ID == 0 {
  811. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  812. }
  813. }
  814. //更新字典里面的库存
  815. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  816. var sum_count int64
  817. for _, its := range stockInfo {
  818. if its.MaxUnit == medical.MaxUnit {
  819. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  820. }
  821. sum_count += its.StockMaxNumber + its.StockMinNumber
  822. }
  823. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  824. //剩余库存
  825. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  826. }
  827. }
  828. } else {
  829. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  830. if medical.IsUse == 2 {
  831. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  832. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  833. if drugOutInfo.ID == 0 {
  834. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  835. }
  836. }
  837. if pharmacyConfig.IsOpen != 1 {
  838. drugError := models.XtDrugError{
  839. ID: 0,
  840. UserOrgId: item.UserOrgId,
  841. DrugId: item.DrugId,
  842. RecordDate: item.AdviceDate,
  843. PatientId: item.PatientId,
  844. Remark: "恒泰中医院出库开始",
  845. Status: 1,
  846. Ctime: time.Now().Unix(),
  847. Mtime: 0,
  848. Prescribingnumber: item.PrescribingNumber,
  849. PrescribingNumberUnit: item.PrescribingNumberUnit,
  850. SumCount: 0,
  851. }
  852. service.CreateDrugError(drugError)
  853. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  854. if drugOutInfo.ID == 0 {
  855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  856. }
  857. }
  858. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  859. var sum_count int64
  860. for _, its := range stockInfo {
  861. if its.MaxUnit == medical.MaxUnit {
  862. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  863. }
  864. sum_count += its.StockMaxNumber + its.StockMinNumber
  865. }
  866. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  867. //剩余库存
  868. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  869. }
  870. }
  871. }
  872. }
  873. }
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "msg": "1",
  876. "advice": advice,
  877. "ids": ids,
  878. })
  879. return
  880. } else {
  881. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  882. if len(advices) > 0 {
  883. var total int64
  884. var prescribing_number_total int64
  885. for _, item := range advices {
  886. if item.Way == 1 {
  887. //查询改药品信息
  888. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  889. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  890. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  891. //查询该药品的剩余库存
  892. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  893. //判断单位是否相等
  894. if medical.MaxUnit == item.PrescribingNumberUnit {
  895. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  896. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  897. //转化为最小单位
  898. total = list.Count*medical.MinNumber + list.StockMinNumber
  899. prescribing_number_total = count * medical.MinNumber
  900. }
  901. if medical.MinUnit == item.PrescribingNumberUnit {
  902. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  903. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  904. total = list.Count*medical.MinNumber + list.StockMinNumber
  905. prescribing_number_total = count
  906. }
  907. if medical.IsUse == 1 {
  908. c.ServeSuccessJSON(map[string]interface{}{
  909. "msg": "1",
  910. "advice": advice,
  911. "ids": ids,
  912. })
  913. return
  914. }
  915. if medical.IsUse != 1 {
  916. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  917. if advice.UserOrgId != 10278 {
  918. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  919. advice.ExecutionTime = 0
  920. advice.ExecutionState = 2
  921. advice.ExecutionStaff = 0
  922. }
  923. c.ServeSuccessJSON(map[string]interface{}{
  924. "msg": "3",
  925. "advice": advice,
  926. "ids": ids,
  927. })
  928. return
  929. }
  930. if prescribing_number_total > total {
  931. if advice.UserOrgId != 10278 {
  932. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  933. advice.ExecutionTime = 0
  934. advice.ExecutionState = 2
  935. advice.ExecutionStaff = 0
  936. }
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "msg": "2",
  939. "advice": advice,
  940. "ids": ids,
  941. })
  942. return
  943. }
  944. }
  945. if medical.IsUse == 2 {
  946. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  947. //查询今日是否出库
  948. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  949. if drugOutInfo.ID == 0 {
  950. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  951. }
  952. }
  953. if pharmacyConfig.IsOpen != 1 {
  954. //查询今日是否出库
  955. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  956. if drugOutInfo.ID == 0 {
  957. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  958. }
  959. }
  960. //更新字典里面的库存
  961. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  962. var sum_count int64
  963. for _, its := range stockInfo {
  964. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  965. if its.MaxUnit == baseDrug.MaxUnit {
  966. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  967. }
  968. sum_count += its.StockMaxNumber + its.StockMinNumber
  969. }
  970. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  971. //剩余库存
  972. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  973. }
  974. if medical.IsUse == 1 {
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "msg": "1",
  977. "advice": advice,
  978. "ids": ids,
  979. })
  980. return
  981. }
  982. }
  983. }
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "msg": "1",
  987. "advice": advice,
  988. "ids": ids,
  989. })
  990. return
  991. }
  992. }
  993. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  994. if groupno > 0 {
  995. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  996. for _, item := range advices {
  997. if item.ExecutionState == 1 && item.Way == 2 {
  998. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  999. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1000. timeStr := time.Now().Format("2006-01-02")
  1001. timeArr := strings.Split(timeStr, "-")
  1002. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1003. total = total + 1
  1004. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1005. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1006. number = number + total
  1007. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1008. //插入自备药出库单
  1009. outStock := models.XtSelfOutStock{
  1010. DrugName: item.AdviceName,
  1011. DrugNameId: item.DrugNameId,
  1012. DrugSpec: item.AdviceDesc,
  1013. OutstoreNumber: count,
  1014. AdminUserId: adminUserInfo.AdminUser.Id,
  1015. StorckTime: item.AdviceDate,
  1016. UserOrgId: adminUserInfo.Org.Id,
  1017. CreatedTime: time.Now().Unix(),
  1018. Status: 1,
  1019. PatientId: item.PatientId,
  1020. ExitMode: 2,
  1021. MedicId: item.DrugId,
  1022. StockOutNumber: warehousing_out_order,
  1023. }
  1024. //查询 该患者是否已出库
  1025. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1026. if errcode == gorm.ErrRecordNotFound {
  1027. service.CreateOutStock(&outStock)
  1028. } else if errcode == nil {
  1029. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1030. fmt.Println("err", err)
  1031. }
  1032. }
  1033. }
  1034. } else {
  1035. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1036. for _, item := range advices {
  1037. if item.ExecutionState == 1 && item.Way == 2 {
  1038. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1039. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1040. timeStr := time.Now().Format("2006-01-02")
  1041. timeArr := strings.Split(timeStr, "-")
  1042. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1043. total = total + 1
  1044. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1045. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1046. number = number + total
  1047. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1048. //插入自备药出库单
  1049. outStock := models.XtSelfOutStock{
  1050. DrugName: item.AdviceName,
  1051. DrugNameId: item.DrugNameId,
  1052. DrugSpec: item.AdviceDesc,
  1053. OutstoreNumber: count,
  1054. AdminUserId: adminUserInfo.AdminUser.Id,
  1055. StorckTime: item.AdviceDate,
  1056. UserOrgId: adminUserInfo.Org.Id,
  1057. CreatedTime: time.Now().Unix(),
  1058. Status: 1,
  1059. PatientId: item.PatientId,
  1060. ExitMode: 2,
  1061. MedicId: item.DrugId,
  1062. StockOutNumber: warehousing_out_order,
  1063. }
  1064. //查询 该患者是否已出库
  1065. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1066. if errcode == gorm.ErrRecordNotFound {
  1067. service.CreateOutStock(&outStock)
  1068. } else if errcode == nil {
  1069. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1070. fmt.Println("err", err)
  1071. }
  1072. }
  1073. }
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "msg": "1",
  1076. "advice": advice,
  1077. "ids": ids,
  1078. })
  1079. return
  1080. }
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "1",
  1084. "advice": advice,
  1085. "ids": ids,
  1086. })
  1087. return
  1088. } else if origin == 2 {
  1089. // 开始主事务
  1090. db := service.XTWriteDB()
  1091. tx := db.Begin()
  1092. // 在函数结束时处理事务回滚
  1093. defer func() {
  1094. if r := recover(); r != nil {
  1095. tx.Rollback()
  1096. }
  1097. }()
  1098. adminInfo := c.GetMobileAdminUserInfo()
  1099. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1100. var ids []string
  1101. advice_ids := c.GetString("advice_id")
  1102. ids = strings.Split(advice_ids, ",")
  1103. if len(execution_time) <= 0 {
  1104. utils.ErrorLog("execution_time")
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. timeLayout2 := "2006-01-02 15:04:05"
  1109. loc, _ := time.LoadLocation("Local")
  1110. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1111. if errs != nil {
  1112. utils.ErrorLog(errs.Error())
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1114. return
  1115. }
  1116. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1117. var err error
  1118. for _, item := range advices {
  1119. if item.ExecutionState == 1 {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1121. return
  1122. }
  1123. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1125. return
  1126. }
  1127. if item.StartTime > theTime.Unix() {
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1129. return
  1130. }
  1131. item.ExecutionState = 1
  1132. item.ExecutionStaff = adminInfo.AdminUser.Id
  1133. item.ExecutionTime = theTime.Unix()
  1134. item.IsMobile = 1
  1135. // 查询信息规挡的设置天数
  1136. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1137. if infor.ID > 0 {
  1138. var cha_time int64
  1139. timeNowStr := time.Now().Format("2006-01-02")
  1140. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1141. //今日的日期减去设置的日期
  1142. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1143. if cha_time >= item.AdviceDate {
  1144. //查询审核是否允许
  1145. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1146. //申请状态不允许的情况 拒绝修改
  1147. if infor.ApplicationStatus != 1 {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1149. return
  1150. }
  1151. }
  1152. }
  1153. //err = service.SaveHisDoctorAdvice(item)
  1154. service.SaveHisDoctorAdviceOne(item, tx)
  1155. //记录日志
  1156. byterequest, _ := json.Marshal(item)
  1157. adviceLog := models.XtDoctorAdviceLog{
  1158. UserOrgId: item.UserOrgId,
  1159. PatientId: item.PatientId,
  1160. AdminUserId: item.ExecutionStaff,
  1161. Module: 2,
  1162. ErrLog: string(byterequest),
  1163. Status: 1,
  1164. Ctime: time.Now().Unix(),
  1165. Mtime: 0,
  1166. Source: "手机端执行his医嘱",
  1167. RecordDate: item.AdviceDate,
  1168. }
  1169. service.CreateDoctorAdviceLog(adviceLog)
  1170. if err == nil {
  1171. drugError := models.XtDrugError{
  1172. UserOrgId: adminInfo.Org.Id,
  1173. DrugId: item.DrugId,
  1174. RecordDate: item.AdviceDate,
  1175. PatientId: item.PatientId,
  1176. Remark: "执行成功",
  1177. Status: 1,
  1178. Ctime: time.Now().Unix(),
  1179. Mtime: 0,
  1180. SumCount: 0,
  1181. Prescribingnumber: item.PrescribingNumber,
  1182. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1183. }
  1184. service.CreateDrugError(drugError)
  1185. }
  1186. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1187. redis := service.RedisClient()
  1188. //清空key 值
  1189. redis.Set(key, "", time.Second)
  1190. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1191. redis.Set(keyTwo, "", time.Second)
  1192. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1193. redis.Set(keyThree, "", time.Second)
  1194. recordDate := theTime.Format("2006-01-02")
  1195. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1196. redis.Set(keyFour, "", time.Second)
  1197. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1198. redis.Set(keyFive, "", time.Second)
  1199. defer redis.Close()
  1200. }
  1201. //药品管理信息
  1202. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1203. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1204. if drugStockConfig.IsOpen == 1 {
  1205. for _, item := range advices {
  1206. //查询改药品信息
  1207. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1208. //判断单位是否合格
  1209. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1210. //查询该药品是否有出库记录
  1211. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1212. if len(flowMap) == 0 {
  1213. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1214. if errs != nil {
  1215. drugError := models.XtDrugError{
  1216. UserOrgId: adminInfo.Org.Id,
  1217. DrugId: item.DrugId,
  1218. RecordDate: item.AdviceDate,
  1219. PatientId: item.PatientId,
  1220. Remark: "单位不统一,执行失败",
  1221. Status: 1,
  1222. Ctime: time.Now().Unix(),
  1223. Mtime: 0,
  1224. SumCount: 0,
  1225. Prescribingnumber: item.PrescribingNumber,
  1226. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1227. }
  1228. service.CreateDrugError(drugError)
  1229. }
  1230. }
  1231. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1232. tx.Commit()
  1233. c.ServeSuccessJSON(map[string]interface{}{
  1234. "msg": "7",
  1235. "advice": advice,
  1236. "ids": ids,
  1237. })
  1238. return
  1239. }
  1240. //查询这个患者这个患者这个药已经出库的所有数量
  1241. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1242. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1243. var total_count int64
  1244. var drug_count int64
  1245. for _, it := range advicelist {
  1246. if it.PrescribingNumberUnit == medical.MaxUnit {
  1247. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1248. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1249. total_count += prenumber * medical.MinNumber
  1250. }
  1251. if it.PrescribingNumberUnit == medical.MinUnit {
  1252. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1253. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1254. total_count += prenumber
  1255. }
  1256. }
  1257. for _, its := range drugoutlist {
  1258. if its.CountUnit == medical.MaxUnit {
  1259. drug_count += its.Count * medical.MinNumber
  1260. }
  1261. if its.CountUnit == medical.MinUnit {
  1262. drug_count += its.Count
  1263. }
  1264. }
  1265. if total_count == drug_count {
  1266. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1267. tx.Commit()
  1268. c.ServeSuccessJSON(map[string]interface{}{
  1269. "msg": "1",
  1270. "advice": advice,
  1271. "ids": ids,
  1272. })
  1273. return
  1274. }
  1275. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1276. var total int64
  1277. var prescribing_number_total int64
  1278. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1279. if config.IsOpen != 1 {
  1280. //查询该药品是否有库存
  1281. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1282. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1283. //判断单位是否相等
  1284. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1285. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1286. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1287. //转化为最小单位
  1288. total = list.Count*medical.MinNumber + list.StockMinNumber
  1289. prescribing_number_total = count * medical.MinNumber
  1290. }
  1291. //fmt.Println("医嘱开的数量", total)
  1292. if medical.MinUnit == advice.PrescribingNumberUnit {
  1293. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1294. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1295. total = list.Count*medical.MinNumber + list.StockMinNumber
  1296. prescribing_number_total = count
  1297. }
  1298. if medical.IsUse == 1 {
  1299. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1300. drugError := models.XtDrugError{
  1301. UserOrgId: adminInfo.Org.Id,
  1302. DrugId: item.DrugId,
  1303. RecordDate: item.AdviceDate,
  1304. PatientId: item.PatientId,
  1305. Remark: "零用药品库存不足",
  1306. Status: 1,
  1307. Ctime: time.Now().Unix(),
  1308. Mtime: 0,
  1309. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1310. Prescribingnumber: advice.PrescribingNumber,
  1311. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1312. }
  1313. service.CreateDrugError(drugError)
  1314. tx.Commit()
  1315. c.ServeSuccessJSON(map[string]interface{}{
  1316. "msg": "1",
  1317. "advice": advice,
  1318. "ids": ids,
  1319. })
  1320. return
  1321. }
  1322. }
  1323. if medical.IsUse != 1 {
  1324. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1325. drugError := models.XtDrugError{
  1326. UserOrgId: adminInfo.Org.Id,
  1327. DrugId: item.DrugId,
  1328. RecordDate: item.AdviceDate,
  1329. PatientId: item.PatientId,
  1330. Remark: "药品库存不足",
  1331. Status: 1,
  1332. Ctime: time.Now().Unix(),
  1333. Mtime: 0,
  1334. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1335. Prescribingnumber: advice.PrescribingNumber,
  1336. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1337. }
  1338. service.CreateDrugError(drugError)
  1339. tx.Commit()
  1340. c.ServeSuccessJSON(map[string]interface{}{
  1341. "msg": "3",
  1342. "advice": advice,
  1343. "ids": ids,
  1344. })
  1345. return
  1346. }
  1347. if prescribing_number_total > total {
  1348. drugError := models.XtDrugError{
  1349. UserOrgId: adminInfo.Org.Id,
  1350. DrugId: item.DrugId,
  1351. RecordDate: item.AdviceDate,
  1352. PatientId: item.PatientId,
  1353. Remark: "出库数量大于库存",
  1354. Status: 1,
  1355. Ctime: time.Now().Unix(),
  1356. Mtime: 0,
  1357. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1358. Prescribingnumber: advice.PrescribingNumber,
  1359. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1360. }
  1361. service.CreateDrugError(drugError)
  1362. tx.Commit()
  1363. c.ServeSuccessJSON(map[string]interface{}{
  1364. "msg": "2",
  1365. "advice": advice,
  1366. "ids": ids,
  1367. })
  1368. return
  1369. }
  1370. }
  1371. fmt.Println("hhahhahahahhhhhha", prescribing_number_total)
  1372. fmt.Println("total0000000000000", total)
  1373. fmt.Println("medical22222222222222", medical.IsUse)
  1374. fmt.Println("config.isp", config.IsOpen)
  1375. if prescribing_number_total <= total {
  1376. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1377. //判断药品是否零用
  1378. if medical.IsUse == 2 {
  1379. if config.IsOpen != 1 {
  1380. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1381. //service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
  1382. //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1383. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1384. //查询该药品是否有出库记录
  1385. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1386. if len(flowMap) == 0 {
  1387. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1388. if errs != nil {
  1389. drugError := models.XtDrugError{
  1390. UserOrgId: adminInfo.Org.Id,
  1391. DrugId: item.DrugId,
  1392. RecordDate: item.AdviceDate,
  1393. PatientId: item.PatientId,
  1394. Remark: "出库记录为空,更新执行人失败",
  1395. Status: 1,
  1396. Ctime: time.Now().Unix(),
  1397. Mtime: 0,
  1398. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1399. Prescribingnumber: advice.PrescribingNumber,
  1400. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1401. }
  1402. service.CreateDrugError(drugError)
  1403. }
  1404. tx.Commit()
  1405. c.ServeSuccessJSON(map[string]interface{}{
  1406. "msg": "6",
  1407. "advice": advice,
  1408. "ids": ids,
  1409. })
  1410. return
  1411. }
  1412. }
  1413. }
  1414. if pharmacyConfig.IsOpen != 1 {
  1415. //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1416. service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
  1417. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1418. //查询该药品是否有出库记录
  1419. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1420. if len(flowMap) == 0 {
  1421. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1422. if errs != nil {
  1423. drugError := models.XtDrugError{
  1424. UserOrgId: adminInfo.Org.Id,
  1425. DrugId: item.DrugId,
  1426. RecordDate: item.AdviceDate,
  1427. PatientId: item.PatientId,
  1428. Remark: "出库记录为空,更新执行人失败",
  1429. Status: 1,
  1430. Ctime: time.Now().Unix(),
  1431. Mtime: 0,
  1432. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1433. Prescribingnumber: advice.PrescribingNumber,
  1434. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1435. }
  1436. service.CreateDrugError(drugError)
  1437. }
  1438. tx.Commit()
  1439. c.ServeSuccessJSON(map[string]interface{}{
  1440. "msg": "6",
  1441. "advice": advice,
  1442. "ids": ids,
  1443. })
  1444. return
  1445. }
  1446. }
  1447. }
  1448. //更新字典里面的库存
  1449. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1450. var sum_count int64
  1451. for _, its := range stockInfo {
  1452. if its.MaxUnit == medical.MaxUnit {
  1453. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1454. }
  1455. sum_count += its.StockMaxNumber + its.StockMinNumber
  1456. }
  1457. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1458. //剩余库存
  1459. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1460. }
  1461. }
  1462. }
  1463. }
  1464. //fmt.Println("config+++++++++++", config.IsOpen)
  1465. //fmt.Println("config+++++++++++", item.UserOrgId)
  1466. //
  1467. //if config.IsOpen == 1 && item.UserOrgId == 10402 {
  1468. //
  1469. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1470. // //更新字典里面的库存
  1471. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1472. // var sum_count int64
  1473. // for _, its := range stockInfo {
  1474. // if its.MaxUnit == medical.MaxUnit {
  1475. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1476. // }
  1477. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1478. // }
  1479. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1480. // //剩余库存
  1481. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1482. //}
  1483. }
  1484. }
  1485. tx.Commit()
  1486. for _, item := range advices {
  1487. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1488. c.ServeSuccessJSON(map[string]interface{}{
  1489. "msg": "1",
  1490. "advice": advice,
  1491. "ids": ids,
  1492. })
  1493. }
  1494. }
  1495. }
  1496. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1497. execution_time := c.GetString("execution_time")
  1498. fmt.Println("execution_time", execution_time)
  1499. groupno, _ := c.GetInt64("groupno", -1)
  1500. //patient_id, _ := c.GetInt64("patient_id")
  1501. advice_date, _ := c.GetInt64("advice_date")
  1502. var ids []string
  1503. if groupno == 0 {
  1504. advice_ids := c.GetString("advice_id")
  1505. ids = strings.Split(advice_ids, ",")
  1506. }
  1507. if groupno < 0 {
  1508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1509. return
  1510. }
  1511. if len(execution_time) <= 0 {
  1512. utils.ErrorLog("execution_time")
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. timeLayout2 := "2006-01-02 15:04:05"
  1517. loc, _ := time.LoadLocation("Local")
  1518. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1519. if errs != nil {
  1520. utils.ErrorLog(errs.Error())
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1522. return
  1523. }
  1524. adminUserInfo := c.GetMobileAdminUserInfo()
  1525. var advice models.DoctorAdvice
  1526. if groupno > 0 {
  1527. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1528. for _, item := range advices {
  1529. if item.ExecutionState == 1 {
  1530. advice = item
  1531. }
  1532. }
  1533. } else {
  1534. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1535. for _, item := range advices {
  1536. if item.ExecutionState == 1 {
  1537. advice = item
  1538. }
  1539. }
  1540. }
  1541. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1542. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1543. // if getPermissionErr != nil {
  1544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1545. // return
  1546. // } else if headNursePermission == nil {
  1547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1548. // return
  1549. // }
  1550. //}
  1551. if advice.StartTime > theTime.Unix() {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1553. return
  1554. }
  1555. advices := models.DoctorAdvice{
  1556. ExecutionTime: theTime.Unix(),
  1557. UpdatedTime: time.Now().Unix(),
  1558. }
  1559. var err error
  1560. if groupno > 0 {
  1561. // 查询信息规挡的设置天数
  1562. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1563. if infor.ID > 0 {
  1564. var cha_time int64
  1565. timeNowStr := time.Now().Format("2006-01-02")
  1566. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1567. //今日的日期减去设置的日期
  1568. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1569. if cha_time >= advices.AdviceDate {
  1570. //查询审核是否允许
  1571. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1572. //申请状态不允许的情况 拒绝修改
  1573. if infor.ApplicationStatus != 1 {
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1575. return
  1576. }
  1577. }
  1578. }
  1579. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1580. //记录日志
  1581. byterequest, _ := json.Marshal(advices)
  1582. adviceLog := models.XtDoctorAdviceLog{
  1583. UserOrgId: adminUserInfo.Org.Id,
  1584. PatientId: advices.PatientId,
  1585. AdminUserId: adminUserInfo.AdminUser.Id,
  1586. Module: 1,
  1587. ErrLog: string(byterequest),
  1588. Status: 1,
  1589. Ctime: time.Now().Unix(),
  1590. Mtime: 0,
  1591. Source: "手机端编辑医嘱",
  1592. RecordDate: advices.AdviceDate,
  1593. }
  1594. service.CreateDoctorAdviceLog(adviceLog)
  1595. redis := service.RedisClient()
  1596. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1597. redis.Set(key, "", time.Second)
  1598. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1599. redis.Set(keyOne, "", time.Second)
  1600. defer redis.Close()
  1601. } else {
  1602. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1603. if infor.ID > 0 {
  1604. var cha_time int64
  1605. timeNowStr := time.Now().Format("2006-01-02")
  1606. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1607. //今日的日期减去设置的日期
  1608. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1609. if cha_time >= advices.AdviceDate {
  1610. //查询审核是否允许
  1611. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1612. //申请状态不允许的情况 拒绝修改
  1613. if infor.ApplicationStatus != 1 {
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1615. return
  1616. }
  1617. }
  1618. }
  1619. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1620. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1621. //记录日志
  1622. byterequest, _ := json.Marshal(advices)
  1623. adviceLog := models.XtDoctorAdviceLog{
  1624. UserOrgId: adminUserInfo.Org.Id,
  1625. PatientId: advices.PatientId,
  1626. AdminUserId: adminUserInfo.AdminUser.Id,
  1627. Module: 1,
  1628. ErrLog: string(byterequest),
  1629. Status: 1,
  1630. Ctime: time.Now().Unix(),
  1631. Mtime: 0,
  1632. Source: "手机端编辑执行医嘱",
  1633. RecordDate: advices.AdviceDate,
  1634. }
  1635. service.CreateDoctorAdviceLog(adviceLog)
  1636. redis := service.RedisClient()
  1637. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1638. redis.Set(key, "", time.Second)
  1639. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1640. redis.Set(keyOne, "", time.Second)
  1641. defer redis.Close()
  1642. }
  1643. //判断是否开启his
  1644. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1645. //如果开启去修改执行时间
  1646. if config.IsOpen == 1 {
  1647. advicesinfo := models.HisDoctorAdviceInfo{
  1648. ExecutionTime: theTime.Unix(),
  1649. UpdatedTime: time.Now().Unix(),
  1650. }
  1651. var advicehis models.HisDoctorAdviceInfo
  1652. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1653. //记录日志
  1654. byterequest, _ := json.Marshal(advicesinfo)
  1655. adviceLog := models.XtDoctorAdviceLog{
  1656. UserOrgId: adminUserInfo.Org.Id,
  1657. PatientId: advices.PatientId,
  1658. AdminUserId: adminUserInfo.AdminUser.Id,
  1659. Module: 1,
  1660. ErrLog: string(byterequest),
  1661. Status: 1,
  1662. Ctime: time.Now().Unix(),
  1663. Mtime: 0,
  1664. Source: "手机端his编辑医嘱",
  1665. RecordDate: advices.AdviceDate,
  1666. }
  1667. service.CreateDoctorAdviceLog(adviceLog)
  1668. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1669. for _, item := range his_advices {
  1670. if item.ExecutionState == 1 {
  1671. advicehis = item
  1672. }
  1673. }
  1674. redis := service.RedisClient()
  1675. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1676. redis.Set(keyThree, "", time.Second)
  1677. recordDate := theTime.Format("2006-01-02")
  1678. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1679. redis.Set(keyFour, "", time.Second)
  1680. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1681. redis.Set(keyFive, "", time.Second)
  1682. defer redis.Close()
  1683. project := models.HisPrescriptionProject{
  1684. ExecutionTime: theTime.Unix(),
  1685. Mtime: time.Now().Unix(),
  1686. }
  1687. service.ModifyHisPrescriptionProject(&project, ids)
  1688. //记录日志
  1689. projectquerst, _ := json.Marshal(project)
  1690. projectLog := models.XtDoctorAdviceLog{
  1691. UserOrgId: adminUserInfo.Org.Id,
  1692. PatientId: advices.PatientId,
  1693. AdminUserId: adminUserInfo.AdminUser.Id,
  1694. Module: 1,
  1695. ErrLog: string(projectquerst),
  1696. Status: 1,
  1697. Ctime: time.Now().Unix(),
  1698. Mtime: 0,
  1699. Source: "手机端his编辑项目医嘱",
  1700. RecordDate: advices.AdviceDate,
  1701. }
  1702. service.CreateDoctorAdviceLog(projectLog)
  1703. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1704. redis.Set(keyEnd, "", time.Second)
  1705. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1706. redis.Set(keyFours, "", time.Second)
  1707. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1708. redis.Set(keyFives, "", time.Second)
  1709. defer redis.Close()
  1710. }
  1711. if err != nil {
  1712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1713. return
  1714. }
  1715. advice.ExecutionTime = theTime.Unix()
  1716. c.ServeSuccessJSON(map[string]interface{}{
  1717. "msg": "ok",
  1718. "advice": advice,
  1719. "ids": ids,
  1720. })
  1721. return
  1722. }
  1723. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  1724. origin, _ := c.GetInt64("origin", 0)
  1725. record_date, _ := c.GetInt64("record_date")
  1726. patient_id, _ := c.GetInt64("patient_id")
  1727. check_time := c.GetString("check_time")
  1728. if len(check_time) <= 0 {
  1729. utils.ErrorLog("check_time")
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1731. return
  1732. }
  1733. timeLayout2 := "2006-01-02 15:04:05"
  1734. loc, _ := time.LoadLocation("Local")
  1735. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  1736. fmt.Println("theTimewowowow", theTime)
  1737. if errs != nil {
  1738. utils.ErrorLog(errs.Error())
  1739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1740. return
  1741. }
  1742. if origin != 2 {
  1743. groupno, _ := c.GetInt64("groupno", -1)
  1744. var ids []string
  1745. if groupno == 0 {
  1746. advice_ids := c.GetString("advice_id")
  1747. if advice_ids == "" {
  1748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1749. return
  1750. } else {
  1751. ids = strings.Split(advice_ids, ",")
  1752. if len(ids) <= 0 {
  1753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1754. return
  1755. }
  1756. }
  1757. }
  1758. if groupno < 0 {
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1760. return
  1761. }
  1762. adminUserInfo := c.GetMobileAdminUserInfo()
  1763. var advice models.DoctorAdvice
  1764. if groupno > 0 {
  1765. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1766. for _, item := range advices {
  1767. if item.CheckState == 0 {
  1768. advice = item
  1769. }
  1770. //记录日志
  1771. byterequest, _ := json.Marshal(advices)
  1772. adviceLog := models.XtDoctorAdviceLog{
  1773. UserOrgId: adminUserInfo.Org.Id,
  1774. PatientId: item.PatientId,
  1775. AdminUserId: adminUserInfo.AdminUser.Id,
  1776. Module: 3,
  1777. ErrLog: string(byterequest),
  1778. Status: 1,
  1779. Ctime: time.Now().Unix(),
  1780. Mtime: 0,
  1781. Source: "手机端核对医嘱",
  1782. RecordDate: item.AdviceDate,
  1783. }
  1784. service.CreateDoctorAdviceLog(adviceLog)
  1785. }
  1786. if advice.CheckState == 1 {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1788. return
  1789. }
  1790. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1792. return
  1793. }
  1794. } else {
  1795. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1796. for _, item := range advices {
  1797. if item.CheckState == 0 {
  1798. advice = item
  1799. }
  1800. //记录日志
  1801. byterequest, _ := json.Marshal(advices)
  1802. adviceLog := models.XtDoctorAdviceLog{
  1803. UserOrgId: adminUserInfo.Org.Id,
  1804. PatientId: item.PatientId,
  1805. AdminUserId: adminUserInfo.AdminUser.Id,
  1806. Module: 3,
  1807. ErrLog: string(byterequest),
  1808. Status: 1,
  1809. Ctime: time.Now().Unix(),
  1810. Mtime: 0,
  1811. Source: "手机端核对医嘱",
  1812. RecordDate: item.AdviceDate,
  1813. }
  1814. service.CreateDoctorAdviceLog(adviceLog)
  1815. }
  1816. if advice.CheckState == 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1818. return
  1819. }
  1820. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1822. return
  1823. }
  1824. }
  1825. checker := adminUserInfo.AdminUser.Id
  1826. advices := models.DoctorAdvice{
  1827. CheckTime: theTime.Unix(),
  1828. Checker: checker,
  1829. UpdatedTime: time.Now().Unix(),
  1830. }
  1831. fmt.Println("groupnowowowowoowowow", groupno)
  1832. var err error
  1833. if groupno > 0 {
  1834. // 查询信息规挡的设置天数
  1835. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1836. if infor.ID > 0 && infor.WeekDay > 0 {
  1837. var cha_time int64
  1838. timeNowStr := time.Now().Format("2006-01-02")
  1839. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1840. //今日的日期减去设置的日期
  1841. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1842. if cha_time >= record_date {
  1843. //查询审核是否允许
  1844. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  1845. //申请状态不允许的情况 拒绝修改
  1846. if infor.ApplicationStatus != 1 {
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1848. return
  1849. }
  1850. }
  1851. }
  1852. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  1853. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1854. redis := service.RedisClient()
  1855. //清空key 值
  1856. redis.Set(key, "", time.Second)
  1857. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1858. redis.Set(keyTwo, "", time.Second)
  1859. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1860. redis.Set(keyThree, "", time.Second)
  1861. recordDate := theTime.Format("2006-01-02")
  1862. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1863. redis.Set(keyFour, "", time.Second)
  1864. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1865. redis.Set(keyFive, "", time.Second)
  1866. defer redis.Close()
  1867. } else {
  1868. if len(ids[0]) <= 0 {
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1870. return
  1871. } else {
  1872. //t := time.Now().Format("2006-01-02")/**/
  1873. //timeLayout2 := "2006-01-02"
  1874. //loc, _ := time.LoadLocation("Local")
  1875. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1876. // 查询信息规挡的设置天数
  1877. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1878. if infor.ID > 0 {
  1879. var cha_time int64
  1880. timeNowStr := time.Now().Format("2006-01-02")
  1881. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1882. //今日的日期减去设置的日期
  1883. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1884. if cha_time >= advices.AdviceDate {
  1885. //查询审核是否允许
  1886. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1887. //申请状态不允许的情况 拒绝修改
  1888. if infor.ApplicationStatus != 1 {
  1889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1890. return
  1891. }
  1892. }
  1893. }
  1894. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1895. //记录日志
  1896. byterequest, _ := json.Marshal(advices)
  1897. adviceLog := models.XtDoctorAdviceLog{
  1898. UserOrgId: adminUserInfo.Org.Id,
  1899. PatientId: advices.PatientId,
  1900. AdminUserId: advices.Checker,
  1901. Module: 3,
  1902. ErrLog: string(byterequest),
  1903. Status: 1,
  1904. Ctime: time.Now().Unix(),
  1905. Mtime: 0,
  1906. Source: "手机端核对医嘱",
  1907. RecordDate: advices.AdviceDate,
  1908. }
  1909. service.CreateDoctorAdviceLog(adviceLog)
  1910. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1911. redis := service.RedisClient()
  1912. //清空key 值
  1913. redis.Set(key, "", time.Second)
  1914. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1915. redis.Set(keyTwo, "", time.Second)
  1916. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1917. redis.Set(keyThree, "", time.Second)
  1918. recordDate := theTime.Format("2006-01-02")
  1919. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1920. redis.Set(keyFour, "", time.Second)
  1921. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1922. redis.Set(keyFive, "", time.Second)
  1923. defer redis.Close()
  1924. }
  1925. }
  1926. if err != nil {
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1928. return
  1929. }
  1930. advice.Checker = checker
  1931. advice.CheckTime = theTime.Unix()
  1932. advice.CheckState = 1
  1933. c.ServeSuccessJSON(map[string]interface{}{
  1934. "msg": "ok",
  1935. "advice": advice,
  1936. })
  1937. }
  1938. return
  1939. }
  1940. func (c *PatientApiController) CheckDoctorAdvice() {
  1941. origin, _ := c.GetInt64("origin", 0)
  1942. record_date, _ := c.GetInt64("record_date")
  1943. patient_id, _ := c.GetInt64("patient_id")
  1944. if origin != 2 {
  1945. groupno, _ := c.GetInt64("groupno", -1)
  1946. var ids []string
  1947. if groupno == 0 {
  1948. advice_ids := c.GetString("advice_id")
  1949. if advice_ids == "" {
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. } else {
  1953. ids = strings.Split(advice_ids, ",")
  1954. if len(ids) <= 0 {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1956. return
  1957. }
  1958. }
  1959. }
  1960. if groupno < 0 {
  1961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1962. return
  1963. }
  1964. adminUserInfo := c.GetMobileAdminUserInfo()
  1965. var advice models.DoctorAdvice
  1966. if groupno > 0 {
  1967. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1968. for _, item := range advices {
  1969. if item.CheckState == 0 {
  1970. advice = item
  1971. }
  1972. //记录日志
  1973. byterequest, _ := json.Marshal(advices)
  1974. adviceLog := models.XtDoctorAdviceLog{
  1975. UserOrgId: adminUserInfo.Org.Id,
  1976. PatientId: item.PatientId,
  1977. AdminUserId: adminUserInfo.AdminUser.Id,
  1978. Module: 3,
  1979. ErrLog: string(byterequest),
  1980. Status: 1,
  1981. Ctime: time.Now().Unix(),
  1982. Mtime: 0,
  1983. Source: "手机端核对医嘱",
  1984. RecordDate: item.AdviceDate,
  1985. }
  1986. service.CreateDoctorAdviceLog(adviceLog)
  1987. }
  1988. if advice.CheckState == 1 {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1990. return
  1991. }
  1992. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1994. return
  1995. }
  1996. } else {
  1997. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1998. for _, item := range advices {
  1999. if item.CheckState == 0 {
  2000. advice = item
  2001. }
  2002. //记录日志
  2003. byterequest, _ := json.Marshal(advices)
  2004. adviceLog := models.XtDoctorAdviceLog{
  2005. UserOrgId: adminUserInfo.Org.Id,
  2006. PatientId: item.PatientId,
  2007. AdminUserId: adminUserInfo.AdminUser.Id,
  2008. Module: 3,
  2009. ErrLog: string(byterequest),
  2010. Status: 1,
  2011. Ctime: time.Now().Unix(),
  2012. Mtime: 0,
  2013. Source: "手机端核对医嘱",
  2014. RecordDate: item.AdviceDate,
  2015. }
  2016. service.CreateDoctorAdviceLog(adviceLog)
  2017. }
  2018. if advice.CheckState == 1 {
  2019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2020. return
  2021. }
  2022. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2024. return
  2025. }
  2026. }
  2027. checker := adminUserInfo.AdminUser.Id
  2028. theTime := time.Now()
  2029. advices := models.DoctorAdvice{
  2030. CheckTime: theTime.Unix(),
  2031. Checker: checker,
  2032. UpdatedTime: time.Now().Unix(),
  2033. }
  2034. var err error
  2035. if groupno > 0 {
  2036. // 查询信息规挡的设置天数
  2037. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2038. if infor.ID > 0 && infor.WeekDay > 0 {
  2039. var cha_time int64
  2040. timeNowStr := time.Now().Format("2006-01-02")
  2041. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2042. //今日的日期减去设置的日期
  2043. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2044. if cha_time >= record_date {
  2045. //查询审核是否允许
  2046. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2047. //申请状态不允许的情况 拒绝修改
  2048. if infor.ApplicationStatus != 1 {
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2050. return
  2051. }
  2052. }
  2053. }
  2054. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2055. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2056. redis := service.RedisClient()
  2057. //清空key 值
  2058. redis.Set(key, "", time.Second)
  2059. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2060. redis.Set(keyTwo, "", time.Second)
  2061. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2062. redis.Set(keyThree, "", time.Second)
  2063. recordDate := theTime.Format("2006-01-02")
  2064. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. redis.Set(keyFour, "", time.Second)
  2066. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2067. redis.Set(keyFive, "", time.Second)
  2068. defer redis.Close()
  2069. } else {
  2070. if len(ids[0]) <= 0 {
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2072. return
  2073. } else {
  2074. //t := time.Now().Format("2006-01-02")/**/
  2075. //timeLayout2 := "2006-01-02"
  2076. //loc, _ := time.LoadLocation("Local")
  2077. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2078. // 查询信息规挡的设置天数
  2079. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2080. if infor.ID > 0 {
  2081. var cha_time int64
  2082. timeNowStr := time.Now().Format("2006-01-02")
  2083. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2084. //今日的日期减去设置的日期
  2085. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2086. if cha_time >= advices.AdviceDate {
  2087. //查询审核是否允许
  2088. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2089. //申请状态不允许的情况 拒绝修改
  2090. if infor.ApplicationStatus != 1 {
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2097. //记录日志
  2098. byterequest, _ := json.Marshal(advices)
  2099. adviceLog := models.XtDoctorAdviceLog{
  2100. UserOrgId: adminUserInfo.Org.Id,
  2101. PatientId: advices.PatientId,
  2102. AdminUserId: advices.Checker,
  2103. Module: 3,
  2104. ErrLog: string(byterequest),
  2105. Status: 1,
  2106. Ctime: time.Now().Unix(),
  2107. Mtime: 0,
  2108. Source: "手机端核对医嘱",
  2109. RecordDate: advices.AdviceDate,
  2110. }
  2111. service.CreateDoctorAdviceLog(adviceLog)
  2112. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2113. redis := service.RedisClient()
  2114. //清空key 值
  2115. redis.Set(key, "", time.Second)
  2116. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2117. redis.Set(keyTwo, "", time.Second)
  2118. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2119. redis.Set(keyThree, "", time.Second)
  2120. recordDate := theTime.Format("2006-01-02")
  2121. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2122. redis.Set(keyFour, "", time.Second)
  2123. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2124. redis.Set(keyFive, "", time.Second)
  2125. defer redis.Close()
  2126. }
  2127. }
  2128. if err != nil {
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2130. return
  2131. }
  2132. advice.Checker = checker
  2133. advice.CheckTime = theTime.Unix()
  2134. advice.CheckState = 1
  2135. c.ServeSuccessJSON(map[string]interface{}{
  2136. "msg": "ok",
  2137. "advice": advice,
  2138. })
  2139. } else if origin == 2 {
  2140. adminInfo := c.GetMobileAdminUserInfo()
  2141. var ids []string
  2142. advice_ids := c.GetString("advice_id")
  2143. ids = strings.Split(advice_ids, ",")
  2144. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2145. var err error
  2146. for _, item := range advices {
  2147. if item.CheckState == 1 {
  2148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2149. return
  2150. }
  2151. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2153. return
  2154. }
  2155. item.Checker = adminInfo.AdminUser.Id
  2156. item.CheckTime = time.Now().Unix()
  2157. item.CheckState = 1
  2158. // 查询信息规挡的设置天数
  2159. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2160. if infor.ID > 0 {
  2161. var cha_time int64
  2162. timeNowStr := time.Now().Format("2006-01-02")
  2163. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2164. //今日的日期减去设置的日期
  2165. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2166. if cha_time >= record_date {
  2167. //查询审核是否允许
  2168. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2169. //申请状态不允许的情况 拒绝修改
  2170. if infor.ApplicationStatus != 1 {
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2172. return
  2173. }
  2174. }
  2175. }
  2176. err = service.SaveHisDoctorAdvice(item)
  2177. //记录日志
  2178. byterequest, _ := json.Marshal(advices)
  2179. adviceLog := models.XtDoctorAdviceLog{
  2180. UserOrgId: adminInfo.Org.Id,
  2181. PatientId: item.PatientId,
  2182. AdminUserId: item.Checker,
  2183. Module: 3,
  2184. ErrLog: string(byterequest),
  2185. Status: 1,
  2186. Ctime: time.Now().Unix(),
  2187. Mtime: 0,
  2188. Source: "手机端核对His医嘱",
  2189. RecordDate: item.AdviceDate,
  2190. }
  2191. service.CreateDoctorAdviceLog(adviceLog)
  2192. redis := service.RedisClient()
  2193. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2194. //清空key 值
  2195. redis.Set(key, "", time.Second)
  2196. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2197. redis.Set(keyTwo, "", time.Second)
  2198. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2199. redis.Set(keyThree, "", time.Second)
  2200. theTime := time.Now()
  2201. recordDate := theTime.Format("2006-01-02")
  2202. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2203. redis.Set(keyFour, "", time.Second)
  2204. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2205. redis.Set(keyFive, "", time.Second)
  2206. defer redis.Close()
  2207. }
  2208. if err == nil {
  2209. c.ServeSuccessJSON(map[string]interface{}{
  2210. "msg": "ok",
  2211. "advice": advices,
  2212. })
  2213. } else {
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2215. return
  2216. }
  2217. }
  2218. return
  2219. }
  2220. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2221. id, _ := c.GetInt64("patient", 0)
  2222. assessmentDate := c.GetString("assessment_date", "")
  2223. if id <= 0 || len(assessmentDate) != 10 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. timeLayout := "2006-01-02"
  2228. loc, _ := time.LoadLocation("Local")
  2229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2230. if err != nil {
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. theAssessmentDateTime := theTime.Unix()
  2235. adminUserInfo := c.GetMobileAdminUserInfo()
  2236. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2237. if patient.ID == 0 {
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2239. return
  2240. }
  2241. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2242. if getPEErr != nil {
  2243. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2248. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2249. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2250. var evaluation models.PredialysisEvaluation
  2251. if theEvaluation != nil {
  2252. evaluation = *theEvaluation
  2253. }
  2254. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2255. if code > 0 {
  2256. c.ServeFailJSONWithSGJErrorCode(code)
  2257. return
  2258. }
  2259. if theEvaluation == nil {
  2260. evaluation.CreatedTime = time.Now().Unix()
  2261. evaluation.Status = 1
  2262. evaluation.AssessmentDate = theAssessmentDateTime
  2263. evaluation.PatientId = id
  2264. evaluation.UserOrgId = adminUserInfo.Org.Id
  2265. if appRole.UserType == 2 || appRole.UserType == 1 {
  2266. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2267. evaluation.AssessmentTime = time.Now().Unix()
  2268. } else {
  2269. evaluation.Creater = adminUserInfo.AdminUser.Id
  2270. }
  2271. } else {
  2272. evaluation.UpdatedTime = time.Now().Unix()
  2273. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2274. if appRole.UserType == 2 || appRole.UserType == 1 {
  2275. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2276. evaluation.AssessmentTime = time.Now().Unix()
  2277. } else {
  2278. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2279. if evaluation.Creater == 0 {
  2280. evaluation.Creater = adminUserInfo.AdminUser.Id
  2281. }
  2282. }
  2283. }
  2284. //新增逻辑
  2285. var dewater_amount float64
  2286. dewater_amount = 0
  2287. if evaluation.DryWeight > 0 {
  2288. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2289. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  2290. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2291. dewater_amount = dewater_amount * 1000
  2292. }
  2293. }
  2294. if dewater_amount <= 0 {
  2295. dewater_amount = 0
  2296. }
  2297. } else {
  2298. dewater_amount = 0
  2299. }
  2300. // 计算透析处方的相关超滤量
  2301. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2302. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2303. var lastDialysisPrescribe *models.DialysisPrescription
  2304. var dialysisSolution *models.DialysisSolution
  2305. var dialysisPrescribe *models.DialysisPrescription
  2306. var system_dialysisPrescribe *models.SystemPrescription
  2307. var mode_id int64
  2308. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2309. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2310. if schedual != nil {
  2311. // 获取透析模版
  2312. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2313. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2314. mode_id = schedual.ModeId
  2315. } else {
  2316. // 获取透析模版
  2317. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2318. if dialysisPrescribe == nil && dialysisSolution != nil {
  2319. mode_id = dialysisSolution.ModeId
  2320. }
  2321. if dialysisPrescribe == nil && dialysisSolution == nil {
  2322. mode_id = 0
  2323. }
  2324. }
  2325. // 插入透析处方
  2326. if dialysisPrescribe == nil && dialysisSolution != nil {
  2327. var newprescribe models.DialysisPrescription
  2328. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2329. newprescribe.PatientId = id
  2330. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2331. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2332. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2333. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2334. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2335. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2336. newprescribe.ModeId = dialysisSolution.ModeId
  2337. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2338. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2339. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2340. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2341. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2342. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2343. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2344. newprescribe.Glucose = dialysisSolution.Glucose
  2345. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2346. newprescribe.Kalium = dialysisSolution.Kalium
  2347. newprescribe.Sodium = dialysisSolution.Sodium
  2348. newprescribe.Calcium = dialysisSolution.Calcium
  2349. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2350. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2351. newprescribe.Conductivity = dialysisSolution.Conductivity
  2352. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2353. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2354. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2355. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2356. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2357. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2358. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2359. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2360. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2361. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2362. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2363. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2364. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2365. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2366. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2367. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2368. newprescribe.CreatedTime = time.Now().Unix()
  2369. newprescribe.UpdatedTime = time.Now().Unix()
  2370. newprescribe.RecordDate = theAssessmentDateTime
  2371. newprescribe.DewaterAmount = dewater_amount
  2372. newprescribe.TargetUltrafiltration = dewater_amount
  2373. newprescribe.Status = 1
  2374. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2375. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2376. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2377. newprescribe.Remark = lastDialysisPrescription.Remark
  2378. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2379. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2380. newprescribe.ID = dialysisPrescription.ID
  2381. if dialysisPrescription.ID == 0 {
  2382. if adminUserInfo.Org.Id == 10340 {
  2383. newprescribe.Sodium = 138
  2384. newprescribe.Bicarbonate = 31.1
  2385. newprescribe.DialysateFlow = 500
  2386. newprescribe.PrescribingNumber = 1
  2387. }
  2388. err := service.AddSigleRecord(&newprescribe)
  2389. //记录日志
  2390. byterequest, _ := json.Marshal(newprescribe)
  2391. prescriptionLog := models.XtDialysisPrescriptionLog{
  2392. UserOrgId: adminUserInfo.Org.Id,
  2393. Ctime: time.Now().Unix(),
  2394. Mtime: 0,
  2395. ErrLog: string(byterequest),
  2396. AdminUserId: adminUserInfo.AdminUser.Id,
  2397. RecordDate: newprescribe.RecordDate,
  2398. PatientId: id,
  2399. Source: "手机端新增透前评估插入处方",
  2400. Status: 1,
  2401. }
  2402. service.CreatePrescriptionLog(prescriptionLog)
  2403. //获取key,清空redis
  2404. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2405. redis := service.RedisClient()
  2406. //清空key 值
  2407. redis.Set(key, "", time.Second)
  2408. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2409. //清空key 值
  2410. redis.Set(keyOne, "", time.Second)
  2411. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2412. //清空key 值
  2413. redis.Set(keyTwo, "", time.Second)
  2414. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2415. redis.Set(keySix, "", time.Second)
  2416. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2417. redis.Set(keySeven, "", time.Second)
  2418. if err != nil {
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2420. }
  2421. } else {
  2422. if adminUserInfo.Org.Id == 10340 {
  2423. newprescribe.Sodium = 138
  2424. newprescribe.Bicarbonate = 31.1
  2425. newprescribe.DialysateFlow = 500
  2426. }
  2427. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2428. //
  2429. if appRole.UserType == 2 || appRole.UserType == 1 {
  2430. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2431. if adminUserInfo.Org.Id == 9882 {
  2432. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2433. }
  2434. }
  2435. err := service.UpDateDialysisPrescription(&newprescribe)
  2436. //记录日志
  2437. byterequest, _ := json.Marshal(newprescribe)
  2438. prescriptionLog := models.XtDialysisPrescriptionLog{
  2439. UserOrgId: adminUserInfo.Org.Id,
  2440. Ctime: time.Now().Unix(),
  2441. Mtime: 0,
  2442. ErrLog: string(byterequest),
  2443. AdminUserId: adminUserInfo.AdminUser.Id,
  2444. RecordDate: newprescribe.RecordDate,
  2445. PatientId: id,
  2446. Source: "手机端新增透前评估插入处方",
  2447. Status: 1,
  2448. }
  2449. service.CreatePrescriptionLog(prescriptionLog)
  2450. //获取key,清空redis
  2451. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2452. redis := service.RedisClient()
  2453. //清空key 值
  2454. redis.Set(key, "", time.Second)
  2455. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2456. //清空key 值
  2457. redis.Set(keyOne, "", time.Second)
  2458. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2459. //清空key 值
  2460. redis.Set(keyTwo, "", time.Second)
  2461. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2462. redis.Set(keySix, "", time.Second)
  2463. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2464. redis.Set(keySeven, "", time.Second)
  2465. if err != nil {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2467. }
  2468. }
  2469. }
  2470. if dialysisPrescribe == nil && dialysisSolution == nil {
  2471. if lastDialysisPrescribe != nil {
  2472. var newprescribe models.DialysisPrescription
  2473. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2474. newprescribe.PatientId = id
  2475. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2476. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2477. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2478. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2479. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2480. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2481. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2482. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2483. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2484. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2485. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2486. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2487. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2488. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2489. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2490. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2491. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2492. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2493. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2494. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2495. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2496. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2497. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2498. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2499. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2500. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2501. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2502. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2503. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2504. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2505. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2506. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2507. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2508. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2509. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2510. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2511. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2512. newprescribe.CreatedTime = time.Now().Unix()
  2513. newprescribe.UpdatedTime = time.Now().Unix()
  2514. newprescribe.RecordDate = theAssessmentDateTime
  2515. newprescribe.DewaterAmount = dewater_amount
  2516. newprescribe.TargetUltrafiltration = dewater_amount
  2517. newprescribe.Status = 1
  2518. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2519. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2520. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  2521. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2522. }
  2523. newprescribe.Remark = lastDialysisPrescription.Remark
  2524. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2525. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2526. newprescribe.ID = dialysisPrescription.ID
  2527. if dialysisPrescription.ID == 0 {
  2528. if adminUserInfo.Org.Id == 10340 {
  2529. newprescribe.Sodium = 138
  2530. newprescribe.Bicarbonate = 31.1
  2531. newprescribe.DialysateFlow = 500
  2532. }
  2533. err := service.AddSigleRecord(&newprescribe)
  2534. //记录日志
  2535. byterequest, _ := json.Marshal(newprescribe)
  2536. prescriptionLog := models.XtDialysisPrescriptionLog{
  2537. UserOrgId: adminUserInfo.Org.Id,
  2538. Ctime: time.Now().Unix(),
  2539. Mtime: 0,
  2540. ErrLog: string(byterequest),
  2541. AdminUserId: adminUserInfo.AdminUser.Id,
  2542. RecordDate: newprescribe.RecordDate,
  2543. PatientId: id,
  2544. Source: "手机端新增透前评估插入处方",
  2545. Status: 1,
  2546. }
  2547. service.CreatePrescriptionLog(prescriptionLog)
  2548. //获取key,清空redis
  2549. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2550. redis := service.RedisClient()
  2551. //清空key 值
  2552. redis.Set(key, "", time.Second)
  2553. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2554. //清空key 值
  2555. redis.Set(keyOne, "", time.Second)
  2556. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2557. //清空key 值
  2558. redis.Set(keyTwo, "", time.Second)
  2559. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2560. redis.Set(keySix, "", time.Second)
  2561. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2562. redis.Set(keySeven, "", time.Second)
  2563. if err != nil {
  2564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2565. }
  2566. } else {
  2567. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2568. //
  2569. if appRole.UserType == 2 || appRole.UserType == 1 {
  2570. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2571. if adminUserInfo.Org.Id == 9882 {
  2572. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2573. }
  2574. }
  2575. err := service.UpDateDialysisPrescription(&newprescribe)
  2576. //记录日志
  2577. byterequest, _ := json.Marshal(newprescribe)
  2578. prescriptionLog := models.XtDialysisPrescriptionLog{
  2579. UserOrgId: adminUserInfo.Org.Id,
  2580. Ctime: time.Now().Unix(),
  2581. Mtime: 0,
  2582. ErrLog: string(byterequest),
  2583. AdminUserId: adminUserInfo.AdminUser.Id,
  2584. RecordDate: newprescribe.RecordDate,
  2585. PatientId: id,
  2586. Source: "手机端新增透前评估插入处方",
  2587. Status: 1,
  2588. }
  2589. service.CreatePrescriptionLog(prescriptionLog)
  2590. //获取key,清空redis
  2591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2592. redis := service.RedisClient()
  2593. //清空key 值
  2594. redis.Set(key, "", time.Second)
  2595. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2596. //清空key 值
  2597. redis.Set(keyOne, "", time.Second)
  2598. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2599. //清空key 值
  2600. redis.Set(keyTwo, "", time.Second)
  2601. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2602. redis.Set(keySix, "", time.Second)
  2603. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2604. redis.Set(keySeven, "", time.Second)
  2605. if err != nil {
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2607. }
  2608. }
  2609. if err != nil {
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2611. }
  2612. } else if system_dialysisPrescribe != nil {
  2613. var newprescribe models.DialysisPrescription
  2614. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2615. newprescribe.PatientId = id
  2616. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2617. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2618. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2619. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2620. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2621. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2622. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2623. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2624. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2625. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2626. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2627. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2628. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2629. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2630. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2631. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2632. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2633. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2634. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2635. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2636. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2637. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2638. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2639. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2640. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2641. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2642. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2643. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2644. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2645. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2646. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2647. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2648. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2649. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2650. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2651. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2652. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2653. newprescribe.CreatedTime = time.Now().Unix()
  2654. newprescribe.UpdatedTime = time.Now().Unix()
  2655. newprescribe.RecordDate = theAssessmentDateTime
  2656. newprescribe.DewaterAmount = dewater_amount
  2657. newprescribe.TargetUltrafiltration = dewater_amount
  2658. newprescribe.Status = 1
  2659. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2660. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2661. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2662. newprescribe.Remark = lastDialysisPrescription.Remark
  2663. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2664. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2665. newprescribe.ID = dialysisPrescription.ID
  2666. if dialysisPrescription.ID == 0 {
  2667. if adminUserInfo.Org.Id == 10340 {
  2668. newprescribe.Sodium = 138
  2669. newprescribe.Bicarbonate = 31.1
  2670. newprescribe.DialysateFlow = 500
  2671. }
  2672. err := service.AddSigleRecord(&newprescribe)
  2673. //记录日志
  2674. byterequest, _ := json.Marshal(newprescribe)
  2675. prescriptionLog := models.XtDialysisPrescriptionLog{
  2676. UserOrgId: adminUserInfo.Org.Id,
  2677. Ctime: time.Now().Unix(),
  2678. Mtime: 0,
  2679. ErrLog: string(byterequest),
  2680. AdminUserId: adminUserInfo.AdminUser.Id,
  2681. RecordDate: newprescribe.RecordDate,
  2682. PatientId: id,
  2683. Source: "手机端新增透前评估插入处方",
  2684. Status: 1,
  2685. }
  2686. service.CreatePrescriptionLog(prescriptionLog)
  2687. //获取key,清空redis
  2688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2689. redis := service.RedisClient()
  2690. //清空key 值
  2691. redis.Set(key, "", time.Second)
  2692. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2693. //清空key 值
  2694. redis.Set(keyOne, "", time.Second)
  2695. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2696. //清空key 值
  2697. redis.Set(keyTwo, "", time.Second)
  2698. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2699. redis.Set(keySix, "", time.Second)
  2700. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2701. redis.Set(keySeven, "", time.Second)
  2702. if err != nil {
  2703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2704. }
  2705. } else {
  2706. if adminUserInfo.Org.Id == 10340 {
  2707. newprescribe.Sodium = 138
  2708. newprescribe.Bicarbonate = 31.1
  2709. newprescribe.DialysateFlow = 500
  2710. }
  2711. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2712. //
  2713. if appRole.UserType == 2 || appRole.UserType == 1 {
  2714. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2715. if adminUserInfo.Org.Id == 9882 {
  2716. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2717. }
  2718. }
  2719. err := service.UpDateDialysisPrescription(&newprescribe)
  2720. //记录日志
  2721. byterequest, _ := json.Marshal(newprescribe)
  2722. prescriptionLog := models.XtDialysisPrescriptionLog{
  2723. UserOrgId: adminUserInfo.Org.Id,
  2724. Ctime: time.Now().Unix(),
  2725. Mtime: 0,
  2726. ErrLog: string(byterequest),
  2727. AdminUserId: adminUserInfo.AdminUser.Id,
  2728. RecordDate: newprescribe.RecordDate,
  2729. PatientId: id,
  2730. Source: "手机端新增透前评估插入处方",
  2731. Status: 1,
  2732. }
  2733. service.CreatePrescriptionLog(prescriptionLog)
  2734. //获取key,清空redis
  2735. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2736. redis := service.RedisClient()
  2737. //清空key 值
  2738. redis.Set(key, "", time.Second)
  2739. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2740. //清空key 值
  2741. redis.Set(keyOne, "", time.Second)
  2742. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2743. //清空key 值
  2744. redis.Set(keyTwo, "", time.Second)
  2745. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2746. redis.Set(keySix, "", time.Second)
  2747. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2748. redis.Set(keySeven, "", time.Second)
  2749. if err != nil {
  2750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2751. }
  2752. }
  2753. if err != nil {
  2754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2755. }
  2756. } else {
  2757. var newprescribe models.DialysisPrescription
  2758. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2759. newprescribe.PatientId = id
  2760. newprescribe.ModeId = mode_id
  2761. newprescribe.CreatedTime = time.Now().Unix()
  2762. newprescribe.UpdatedTime = time.Now().Unix()
  2763. newprescribe.RecordDate = theAssessmentDateTime
  2764. newprescribe.DewaterAmount = dewater_amount
  2765. newprescribe.TargetUltrafiltration = dewater_amount
  2766. newprescribe.Status = 1
  2767. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2768. if dialysisPrescription.ID > 0 {
  2769. newprescribe.ID = dialysisPrescription.ID
  2770. }
  2771. if dialysisPrescription.ID == 0 {
  2772. if adminUserInfo.Org.Id == 10340 {
  2773. newprescribe.Sodium = 138
  2774. newprescribe.Bicarbonate = 31.1
  2775. newprescribe.DialysateFlow = 500
  2776. }
  2777. err := service.AddSigleRecord(&newprescribe)
  2778. //获取key,清空redis
  2779. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2780. redis := service.RedisClient()
  2781. //清空key 值
  2782. redis.Set(key, "", time.Second)
  2783. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2784. //清空key 值
  2785. redis.Set(keyOne, "", time.Second)
  2786. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2787. //清空key 值
  2788. redis.Set(keyTwo, "", time.Second)
  2789. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2790. redis.Set(keySix, "", time.Second)
  2791. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2792. redis.Set(keySeven, "", time.Second)
  2793. if err != nil {
  2794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2795. }
  2796. } else {
  2797. if adminUserInfo.Org.Id == 10340 {
  2798. newprescribe.Sodium = 138
  2799. newprescribe.Bicarbonate = 31.1
  2800. newprescribe.DialysateFlow = 500
  2801. }
  2802. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2803. //
  2804. if appRole.UserType == 2 || appRole.UserType == 1 {
  2805. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2806. if adminUserInfo.Org.Id == 9882 {
  2807. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2808. }
  2809. }
  2810. err := service.UpDateDialysisPrescription(&newprescribe)
  2811. //记录日志
  2812. byterequest, _ := json.Marshal(newprescribe)
  2813. prescriptionLog := models.XtDialysisPrescriptionLog{
  2814. UserOrgId: adminUserInfo.Org.Id,
  2815. Ctime: time.Now().Unix(),
  2816. Mtime: 0,
  2817. ErrLog: string(byterequest),
  2818. AdminUserId: adminUserInfo.AdminUser.Id,
  2819. RecordDate: newprescribe.RecordDate,
  2820. PatientId: id,
  2821. Source: "手机端新增透前评估插入处方",
  2822. Status: 1,
  2823. }
  2824. service.CreatePrescriptionLog(prescriptionLog)
  2825. //获取key,清空redis
  2826. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2827. redis := service.RedisClient()
  2828. //清空key 值
  2829. redis.Set(key, "", time.Second)
  2830. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2831. //清空key 值
  2832. redis.Set(keyOne, "", time.Second)
  2833. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2834. //清空key 值
  2835. redis.Set(keyTwo, "", time.Second)
  2836. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2837. redis.Set(keySix, "", time.Second)
  2838. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2839. redis.Set(keySeven, "", time.Second)
  2840. if err != nil {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2842. }
  2843. }
  2844. if err != nil {
  2845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2846. }
  2847. }
  2848. }
  2849. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2850. // if dialysisPrescribe != nil {
  2851. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2852. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2853. // dialysisPrescribe.DewaterAmount = dewater_amount
  2854. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2855. // dialysisPrescribe.Status = 1
  2856. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2857. // if updateErr != nil {
  2858. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2859. // }
  2860. // }
  2861. // 查询信息规挡的设置天数
  2862. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2863. if infor.ID > 0 && infor.WeekDay > 0 {
  2864. var cha_time int64
  2865. timeNowStr := time.Now().Format("2006-01-02")
  2866. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2867. //今日的日期减去设置的日期
  2868. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2869. if cha_time >= evaluation.AssessmentDate {
  2870. //查询审核是否允许
  2871. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  2872. //申请状态不允许的情况 拒绝修改
  2873. if infor.ApplicationStatus != 1 {
  2874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2875. return
  2876. }
  2877. }
  2878. }
  2879. //针对长沙南雅的问题
  2880. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  2881. if len(evaluation.SymptomBeforeDialysis) == 0 {
  2882. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  2883. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  2884. }
  2885. }
  2886. err = service.UpadatePredialysisEvaluation(&evaluation)
  2887. //记录日志
  2888. byterequest, _ := json.Marshal(evaluation)
  2889. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2890. UserOrgId: evaluation.UserOrgId,
  2891. AdminUserId: adminUserInfo.AdminUser.Id,
  2892. ErrLog: string(byterequest),
  2893. PatientId: evaluation.PatientId,
  2894. RecordDate: evaluation.AssessmentDate,
  2895. Ctime: time.Now().Unix(),
  2896. Mtime: 0,
  2897. Status: 1,
  2898. Source: "手机端保存透前评估",
  2899. }
  2900. service.CreateBeforLog(beforeDislysisLog)
  2901. finish := models.XtDialysisFinish{
  2902. IsFinish: 1,
  2903. UserOrgId: adminUserInfo.Org.Id,
  2904. Status: 1,
  2905. Ctime: time.Now().Unix(),
  2906. Mtime: 0,
  2907. Module: 3,
  2908. RecordDate: evaluation.AssessmentDate,
  2909. Sourse: 1,
  2910. PatientId: id,
  2911. }
  2912. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2913. if dialysisFinish.ID == 0 {
  2914. service.CreateDialysisFinish(finish)
  2915. }
  2916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2917. redis := service.RedisClient()
  2918. defer redis.Close()
  2919. //清空key 值
  2920. redis.Set(key, "", time.Second)
  2921. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2922. redis.Set(keyOne, "", time.Second)
  2923. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2924. redis.Set(keyTwo, "", time.Second)
  2925. if err != nil {
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2927. return
  2928. }
  2929. c.ServeSuccessJSON(map[string]interface{}{
  2930. "msg": "ok",
  2931. "evaluation": evaluation,
  2932. })
  2933. return
  2934. }
  2935. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2936. dataBody := make(map[string]interface{}, 0)
  2937. err := json.Unmarshal(data, &dataBody)
  2938. utils.InfoLog(string(data))
  2939. if err != nil {
  2940. utils.ErrorLog(err.Error())
  2941. code = enums.ErrorCodeParamWrong
  2942. return
  2943. }
  2944. // if method == "create" {
  2945. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2946. utils.ErrorLog("mode")
  2947. code = enums.ErrorCodeParamWrong
  2948. return
  2949. }
  2950. mode := int64(dataBody["mode"].(float64))
  2951. if mode <= 0 {
  2952. utils.ErrorLog("mode <= 0")
  2953. code = enums.ErrorCodeParamWrong
  2954. return
  2955. }
  2956. solution.ModeId = mode
  2957. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2958. utils.ErrorLog("mode_name")
  2959. code = enums.ErrorCodeParamWrong
  2960. return
  2961. }
  2962. modeName, _ := dataBody["mode_name"].(string)
  2963. if len(modeName) == 0 {
  2964. utils.ErrorLog("len(mode_name) == 0")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. solution.ModeName = modeName
  2969. solution.Name = modeName
  2970. // }
  2971. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2972. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2973. solution.DialysisDuration = dialysisDuration
  2974. }
  2975. if dataBody["dialysis_duration"] != nil {
  2976. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2977. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2978. solution.DialysisDuration = dialysisDuration
  2979. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2980. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2981. solution.DialysisDuration = dialysisDuration
  2982. }
  2983. }
  2984. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2985. dialyzer := int64(dataBody["dialyzer"].(float64))
  2986. solution.Dialyzer = dialyzer
  2987. }
  2988. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2989. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2990. solution.PerfusionApparatus = perfusionApparatus
  2991. }
  2992. if dataBody["blood_flow_volume"] != nil {
  2993. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2994. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2995. solution.BloodFlowVolume = bloodFlowVolume
  2996. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2997. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2998. solution.BloodFlowVolume = bloodFlowVolume
  2999. }
  3000. }
  3001. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3002. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3003. solution.HemodialysisMachine = hemodialysisMachine
  3004. }
  3005. if dataBody["dewater"] != nil {
  3006. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3007. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3008. solution.Dewater = dewater
  3009. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3010. dewater := dataBody["dewater"].(float64)
  3011. solution.Dewater = dewater
  3012. }
  3013. }
  3014. if dataBody["replacement_total"] != nil {
  3015. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3016. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3017. solution.ReplacementTotal = replacementTotal
  3018. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3019. replacementTotal := dataBody["replacement_total"].(float64)
  3020. solution.ReplacementTotal = replacementTotal
  3021. }
  3022. }
  3023. if dataBody["displace_liqui"] != nil {
  3024. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3025. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3026. solution.DisplaceLiqui = displaceLiqui
  3027. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3028. displaceLiqui := dataBody["displace_liqui"].(float64)
  3029. solution.DisplaceLiqui = displaceLiqui
  3030. }
  3031. }
  3032. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3033. replacementWay := int64(dataBody["replacement_way"].(float64))
  3034. solution.ReplacementWay = replacementWay
  3035. }
  3036. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3037. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3038. solution.Anticoagulant = anticoagulant
  3039. }
  3040. if dataBody["anticoagulant_shouji"] != nil {
  3041. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3042. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3043. solution.AnticoagulantShouji = anticoagulantShouji
  3044. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3045. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3046. solution.AnticoagulantShouji = anticoagulantShouji
  3047. }
  3048. }
  3049. if dataBody["anticoagulant_weichi"] != nil {
  3050. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3051. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3052. solution.AnticoagulantWeichi = anticoagulantWeichi
  3053. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3054. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3055. solution.AnticoagulantWeichi = anticoagulantWeichi
  3056. }
  3057. }
  3058. if dataBody["anticoagulant_zongliang"] != nil {
  3059. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3060. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3061. solution.AnticoagulantZongliang = anticoagulantZongliang
  3062. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3063. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3064. solution.AnticoagulantZongliang = anticoagulantZongliang
  3065. }
  3066. }
  3067. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3068. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3069. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3070. }
  3071. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3072. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3073. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3074. }
  3075. if dataBody["kalium"] != nil {
  3076. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3077. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3078. solution.Kalium = kalium
  3079. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3080. kalium := dataBody["kalium"].(float64)
  3081. solution.Kalium = kalium
  3082. }
  3083. }
  3084. if dataBody["sodium"] != nil {
  3085. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3086. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3087. solution.Sodium = sodium
  3088. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3089. sodium := dataBody["sodium"].(float64)
  3090. solution.Sodium = sodium
  3091. }
  3092. }
  3093. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3094. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3095. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3096. solution.Calcium = calcium
  3097. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3098. calcium := dataBody["calcium"].(float64)
  3099. solution.Calcium = calcium
  3100. }
  3101. }
  3102. if dataBody["bicarbonate"] != nil {
  3103. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3104. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3105. solution.Bicarbonate = bicarbonate
  3106. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3107. bicarbonate := dataBody["bicarbonate"].(float64)
  3108. solution.Bicarbonate = bicarbonate
  3109. }
  3110. }
  3111. if dataBody["glucose"] != nil {
  3112. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3113. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3114. solution.Glucose = glucose
  3115. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3116. glucose := dataBody["glucose"].(float64)
  3117. solution.Glucose = glucose
  3118. }
  3119. }
  3120. // if dataBody["dry_weight"] != nil {
  3121. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3122. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3123. // solution.DryWeight = dryWeight
  3124. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3125. // dryWeight := dataBody["dry_weight"].(float64)
  3126. // solution.DryWeight = dryWeight
  3127. // }
  3128. // }
  3129. if dataBody["dialysate_flow"] != nil {
  3130. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3131. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3132. solution.DialysateFlow = dialysateFlow
  3133. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3134. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3135. solution.DialysateFlow = dialysateFlow
  3136. }
  3137. }
  3138. if dataBody["dialysate_temperature"] != nil {
  3139. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3140. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3141. solution.DialysateTemperature = dialysateTemperature
  3142. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3143. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3144. solution.DialysateTemperature = dialysateTemperature
  3145. }
  3146. }
  3147. if dataBody["conductivity"] != nil {
  3148. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3149. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3150. solution.Conductivity = conductivity
  3151. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3152. conductivity := dataBody["conductivity"].(float64)
  3153. solution.Conductivity = conductivity
  3154. }
  3155. }
  3156. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3157. remark := dataBody["remark"].(string)
  3158. solution.Remark = remark
  3159. }
  3160. if dataBody["dialysis_duration_hour"] != nil {
  3161. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3162. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3163. solution.DialysisDurationHour = dialysisDurationHour
  3164. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3165. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3166. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3167. }
  3168. }
  3169. if dataBody["dialysis_duration_minute"] != nil {
  3170. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3171. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3172. solution.DialysisDurationMinute = dialysisDurationMinute
  3173. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3174. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3175. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3176. }
  3177. }
  3178. if dataBody["target_ultrafiltration"] != nil {
  3179. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3180. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3181. solution.TargetUltrafiltration = targetUltrafiltration
  3182. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3183. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3184. solution.TargetUltrafiltration = targetUltrafiltration
  3185. }
  3186. }
  3187. if dataBody["dialysate_formulation"] != nil {
  3188. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3189. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3190. solution.DialysateFormulation = dialysateFormulation
  3191. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3192. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3193. solution.DialysateFormulation = int64(dialysateFormulation)
  3194. }
  3195. }
  3196. return
  3197. }
  3198. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3199. dataBody := make(map[string]interface{}, 0)
  3200. err := json.Unmarshal(data, &dataBody)
  3201. utils.InfoLog(string(data))
  3202. if err != nil {
  3203. utils.ErrorLog(err.Error())
  3204. code = enums.ErrorCodeParamWrong
  3205. return
  3206. }
  3207. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3208. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3209. evaluation.WeightBefore = weightVefore
  3210. }
  3211. // fmt.Println(dataBody["dry_weight"])
  3212. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3213. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3214. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3215. fmt.Println(additionalWeight)
  3216. evaluation.DryWeight = additionalWeight
  3217. }
  3218. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3219. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3220. fmt.Println(additionalWeight)
  3221. evaluation.AdditionalWeight = additionalWeight
  3222. }
  3223. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3224. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3225. evaluation.Temperature = Temperature
  3226. }
  3227. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3228. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3229. evaluation.SystolicBloodPressure = systolicBloodPressure
  3230. }
  3231. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3232. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3233. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3234. }
  3235. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3236. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3237. evaluation.PulseFrequency = pulseFrequency
  3238. }
  3239. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3240. breathingRate := dataBody["breathing_rate"].(string)
  3241. evaluation.BreathingRate = breathingRate
  3242. }
  3243. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3244. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3245. evaluation.LastPostDialysis = lastPostDialysis
  3246. }
  3247. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3248. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3249. evaluation.DialysisInterphase = dialysisInterphase
  3250. }
  3251. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3252. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3253. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3254. }
  3255. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3256. catheter, _ := dataBody["catheter"].(string)
  3257. evaluation.Catheter = catheter
  3258. }
  3259. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3260. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3261. evaluation.CatheterBend = catheter_bend
  3262. }
  3263. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3264. Complication, _ := dataBody["complication"].(string)
  3265. evaluation.Complication = Complication
  3266. }
  3267. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3268. remark := dataBody["remark"].(string)
  3269. evaluation.Remark = remark
  3270. }
  3271. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3272. machine_type := dataBody["machine_type"].(string)
  3273. evaluation.MachineType = machine_type
  3274. }
  3275. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3276. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3277. evaluation.BloodAccessPartId = blood_access_part_id
  3278. }
  3279. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3280. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3281. // evaluation.BloodAccessPartId = blood_access_part_id
  3282. //}
  3283. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3284. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3285. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3286. }
  3287. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3288. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3289. evaluation.InternalFistula = internal_fistula
  3290. }
  3291. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3292. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3293. evaluation.InternalFistulaSkin = internal_fistula_skin
  3294. }
  3295. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3296. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3297. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3298. evaluation.IsHemorrhage = is_hemorrhage
  3299. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3300. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3301. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3302. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3303. is_hemorrhage = 0
  3304. }
  3305. evaluation.IsHemorrhage = is_hemorrhage
  3306. if is_hemorrhage == 1 {
  3307. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3308. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3309. evaluation.Hemorrhage = hemorrhage
  3310. }
  3311. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3312. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3313. evaluation.HemorrhageOther = hemorrhage_other
  3314. }
  3315. }
  3316. } else {
  3317. evaluation.IsHemorrhage = 0
  3318. }
  3319. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3320. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3321. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3322. }
  3323. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3324. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3325. evaluation.InternalFistulaOther = internal_fistula_other
  3326. }
  3327. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3328. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3329. evaluation.BloodAccessNoise = blood_access_noise
  3330. }
  3331. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3332. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3333. puncture_way := dataBody["puncture_way"].(string)
  3334. evaluation.PunctureWay = puncture_way
  3335. }
  3336. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3337. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3338. evaluation.VenousCatheterization = venous_catheterization
  3339. }
  3340. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3341. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3342. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3343. }
  3344. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3345. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3346. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3347. }
  3348. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3349. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3350. evaluation.DuctusArantii = ductus_arantii
  3351. }
  3352. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3353. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3354. evaluation.EmergencyTreatment = emergency_treatment
  3355. }
  3356. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3357. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3358. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3359. }
  3360. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3361. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3362. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3363. evaluation.DialysisCount = dialysis_count
  3364. }
  3365. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3366. is_infect, _ := dataBody["is_infect"].(string)
  3367. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3368. evaluation.IsInfect = infect
  3369. }
  3370. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3371. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3372. evaluation.Exposed = exposed
  3373. }
  3374. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3375. skin, _ := dataBody["skin"].(string)
  3376. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3377. evaluation.Skin = skin
  3378. }
  3379. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3380. skin_other, _ := dataBody["skin_other"].(string)
  3381. evaluation.SkinOther = skin_other
  3382. }
  3383. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3384. infect_other, _ := dataBody["infect_other"].(string)
  3385. evaluation.InfectOther = infect_other
  3386. }
  3387. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3388. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3389. evaluation.DuctusArantiiOther = ductus_arantii_other
  3390. }
  3391. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3392. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3393. evaluation.PunctureNeedle = punctureNeedle
  3394. }
  3395. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3396. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3397. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3398. }
  3399. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3400. pinholing := dataBody["pinholing"].(string)
  3401. evaluation.Phinholing = pinholing
  3402. }
  3403. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3404. catheter_suture := dataBody["catheter_suture"].(string)
  3405. evaluation.CatheterSuture = catheter_suture
  3406. }
  3407. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3408. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3409. evaluation.CatheterSutureOther = catheter_suture_other
  3410. }
  3411. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3412. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3413. evaluation.UrineVolume = urine_volume
  3414. }
  3415. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3416. edema := dataBody["edema"].(string)
  3417. evaluation.Edema = edema
  3418. }
  3419. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  3420. specialTreatment := dataBody["special_treatment"].(string)
  3421. evaluation.SpecialTreatment = specialTreatment
  3422. }
  3423. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  3424. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  3425. evaluation.CatheterMaintenance = catheter_maintenance
  3426. }
  3427. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  3428. thromubusType := int64(dataBody["thromubus_type"].(float64))
  3429. evaluation.ThromubusType = thromubusType
  3430. }
  3431. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  3432. thrombus_av := dataBody["thrombus_av"].(string)
  3433. evaluation.ThrombusAv = thrombus_av
  3434. }
  3435. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  3436. thromubus_a := dataBody["thromubus_a"].(string)
  3437. evaluation.ThromubusA = thromubus_a
  3438. }
  3439. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  3440. thromubus_v := dataBody["thromubus_v"].(string)
  3441. evaluation.ThromubusV = thromubus_v
  3442. }
  3443. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  3444. dehydration := dataBody["dehydration"].(string)
  3445. evaluation.Dehydration = dehydration
  3446. }
  3447. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  3448. period := int64(dataBody["period"].(float64))
  3449. evaluation.Period = period
  3450. }
  3451. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  3452. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  3453. evaluation.EstimatedFoodIntake = estimated_food_intake
  3454. }
  3455. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  3456. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  3457. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  3458. }
  3459. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  3460. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  3461. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  3462. }
  3463. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  3464. urea_befor := dataBody["urea_befor"].(string)
  3465. evaluation.UreaBefor = urea_befor
  3466. }
  3467. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  3468. suction := dataBody["suction"].(string)
  3469. evaluation.Suction = suction
  3470. }
  3471. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  3472. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  3473. evaluation.WeightBeforRemake = weight_befor_remake
  3474. }
  3475. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  3476. height := dataBody["height"].(string)
  3477. evaluation.Height = height
  3478. }
  3479. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  3480. age := dataBody["age"].(string)
  3481. evaluation.Age = age
  3482. }
  3483. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  3484. his_department := dataBody["his_department"].(string)
  3485. evaluation.HisDepartment = his_department
  3486. }
  3487. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  3488. his_bed := dataBody["his_bed"].(string)
  3489. evaluation.HisBed = his_bed
  3490. }
  3491. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  3492. point_puncture := dataBody["point_puncture"].(string)
  3493. evaluation.PointPuncture = point_puncture
  3494. }
  3495. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  3496. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  3497. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  3498. }
  3499. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  3500. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  3501. evaluation.SkinSiteCatheterization = skin_site_catheterization
  3502. }
  3503. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  3504. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  3505. evaluation.WhetherUnobstructed = whether_unobstructed
  3506. }
  3507. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  3508. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  3509. evaluation.LienNecessary = lien_necessary
  3510. }
  3511. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  3512. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  3513. timeLayout := "2006-01-02"
  3514. loc, _ := time.LoadLocation("Local")
  3515. var startTime int64
  3516. if len(pathway_formation_time) > 0 {
  3517. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  3518. startTime = theTime.Unix()
  3519. }
  3520. evaluation.PathwayFormationTime = startTime
  3521. }
  3522. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  3523. befor_symptoms := dataBody["befor_symptoms"].(string)
  3524. evaluation.BeforSymptoms = befor_symptoms
  3525. }
  3526. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  3527. washing_time, _ := dataBody["washing_time"].(string)
  3528. evaluation.WashingTime = washing_time
  3529. }
  3530. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  3531. warsh_count, _ := dataBody["warsh_count"].(string)
  3532. evaluation.WarshCount = warsh_count
  3533. }
  3534. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  3535. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  3536. evaluation.PunctureNeedleDirection = puncture_needle_direction
  3537. }
  3538. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  3539. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  3540. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  3541. }
  3542. return
  3543. }
  3544. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3545. dataBody := make(map[string]interface{}, 0)
  3546. err := json.Unmarshal(data, &dataBody)
  3547. if err != nil {
  3548. utils.ErrorLog(err.Error())
  3549. code = enums.ErrorCodeParamWrong
  3550. return
  3551. }
  3552. timeLayout := "2006-01-02"
  3553. loc, _ := time.LoadLocation("Local")
  3554. isChild := false
  3555. if action == "create" {
  3556. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3557. utils.ErrorLog("advice_type")
  3558. code = enums.ErrorCodeParamWrong
  3559. return
  3560. }
  3561. adviceType := int64(dataBody["advice_type"].(float64))
  3562. if adviceType != 1 && adviceType != 2 {
  3563. utils.ErrorLog("advice_type != 1&&2")
  3564. code = enums.ErrorCodeParamWrong
  3565. return
  3566. }
  3567. advice.AdviceType = adviceType
  3568. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3569. utils.ErrorLog("advice_date")
  3570. code = enums.ErrorCodeParamWrong
  3571. return
  3572. }
  3573. adviceDate, _ := dataBody["advice_date"].(string)
  3574. if len(adviceDate) == 0 {
  3575. utils.ErrorLog("len(adviceDate) == 0")
  3576. code = enums.ErrorCodeParamWrong
  3577. return
  3578. }
  3579. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3580. if err != nil {
  3581. utils.ErrorLog(err.Error())
  3582. code = enums.ErrorCodeParamWrong
  3583. return
  3584. }
  3585. advice.AdviceDate = theTime.Unix()
  3586. advice.RecordDate = theTime.Unix()
  3587. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3588. parentId := int64(dataBody["parent_id"].(float64))
  3589. advice.ParentId = parentId
  3590. if parentId > 0 {
  3591. isChild = true
  3592. }
  3593. }
  3594. } else {
  3595. isChild = advice.ParentId > 0
  3596. }
  3597. if !isChild {
  3598. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3599. utils.ErrorLog("start_time")
  3600. code = enums.ErrorCodeParamWrong
  3601. return
  3602. }
  3603. startTime, _ := dataBody["start_time"].(string)
  3604. if len(startTime) == 0 {
  3605. utils.ErrorLog("len(start_time) == 0")
  3606. code = enums.ErrorCodeParamWrong
  3607. return
  3608. }
  3609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3610. if err != nil {
  3611. utils.ErrorLog(err.Error())
  3612. code = enums.ErrorCodeParamWrong
  3613. return
  3614. }
  3615. advice.StartTime = theTime.Unix()
  3616. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3617. deliveryWay, _ := dataBody["delivery_way"].(string)
  3618. advice.DeliveryWay = deliveryWay
  3619. }
  3620. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3621. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3622. advice.ExecutionFrequency = executionFrequency
  3623. }
  3624. }
  3625. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3626. deliveryWay, _ := dataBody["delivery_way"].(string)
  3627. advice.DeliveryWay = deliveryWay
  3628. }
  3629. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3630. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3631. advice.ExecutionFrequency = executionFrequency
  3632. }
  3633. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3634. utils.ErrorLog("advice_name")
  3635. code = enums.ErrorCodeParamWrong
  3636. return
  3637. }
  3638. adviceName, _ := dataBody["advice_name"].(string)
  3639. if len(adviceName) == 0 {
  3640. utils.ErrorLog("len(advice_name) == 0")
  3641. code = enums.ErrorCodeParamWrong
  3642. return
  3643. }
  3644. advice.AdviceName = adviceName
  3645. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3646. adviceDsc, _ := dataBody["advice_desc"].(string)
  3647. advice.AdviceDesc = adviceDsc
  3648. }
  3649. if dataBody["way"] == nil {
  3650. advice.Way = 0
  3651. } else {
  3652. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3653. way := int64(dataBody["way"].(float64))
  3654. advice.Way = way
  3655. }
  3656. }
  3657. if dataBody["drug_id"] == nil {
  3658. advice.DrugId = 0
  3659. } else {
  3660. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3661. drug_id := int64(dataBody["drug_id"].(float64))
  3662. advice.DrugId = drug_id
  3663. }
  3664. }
  3665. if dataBody["drug_name_id"] == nil {
  3666. advice.DrugNameId = 0
  3667. } else {
  3668. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3669. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3670. advice.DrugNameId = drug_name_id
  3671. }
  3672. }
  3673. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3674. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3675. advice.SingleDose = singleDose
  3676. }
  3677. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3678. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3679. advice.SingleDoseUnit = singleDoseUnit
  3680. }
  3681. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3682. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3683. advice.DrugSpec = drugSpec
  3684. }
  3685. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3686. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3687. advice.DrugSpecUnit = drugSpecUnit
  3688. }
  3689. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3690. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3691. advice.PrescribingNumber = prescribingNumber
  3692. }
  3693. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3694. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3695. advice.PrescribingNumberUnit = prescribingNumberUnit
  3696. }
  3697. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3698. remark, _ := dataBody["remark"].(string)
  3699. advice.Remark = remark
  3700. }
  3701. return
  3702. }
  3703. func (c *PatientApiController) GetPatientEducation() {
  3704. patientID, _ := c.GetInt64("patient_id", 0)
  3705. page, _ := c.GetInt64("page", 0)
  3706. limit, _ := c.GetInt64("limit", 0)
  3707. startTime := c.GetString("start_time", "")
  3708. endTime := c.GetString("end_time", "")
  3709. if page <= 0 {
  3710. page = 1
  3711. }
  3712. if limit <= 0 {
  3713. limit = 10
  3714. }
  3715. if patientID <= 0 {
  3716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3717. return
  3718. }
  3719. timeLayout := "2006-01-02"
  3720. loc, _ := time.LoadLocation("Local")
  3721. var theStartTIme int64
  3722. if len(startTime) > 0 {
  3723. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3724. if err != nil {
  3725. theStartTIme = 0
  3726. }
  3727. theStartTIme = theTime.Unix()
  3728. }
  3729. var theEndtTIme int64
  3730. if len(endTime) > 0 {
  3731. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3732. if err != nil {
  3733. theEndtTIme = 0
  3734. }
  3735. theEndtTIme = theTime.Unix()
  3736. }
  3737. adminUserInfo := c.GetMobileAdminUserInfo()
  3738. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3739. c.ServeSuccessJSON(map[string]interface{}{
  3740. "total": total,
  3741. "edus": edus,
  3742. })
  3743. return
  3744. }
  3745. func (c *PatientApiController) GetPatientSchedulesList() {
  3746. patientID, _ := c.GetInt64("patient_id", 0)
  3747. page, _ := c.GetInt64("page", 0)
  3748. limit, _ := c.GetInt64("limit", 0)
  3749. if patientID <= 0 {
  3750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3751. return
  3752. }
  3753. adminUserInfo := c.GetMobileAdminUserInfo()
  3754. todayTime := time.Now().Format("2006-01-02")
  3755. timeLayout := "2006-01-02 15:04:05"
  3756. loc, _ := time.LoadLocation("Local")
  3757. var theStartTime int64
  3758. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3759. theStartTime = theTime.Unix()
  3760. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3761. if len(schedules) > 0 {
  3762. for index, item := range schedules {
  3763. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3764. schedules[index].Week = int64(week)
  3765. }
  3766. }
  3767. c.ServeSuccessJSON(map[string]interface{}{
  3768. "schedules": schedules,
  3769. })
  3770. return
  3771. }
  3772. func (c *PatientApiController) GetRecords() {
  3773. patientID, _ := c.GetInt64("patient_id", 0)
  3774. page, _ := c.GetInt64("page", 0)
  3775. limit, _ := c.GetInt64("limit", 0)
  3776. startTime := c.GetString("start_time", "")
  3777. endTime := c.GetString("end_time", "")
  3778. mode_id, _ := c.GetInt64("mode_id", 0)
  3779. if page <= 0 {
  3780. page = 1
  3781. }
  3782. if limit <= 0 {
  3783. limit = 10
  3784. }
  3785. if patientID <= 0 {
  3786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3787. return
  3788. }
  3789. timeLayout := "2006-01-02"
  3790. loc, _ := time.LoadLocation("Local")
  3791. var theStartTIme int64
  3792. if len(startTime) > 0 {
  3793. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3794. if err != nil {
  3795. theStartTIme = 0
  3796. }
  3797. theStartTIme = theTime.Unix()
  3798. }
  3799. var theEndtTIme int64
  3800. if len(endTime) > 0 {
  3801. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3802. if err != nil {
  3803. theEndtTIme = 0
  3804. }
  3805. theEndtTIme = theTime.Unix()
  3806. }
  3807. adminUserInfo := c.GetMobileAdminUserInfo()
  3808. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3809. c.ServeSuccessJSON(map[string]interface{}{
  3810. "total": total,
  3811. "records": records,
  3812. })
  3813. return
  3814. }
  3815. func (c *PatientApiController) GetPatientMonitor() {
  3816. partition, _ := c.GetInt64("partition")
  3817. monitorDate := c.GetString("date")
  3818. patient_id, _ := c.GetInt64("patient_id")
  3819. timeLayout := "2006-01-02"
  3820. loc, _ := time.LoadLocation("Local")
  3821. var theStartTime int64
  3822. if len(monitorDate) > 0 {
  3823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3824. if err != nil {
  3825. theStartTime = 0
  3826. }
  3827. theStartTime = theTime.Unix()
  3828. }
  3829. adminInfo := c.GetMobileAdminUserInfo()
  3830. orgID := adminInfo.Org.Id
  3831. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3832. if err != nil {
  3833. c.ErrorLog("获取排班信息失败:%v", err)
  3834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3835. } else {
  3836. if len(monitor) > 0 {
  3837. //获取所有床位
  3838. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3839. //获取所有分区
  3840. zoneList, _ := service.GetAllZoneByList(orgID)
  3841. //获取透析处方
  3842. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3843. //获取透前评估
  3844. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3845. //获取上机
  3846. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3847. //获取透后
  3848. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3849. //获取透后监测
  3850. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3851. //获取所有的患者
  3852. patients, _ := service.GetAllPatientListByListOne(orgID)
  3853. for _, it := range patients {
  3854. if orgID == 10445 {
  3855. if theStartTime <= 1703952000 {
  3856. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  3857. it.TotalDialysis = listOne.Count
  3858. }
  3859. if theStartTime >= 1704038400 {
  3860. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  3861. it.TotalDialysis = listOrder.Count
  3862. }
  3863. }
  3864. }
  3865. //获取所有透析模式
  3866. treatments, _ := service.GetAllTreatModeByList(orgID)
  3867. for key, item := range monitor {
  3868. // 获取床位信息
  3869. for _, it := range numberList {
  3870. if item.BedId == it.ID {
  3871. monitor[key].DeviceNumber = it
  3872. break
  3873. }
  3874. }
  3875. //获取分区信息
  3876. for _, it := range zoneList {
  3877. if item.PartitionId == it.ID {
  3878. monitor[key].DeviceZone = it
  3879. }
  3880. }
  3881. for _, prescription := range prescriptions {
  3882. if item.PatientId == prescription.PatientId {
  3883. monitor[key].Prescription = prescription
  3884. break
  3885. }
  3886. }
  3887. // 透前评估
  3888. for _, assessmentBefore := range assessmentBefores {
  3889. if item.PatientId == assessmentBefore.PatientId {
  3890. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3891. break
  3892. }
  3893. }
  3894. // 透析上下机
  3895. for _, dialysisOrder := range dialysisOrders {
  3896. if item.PatientId == dialysisOrder.PatientId {
  3897. monitor[key].DialysisOrder = dialysisOrder
  3898. break
  3899. }
  3900. }
  3901. // 治疗小节
  3902. for _, afterDislysis := range AssessmentAfterDislysis {
  3903. if item.PatientId == afterDislysis.PatientId {
  3904. monitor[key].AssessmentAfterDislysis = afterDislysis
  3905. break
  3906. }
  3907. }
  3908. for _, it := range monitorlist {
  3909. if item.PatientId == it.PatientId {
  3910. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3911. }
  3912. }
  3913. for _, patient := range patients {
  3914. if item.PatientId == patient.ID {
  3915. monitor[key].MonitorPatients = patient
  3916. break
  3917. }
  3918. }
  3919. for _, treatment := range treatments {
  3920. if item.ModeId == treatment.ID {
  3921. monitor[key].TreatmentMode = treatment
  3922. break
  3923. }
  3924. }
  3925. }
  3926. }
  3927. }
  3928. //获取患者的透析次数
  3929. //count, err := service.GetDialysisCount(orgID, partition)
  3930. patients, err := service.GetAllpatientFourty(orgID)
  3931. if err == nil {
  3932. c.ServeSuccessJSON(map[string]interface{}{
  3933. "monitor": monitor,
  3934. //"patientCount": count,
  3935. "patients": patients,
  3936. })
  3937. } else {
  3938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3939. }
  3940. }
  3941. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3942. // @param keyword:string 病人姓名或透析号
  3943. // @param page:int
  3944. func (this *PatientApiController) SearchMonitorPatient() {
  3945. keyword := this.GetString("keyword")
  3946. page, _ := this.GetInt("page")
  3947. if page <= 0 {
  3948. page = 1
  3949. }
  3950. if len(keyword) == 0 {
  3951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3952. return
  3953. }
  3954. adminUserInfo := this.GetMobileAdminUserInfo()
  3955. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3956. if getMonitorErr != nil {
  3957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3958. return
  3959. } else {
  3960. this.ServeSuccessJSON(map[string]interface{}{
  3961. "monitor": monitors,
  3962. })
  3963. }
  3964. }
  3965. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3966. id, _ := c.GetInt64("id", 0)
  3967. page, _ := c.GetInt64("page", 0)
  3968. limit, _ := c.GetInt64("limit", 0)
  3969. if id <= 0 {
  3970. c.ServeSuccessJSON(map[string]interface{}{
  3971. "solutions": nil,
  3972. })
  3973. return
  3974. }
  3975. if page <= 0 {
  3976. page = 1
  3977. }
  3978. if limit <= 0 {
  3979. limit = 10
  3980. }
  3981. adminInfo := c.GetMobileAdminUserInfo()
  3982. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3983. c.ServeSuccessJSON(map[string]interface{}{
  3984. "solutions": solutions,
  3985. "total": total,
  3986. })
  3987. return
  3988. }
  3989. // GetDoctorAdvices 医嘱列表
  3990. func (c *PatientApiController) GetDoctorAdvices() {
  3991. id, _ := c.GetInt64("id", 0)
  3992. adviceType, _ := c.GetInt64("advice_type", 0)
  3993. stopType, _ := c.GetInt64("stop_state", 0)
  3994. startTime := c.GetString("start_time", "")
  3995. endTime := c.GetString("end_time", "")
  3996. keywords := c.GetString("keywords", "")
  3997. need, _ := c.GetInt64("need_doctor", 0)
  3998. adminUserInfo := c.GetMobileAdminUserInfo()
  3999. timeLayout := "2006-01-02"
  4000. loc, _ := time.LoadLocation("Local")
  4001. var theStartTIme int64
  4002. if len(startTime) > 0 {
  4003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4004. if err != nil {
  4005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4006. return
  4007. }
  4008. theStartTIme = theTime.Unix()
  4009. }
  4010. var theEndtTIme int64
  4011. if len(endTime) > 0 {
  4012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4013. if err != nil {
  4014. utils.ErrorLog(err.Error())
  4015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4016. return
  4017. }
  4018. theEndtTIme = theTime.Unix()
  4019. }
  4020. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4021. if need == 1 {
  4022. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4023. c.ServeSuccessJSON(map[string]interface{}{
  4024. "advices": advices,
  4025. "total": total,
  4026. "users": users,
  4027. })
  4028. } else {
  4029. c.ServeSuccessJSON(map[string]interface{}{
  4030. "advices": advices,
  4031. "total": total,
  4032. "users": []string{},
  4033. })
  4034. }
  4035. return
  4036. }
  4037. func (c *PatientApiController) GetPrintDialysisOrder() {
  4038. xtno := c.GetString("xtno")
  4039. xtdate := c.GetString("xtdate")
  4040. timeLayout := "2006-01-02"
  4041. loc, _ := time.LoadLocation("Local")
  4042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4043. if err != nil {
  4044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4045. return
  4046. }
  4047. xttime := theTime.Unix()
  4048. //获取当前日期月份的第一天
  4049. firstmonth := service.GetFirstDateOfMonth(theTime)
  4050. firstMonthDate := firstmonth.Unix()
  4051. operatorIDs := make([]int64, 0)
  4052. adminUserInfo := c.GetMobileAdminUserInfo()
  4053. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4054. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4055. //透析单
  4056. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4057. if dialysisOrder != nil {
  4058. if dialysisOrder.FinishNurse > 0 {
  4059. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4060. }
  4061. if dialysisOrder.StartNurse > 0 {
  4062. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4063. }
  4064. }
  4065. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4066. //透前评估
  4067. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4068. //透后评估
  4069. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4070. if AssessmentAfterDislysis.Modifier > 0 {
  4071. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4072. }
  4073. //透析处方
  4074. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4075. if dialysisPrescription.PrescriptionDoctor > 0 {
  4076. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4077. }
  4078. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4079. patientInfo.TotalDialysis = dialysis_count
  4080. //临时医嘱
  4081. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4082. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4083. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4084. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4085. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4086. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4087. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4088. for _, item := range projects {
  4089. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4090. var advice models.HisDoctorAdviceInfo
  4091. advice.ID = item.ID
  4092. advice.Checker = item.Checker
  4093. advice.CheckTime = item.CheckTime
  4094. advice.CheckState = item.CheckState
  4095. advice.ExecutionState = item.ExecutionState
  4096. advice.ExecutionStaff = item.ExecutionStaff
  4097. //advice.PrescribingNumber = float64(item.Count)
  4098. advice.PrescribingNumber = cnt
  4099. advice.PrescribingNumberUnit = item.Unit
  4100. advice.AdviceDoctor = item.Doctor
  4101. if item.Type == 3 {
  4102. advice.AdviceName = item.GoodInfo.GoodName
  4103. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4104. } else if item.Type == 2 {
  4105. advice.AdviceName = item.HisProject.ProjectName
  4106. }
  4107. advice.StartTime = item.StartTime
  4108. hisAdvice = append(hisAdvice, &advice)
  4109. }
  4110. }
  4111. if len(DoctorAdvice) > 0 {
  4112. for _, item := range DoctorAdvice {
  4113. if item.AdviceDoctor > 0 {
  4114. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4115. }
  4116. if item.ExecutionStaff > 0 {
  4117. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4118. }
  4119. if item.Checker > 0 {
  4120. operatorIDs = append(operatorIDs, item.Checker)
  4121. }
  4122. }
  4123. }
  4124. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4125. //透析监测
  4126. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4127. //透析小结
  4128. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4129. //接诊评估
  4130. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4131. //相关操作对应的操作人
  4132. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4133. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4134. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4135. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4136. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4137. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4138. if config.IsOpen == 1 {
  4139. c.ServeSuccessJSON(map[string]interface{}{
  4140. "users": adminUser,
  4141. "patientInfo": patientInfo,
  4142. "PredialysisEvaluation": PredialysisEvaluation,
  4143. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4144. "dialysisPrescription": dialysisPrescription,
  4145. "advices": hisAdvice,
  4146. "monitors": Record,
  4147. "summary": TreatmentSummary,
  4148. "receiverTreatmentAccess": receiverTreatmentAccess,
  4149. "dialysisOrder": dialysisOrder,
  4150. "operators": operators,
  4151. "org_template_info": templateInfo,
  4152. "check": check,
  4153. "dialysiscount": dialysiscount,
  4154. "last_order": last_order,
  4155. "projects": projects,
  4156. "project_config": project_config,
  4157. "lastWeight": lastWeight,
  4158. "lastSchedule": lastSchedule,
  4159. })
  4160. }
  4161. if config.IsOpen == 0 || config.IsOpen == 2 {
  4162. c.ServeSuccessJSON(map[string]interface{}{
  4163. "users": adminUser,
  4164. "patientInfo": patientInfo,
  4165. "PredialysisEvaluation": PredialysisEvaluation,
  4166. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4167. "dialysisPrescription": dialysisPrescription,
  4168. "advices": DoctorAdvice,
  4169. "monitors": Record,
  4170. "summary": TreatmentSummary,
  4171. "receiverTreatmentAccess": receiverTreatmentAccess,
  4172. "dialysisOrder": dialysisOrder,
  4173. "operators": operators,
  4174. "org_template_info": templateInfo,
  4175. "check": check,
  4176. "dialysiscount": dialysiscount,
  4177. "last_order": last_order,
  4178. "projects": projects,
  4179. "project_config": project_config,
  4180. "lastWeight": lastWeight,
  4181. "lastSchedule": lastSchedule,
  4182. })
  4183. }
  4184. }
  4185. func (c *PatientApiController) CreateGroupAdvice() {
  4186. is_child, _ := c.GetInt64("is_child", 0)
  4187. if is_child == 1 {
  4188. patient, _ := c.GetInt64("id", 0)
  4189. if patient <= 0 {
  4190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4191. return
  4192. }
  4193. adminUserInfo := c.GetMobileAdminUserInfo()
  4194. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4195. if patientInfo.ID == 0 {
  4196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4197. return
  4198. }
  4199. group_no, _ := c.GetInt64("group_no")
  4200. if group_no <= 0 {
  4201. group_no = 0
  4202. }
  4203. dataBody := make(map[string]interface{}, 0)
  4204. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4205. if err != nil {
  4206. utils.ErrorLog(err.Error())
  4207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4208. return
  4209. }
  4210. timeLayout := "2006-01-02"
  4211. loc, _ := time.LoadLocation("Local")
  4212. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4213. utils.ErrorLog("advice_type")
  4214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4215. return
  4216. }
  4217. adviceType := int64(dataBody["advice_type"].(float64))
  4218. if adviceType != 1 && adviceType != 2 {
  4219. utils.ErrorLog("advice_type != 1&&2")
  4220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4221. return
  4222. }
  4223. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4224. utils.ErrorLog("start_time")
  4225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. startTime2, _ := dataBody["start_time"].(string)
  4229. time_arr := strings.Split(startTime2, " ")
  4230. if len(time_arr) > 0 {
  4231. startTime2 = time_arr[0]
  4232. }
  4233. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4234. utils.ErrorLog("advice_date")
  4235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4236. return
  4237. }
  4238. advice_date, _ := dataBody["advice_date"].(string)
  4239. var advicedateunix int64
  4240. if len(advice_date) > 0 {
  4241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4242. if err != nil {
  4243. fmt.Println(err)
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4245. return
  4246. }
  4247. advicedateunix = theTime.Unix()
  4248. }
  4249. adviceDate := startTime2
  4250. if len(adviceDate) == 0 {
  4251. utils.ErrorLog("len(adviceDate) == 0")
  4252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4253. return
  4254. }
  4255. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4256. if err != nil {
  4257. utils.ErrorLog(err.Error())
  4258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4259. return
  4260. }
  4261. AdviceDate := advicedateunix
  4262. RecordDate := advicedateunix
  4263. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4264. utils.ErrorLog("start_time")
  4265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4266. return
  4267. }
  4268. startTime, _ := dataBody["start_time"].(string)
  4269. if len(startTime) == 0 {
  4270. utils.ErrorLog("len(start_time) == 0")
  4271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4272. return
  4273. }
  4274. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4275. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4276. if err != nil {
  4277. utils.ErrorLog(err.Error())
  4278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4279. return
  4280. }
  4281. StartTime := theTime.Unix()
  4282. Remark := ""
  4283. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4284. remark, _ := dataBody["remark"].(string)
  4285. Remark = remark
  4286. }
  4287. Startdate := int64(dataBody["record_date"].(float64))
  4288. var advices []*models.GroupAdvice
  4289. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4290. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4291. utils.ErrorLog("adviceNames")
  4292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4293. return
  4294. }
  4295. adviceNames := dataBody["adviceNames"].([]interface{})
  4296. for _, adviceNameMap := range adviceNames {
  4297. adviceNameM := adviceNameMap.(map[string]interface{})
  4298. var advice models.GroupAdvice
  4299. advice.Remark = Remark
  4300. advice.AdviceType = adviceType
  4301. advice.StartTime = StartTime
  4302. if adminUserInfo.Org.Id == 10340 {
  4303. advice.AdviceDate = AdviceDate
  4304. advice.RecordDate = RecordDate
  4305. }
  4306. if adminUserInfo.Org.Id != 10340 {
  4307. advice.AdviceDate = theTimeOne.Unix()
  4308. advice.RecordDate = theTimeOne.Unix()
  4309. }
  4310. advice.Status = 1
  4311. advice.CreatedTime = time.Now().Unix()
  4312. advice.UpdatedTime = time.Now().Unix()
  4313. advice.StopState = 2
  4314. advice.ExecutionState = 2
  4315. advice.UserOrgId = adminUserInfo.Org.Id
  4316. advice.PatientId = patientInfo.ID
  4317. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4318. advice.IsSettle = 2
  4319. //入口
  4320. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4321. if errcode > 0 {
  4322. c.ServeFailJSONWithSGJErrorCode(errcode)
  4323. return
  4324. }
  4325. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4326. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4327. if len(subdrugs) > 0 {
  4328. for _, subdrug := range subdrugs {
  4329. var s models.GroupAdvice
  4330. s.Remark = Remark
  4331. s.AdviceType = adviceType
  4332. s.StartTime = StartTime
  4333. s.AdviceDate = AdviceDate
  4334. s.RecordDate = RecordDate
  4335. s.Status = 1
  4336. s.CreatedTime = time.Now().Unix()
  4337. s.UpdatedTime = time.Now().Unix()
  4338. s.StopState = 2
  4339. s.ExecutionState = 2
  4340. s.UserOrgId = adminUserInfo.Org.Id
  4341. s.PatientId = patientInfo.ID
  4342. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4343. s.IsSettle = 2
  4344. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4345. if errcode > 0 {
  4346. c.ServeFailJSONWithSGJErrorCode(errcode)
  4347. return
  4348. }
  4349. advice.Children = append(advice.Children, &s)
  4350. }
  4351. }
  4352. }
  4353. //长沙南雅
  4354. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4355. //查询该患者今日有没有双人核对
  4356. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4357. if check.ID > 0 {
  4358. advice.Checker = check.Modifier
  4359. advice.CheckState = 1
  4360. advice.CheckTime = time.Now().Unix()
  4361. }
  4362. }
  4363. advices = append(advices, &advice)
  4364. }
  4365. // 查询信息规挡的设置天数
  4366. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4367. if infor.ID > 0 && infor.WeekDay > 0 {
  4368. var cha_time int64
  4369. timeNowStr := time.Now().Format("2006-01-02")
  4370. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4371. //今日的日期减去设置的日期
  4372. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4373. if cha_time >= Startdate {
  4374. //查询审核是否允许
  4375. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4376. //申请状态不允许的情况 拒绝修改
  4377. if infor.ApplicationStatus != 1 {
  4378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4379. return
  4380. }
  4381. }
  4382. }
  4383. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4384. for _, item := range advices {
  4385. //记录日志
  4386. byterequest, _ := json.Marshal(item)
  4387. adviceLog := models.XtDoctorAdviceLog{
  4388. UserOrgId: item.UserOrgId,
  4389. PatientId: item.PatientId,
  4390. AdminUserId: adminUserInfo.AdminUser.Id,
  4391. Module: 1,
  4392. ErrLog: string(byterequest),
  4393. Status: 1,
  4394. Ctime: time.Now().Unix(),
  4395. Mtime: 0,
  4396. Source: "手机端新增医嘱",
  4397. RecordDate: item.AdviceDate,
  4398. }
  4399. service.CreateDoctorAdviceLog(adviceLog)
  4400. }
  4401. finish := models.XtDialysisFinish{
  4402. IsFinish: 1,
  4403. UserOrgId: adminUserInfo.Org.Id,
  4404. Status: 1,
  4405. Ctime: time.Now().Unix(),
  4406. Mtime: 0,
  4407. Module: 4,
  4408. RecordDate: advicedateunix,
  4409. Sourse: 1,
  4410. PatientId: patient,
  4411. }
  4412. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4413. if dialysisFinish.ID == 0 {
  4414. service.CreateDialysisFinish(finish)
  4415. }
  4416. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4417. redis := service.RedisClient()
  4418. //清空key 值
  4419. redis.Set(key, "", time.Second)
  4420. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4421. redis.Set(keyOne, "", time.Second)
  4422. defer redis.Close()
  4423. if createErr != nil {
  4424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4425. return
  4426. }
  4427. c.ServeSuccessJSON(map[string]interface{}{
  4428. "msg": "ok",
  4429. "advices": newAdvices,
  4430. })
  4431. return
  4432. } else if is_child == 2 {
  4433. patient, _ := c.GetInt64("id", 0)
  4434. if patient <= 0 {
  4435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4436. return
  4437. }
  4438. adminUserInfo := c.GetMobileAdminUserInfo()
  4439. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4440. if patientInfo.ID == 0 {
  4441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4442. return
  4443. }
  4444. var advice models.DoctorAdvice
  4445. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  4446. if code > 0 {
  4447. c.ServeFailJSONWithSGJErrorCode(code)
  4448. return
  4449. }
  4450. if advice.ParentId > 0 {
  4451. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  4452. if old.ID == 0 || old.PatientId != patient {
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  4454. return
  4455. }
  4456. if old.StopState == 1 || old.ExecutionState == 1 {
  4457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  4458. return
  4459. }
  4460. if old.ParentId > 0 {
  4461. advice.ParentId = old.ParentId
  4462. }
  4463. advice.StartTime = old.StartTime
  4464. advice.AdviceDoctor = old.AdviceDoctor
  4465. advice.DeliveryWay = old.DeliveryWay
  4466. advice.ExecutionFrequency = old.ExecutionFrequency
  4467. advice.GroupNo = old.GroupNo
  4468. }
  4469. advice.Status = 1
  4470. advice.CreatedTime = time.Now().Unix()
  4471. advice.UpdatedTime = time.Now().Unix()
  4472. advice.StopState = 2
  4473. advice.ExecutionState = 2
  4474. advice.UserOrgId = adminUserInfo.Org.Id
  4475. advice.PatientId = patient
  4476. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4477. advice.IsSettle = 2
  4478. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4479. if advice.PrescribingNumber == 0 {
  4480. advice.PrescribingNumber = 1
  4481. }
  4482. //查询该患者今日有没有双人核对
  4483. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  4484. if check.ID > 0 {
  4485. advice.Checker = check.Modifier
  4486. advice.CheckState = 1
  4487. advice.CheckTime = time.Now().Unix()
  4488. }
  4489. }
  4490. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4491. if infor.ID > 0 {
  4492. var cha_time int64
  4493. timeNowStr := time.Now().Format("2006-01-02")
  4494. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4495. //今日的日期减去设置的日期
  4496. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4497. if cha_time >= advice.RecordDate {
  4498. //查询审核是否允许
  4499. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  4500. //申请状态不允许的情况 拒绝修改
  4501. if infor.ApplicationStatus != 1 {
  4502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4503. return
  4504. }
  4505. }
  4506. }
  4507. err := service.CreateDoctorAdvice(&advice)
  4508. //记录日志
  4509. byterequest, _ := json.Marshal(advice)
  4510. adviceLog := models.XtDoctorAdviceLog{
  4511. UserOrgId: advice.UserOrgId,
  4512. PatientId: advice.PatientId,
  4513. AdminUserId: adminUserInfo.Org.Id,
  4514. Module: 1,
  4515. ErrLog: string(byterequest),
  4516. Status: 1,
  4517. Ctime: time.Now().Unix(),
  4518. Mtime: 0,
  4519. Source: "手机端新增医嘱",
  4520. RecordDate: advice.AdviceDate,
  4521. }
  4522. service.CreateDoctorAdviceLog(adviceLog)
  4523. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  4524. redis := service.RedisClient()
  4525. //清空key 值
  4526. redis.Set(key, "", time.Second)
  4527. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  4528. redis.Set(keyOne, "", time.Second)
  4529. defer redis.Close()
  4530. if err != nil {
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4532. return
  4533. }
  4534. c.ServeSuccessJSON(map[string]interface{}{
  4535. "msg": "ok",
  4536. "advice": advice,
  4537. })
  4538. return
  4539. }
  4540. }
  4541. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  4542. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  4543. utils.ErrorLog("advice_name")
  4544. return enums.ErrorCodeParamWrong
  4545. }
  4546. adviceName, _ := json["advice_name"].(string)
  4547. if len(adviceName) == 0 {
  4548. utils.ErrorLog("len(advice_name) == 0")
  4549. return enums.ErrorCodeParamWrong
  4550. }
  4551. advice.AdviceName = adviceName
  4552. adviceDesc, _ := json["advice_desc"].(string)
  4553. advice.AdviceDesc = adviceDesc
  4554. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4555. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4556. advice.DrugSpec = drugSpec
  4557. }
  4558. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4559. remark, _ := json["remark"].(string)
  4560. advice.Remark = remark
  4561. }
  4562. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  4563. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  4564. // advice.Way = src_type
  4565. //}
  4566. if json["way"] == nil {
  4567. advice.Way = 0
  4568. } else {
  4569. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  4570. way := int64(json["way"].(float64))
  4571. advice.Way = way
  4572. }
  4573. }
  4574. if json["drug_id"] == nil {
  4575. advice.DrugId = 0
  4576. } else {
  4577. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  4578. drug_id := int64(json["drug_id"].(float64))
  4579. advice.DrugId = drug_id
  4580. }
  4581. }
  4582. if json["drug_name_id"] == nil {
  4583. advice.DrugNameId = 0
  4584. } else {
  4585. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  4586. drug_name_id := int64(json["drug_name_id"].(float64))
  4587. advice.DrugNameId = drug_name_id
  4588. }
  4589. }
  4590. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  4591. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  4592. advice.DrugSpecUnit = drugSpecUnit
  4593. }
  4594. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4595. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4596. advice.SingleDose = singleDose
  4597. }
  4598. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4599. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4600. advice.SingleDoseUnit = singleDoseUnit
  4601. }
  4602. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4603. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4604. advice.PrescribingNumber = prescribingNumber
  4605. }
  4606. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4607. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4608. advice.PrescribingNumberUnit = prescribingNumberUnit
  4609. }
  4610. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4611. deliveryWay, _ := json["delivery_way"].(string)
  4612. advice.DeliveryWay = deliveryWay
  4613. }
  4614. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4615. executionFrequency, _ := json["execution_frequency"].(string)
  4616. advice.ExecutionFrequency = executionFrequency
  4617. }
  4618. return 0
  4619. }
  4620. func (c *PatientApiController) DelDoctorAdvice() {
  4621. groupno, _ := c.GetInt64("groupno", -1)
  4622. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  4623. patient_id, _ := c.GetInt64("patient_id")
  4624. doc_advice_date, _ := c.GetInt64("advice_date")
  4625. redis := service.RedisClient()
  4626. if is_sub == 1 { //是
  4627. advice_id, _ := c.GetInt64("advice_id")
  4628. adminUserInfo := c.GetMobileAdminUserInfo()
  4629. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4630. if advice.ID == 0 {
  4631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4632. return
  4633. }
  4634. advice.Status = 0
  4635. advice.UpdatedTime = time.Now().Unix()
  4636. advice.Modifier = adminUserInfo.AdminUser.Id
  4637. // 查询信息规挡的设置天数
  4638. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4639. if infor.ID > 0 && infor.WeekDay > 0 {
  4640. var cha_time int64
  4641. timeNowStr := time.Now().Format("2006-01-02")
  4642. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4643. //今日的日期减去设置的日期
  4644. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4645. if cha_time >= advice.AdviceDate {
  4646. //查询审核是否允许
  4647. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4648. //申请状态不允许的情况 拒绝修改
  4649. if infor.ApplicationStatus != 1 {
  4650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4651. return
  4652. }
  4653. }
  4654. }
  4655. err := service.DeleteDoctorAdvice(&advice)
  4656. //记录日志
  4657. byterequest, _ := json.Marshal(advice)
  4658. adviceLog := models.XtDoctorAdviceLog{
  4659. UserOrgId: advice.UserOrgId,
  4660. PatientId: advice.PatientId,
  4661. AdminUserId: adminUserInfo.AdminUser.Id,
  4662. Module: 4,
  4663. ErrLog: string(byterequest),
  4664. Status: 1,
  4665. Ctime: time.Now().Unix(),
  4666. Mtime: 0,
  4667. Source: "手机端删除医嘱",
  4668. RecordDate: advice.RecordDate,
  4669. }
  4670. service.CreateDoctorAdviceLog(adviceLog)
  4671. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4672. redis.Set(key, "", time.Second)
  4673. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4674. redis.Set(keyTwo, "", time.Second)
  4675. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4676. redis.Set(keyThree, "", time.Second)
  4677. redis.Close()
  4678. if err != nil {
  4679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4680. return
  4681. }
  4682. c.ServeSuccessJSON(map[string]interface{}{
  4683. "msg": "ok",
  4684. })
  4685. return
  4686. } else { //
  4687. var ids []string
  4688. if groupno == 0 {
  4689. advice_id := c.GetString("advice_id")
  4690. ids = strings.Split(advice_id, ",")
  4691. if len(ids) <= 0 {
  4692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4693. return
  4694. }
  4695. }
  4696. if groupno < 0 {
  4697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4698. return
  4699. }
  4700. adminUserInfo := c.GetMobileAdminUserInfo()
  4701. var advice models.DoctorAdvice
  4702. if groupno > 0 {
  4703. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4704. if advice.ID == 0 {
  4705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4706. return
  4707. }
  4708. } else {
  4709. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4710. for _, item := range advices {
  4711. if item.ID == 0 {
  4712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4713. return
  4714. }
  4715. }
  4716. }
  4717. advice.UpdatedTime = time.Now().Unix()
  4718. advice.Status = 0
  4719. advice.GroupNo = groupno
  4720. advice.Modifier = adminUserInfo.AdminUser.Id
  4721. var err error
  4722. if groupno > 0 {
  4723. // 查询信息规挡的设置天数
  4724. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4725. if infor.ID > 0 {
  4726. var cha_time int64
  4727. timeNowStr := time.Now().Format("2006-01-02")
  4728. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4729. //今日的日期减去设置的日期
  4730. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4731. if cha_time >= advice.AdviceDate {
  4732. //查询审核是否允许
  4733. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4734. //申请状态不允许的情况 拒绝修改
  4735. if infor.ApplicationStatus != 1 {
  4736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4737. return
  4738. }
  4739. }
  4740. }
  4741. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4742. //记录日志
  4743. byterequest, _ := json.Marshal(advice)
  4744. adviceLog := models.XtDoctorAdviceLog{
  4745. UserOrgId: advice.UserOrgId,
  4746. PatientId: advice.PatientId,
  4747. AdminUserId: adminUserInfo.AdminUser.Id,
  4748. Module: 4,
  4749. ErrLog: string(byterequest),
  4750. Status: 1,
  4751. Ctime: time.Now().Unix(),
  4752. Mtime: 0,
  4753. Source: "手机端删除医嘱",
  4754. RecordDate: advice.RecordDate,
  4755. }
  4756. service.CreateDoctorAdviceLog(adviceLog)
  4757. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4758. redis.Set(key, "", time.Second)
  4759. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4760. redis.Set(keyTwo, "", time.Second)
  4761. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4762. redis.Set(keyThree, "", time.Second)
  4763. } else {
  4764. // 查询信息规挡的设置天数
  4765. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4766. if infor.ID > 0 {
  4767. var cha_time int64
  4768. timeNowStr := time.Now().Format("2006-01-02")
  4769. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4770. //今日的日期减去设置的日期
  4771. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4772. if cha_time >= advice.AdviceDate {
  4773. //查询审核是否允许
  4774. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4775. //申请状态不允许的情况 拒绝修改
  4776. if infor.ApplicationStatus != 1 {
  4777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4778. return
  4779. }
  4780. }
  4781. }
  4782. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4783. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  4784. for _, item := range advicelist {
  4785. //记录日志
  4786. byterequest, _ := json.Marshal(item)
  4787. adviceLog := models.XtDoctorAdviceLog{
  4788. UserOrgId: item.UserOrgId,
  4789. PatientId: item.PatientId,
  4790. AdminUserId: adminUserInfo.AdminUser.Id,
  4791. Module: 4,
  4792. ErrLog: string(byterequest),
  4793. Status: 1,
  4794. Ctime: time.Now().Unix(),
  4795. Mtime: 0,
  4796. Source: "手机端批量删除医嘱",
  4797. RecordDate: item.RecordDate,
  4798. }
  4799. service.CreateDoctorAdviceLog(adviceLog)
  4800. }
  4801. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4802. redis.Set(key, "", time.Second)
  4803. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4804. redis.Set(keyTwo, "", time.Second)
  4805. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4806. redis.Set(keyThree, "", time.Second)
  4807. redis.Close()
  4808. }
  4809. if err != nil {
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4811. return
  4812. }
  4813. c.ServeSuccessJSON(map[string]interface{}{
  4814. "msg": "ok",
  4815. })
  4816. return
  4817. }
  4818. }
  4819. // /m/api/advice/group/modify_starttime [post]
  4820. // @param group_no:int
  4821. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4822. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4823. group_no, _ := this.GetInt64("group_no")
  4824. start_time_str := this.GetString("start_time")
  4825. if group_no <= 0 || len(start_time_str) == 0 {
  4826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4827. return
  4828. }
  4829. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4830. if parseTimeErr != nil {
  4831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4832. return
  4833. }
  4834. adminUserInfo := this.GetMobileAdminUserInfo()
  4835. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4836. if updateStartTimeErr != nil {
  4837. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4839. return
  4840. }
  4841. this.ServeSuccessJSON(map[string]interface{}{
  4842. "start_time": startTime.Unix(),
  4843. })
  4844. }
  4845. func (this *PatientApiController) DelSubDoctorAdvice() {
  4846. advice_id, _ := this.GetInt64("advice_id")
  4847. adminUserInfo := this.GetMobileAdminUserInfo()
  4848. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4849. if advice.ID == 0 {
  4850. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4851. return
  4852. }
  4853. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4854. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4855. // return
  4856. //}
  4857. advice.Status = 0
  4858. advice.UpdatedTime = time.Now().Unix()
  4859. advice.Modifier = adminUserInfo.AdminUser.Id
  4860. err := service.DeleteDoctorAdvice(&advice)
  4861. if err != nil {
  4862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4863. return
  4864. }
  4865. this.ServeSuccessJSON(map[string]interface{}{
  4866. "msg": "ok",
  4867. })
  4868. return
  4869. }
  4870. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4871. //adminUserInfo := this.GetMobileAdminUserInfo()
  4872. //service.FindUnReadDoctorAdviceMessage()
  4873. }
  4874. func (this *PatientApiController) GetPatientsByKeyWord() {
  4875. keyWord := this.GetString("keyword")
  4876. adminUserInfo := this.GetMobileAdminUserInfo()
  4877. today := utils.ZeroHourTimeOfDay(time.Now())
  4878. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4879. if err != nil {
  4880. utils.ErrorLog(err.Error())
  4881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4882. return
  4883. }
  4884. this.ServeSuccessJSON(map[string]interface{}{
  4885. "patient": patient,
  4886. })
  4887. }
  4888. func (this *PatientApiController) GetSearchPatient() {
  4889. keyWord := this.GetString("keyword")
  4890. adminUserInfo := this.GetMobileAdminUserInfo()
  4891. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4892. if err != nil {
  4893. utils.ErrorLog(err.Error())
  4894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4895. return
  4896. }
  4897. this.ServeSuccessJSON(map[string]interface{}{
  4898. "patient": patient,
  4899. })
  4900. }
  4901. func (c *PatientApiController) ExecProject() {
  4902. execution_time := c.GetString("execution_time")
  4903. project_id, _ := c.GetInt64("project_id")
  4904. team_id, _ := c.GetInt64("team_id")
  4905. is_check_team, _ := c.GetInt64("is_check_team")
  4906. if len(execution_time) <= 0 {
  4907. utils.ErrorLog("execution_time")
  4908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4909. return
  4910. }
  4911. timeLayout2 := "2006-01-02 15:04:05"
  4912. loc, _ := time.LoadLocation("Local")
  4913. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4914. if errs != nil {
  4915. utils.ErrorLog(errs.Error())
  4916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4917. return
  4918. }
  4919. adminInfo := c.GetMobileAdminUserInfo()
  4920. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4921. if project.Type == 3 {
  4922. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4923. if good.IsUser != 1 {
  4924. //查询开关是否开启
  4925. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4926. //开关已经开启
  4927. if stockSetting.IsType == 1 {
  4928. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4929. scheduleDateStart := theTime.Format("2006-01-02")
  4930. timeLayout3 := "2006-01-02"
  4931. loc, _ := time.LoadLocation("Local")
  4932. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4933. //查询该耗材是否已经出库
  4934. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4935. if auto.ID == 0 {
  4936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4937. return
  4938. }
  4939. }
  4940. }
  4941. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4942. //查询开关是否开启
  4943. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4944. //开关已经开启
  4945. if stockSetting.IsType == 1 {
  4946. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4947. scheduleDateStart := theTime.Format("2006-01-02")
  4948. timeLayout3 := "2006-01-02"
  4949. loc, _ := time.LoadLocation("Local")
  4950. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4951. //查询该耗材是否已经出库
  4952. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4953. if auto.ID == 0 {
  4954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4955. return
  4956. }
  4957. }
  4958. }
  4959. }
  4960. if project.ExecutionState == 1 {
  4961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4962. return
  4963. }
  4964. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4966. return
  4967. }
  4968. project.ExecutionState = 1
  4969. project.ExecutionStaff = adminInfo.AdminUser.Id
  4970. project.ExecutionTime = theTime.Unix()
  4971. if team_id == 0 {
  4972. // 查询信息规挡的设置天数
  4973. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4974. if infor.ID > 0 {
  4975. var cha_time int64
  4976. timeNowStr := time.Now().Format("2006-01-02")
  4977. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4978. //今日的日期减去设置的日期
  4979. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4980. if cha_time >= project.RecordDate {
  4981. //查询审核是否允许
  4982. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4983. //申请状态不允许的情况 拒绝修改
  4984. if infor.ApplicationStatus != 1 {
  4985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4986. return
  4987. }
  4988. }
  4989. }
  4990. err := service.SaveHisProject(&project)
  4991. if err == nil {
  4992. c.ServeSuccessJSON(map[string]interface{}{
  4993. "project": project,
  4994. })
  4995. } else {
  4996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4997. return
  4998. }
  4999. } else {
  5000. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5001. // 查询信息规挡的设置天数
  5002. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5003. if infor.ID > 0 {
  5004. var cha_time int64
  5005. timeNowStr := time.Now().Format("2006-01-02")
  5006. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5007. //今日的日期减去设置的日期
  5008. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5009. if cha_time >= project.RecordDate {
  5010. //查询审核是否允许
  5011. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5012. //申请状态不允许的情况 拒绝修改
  5013. if infor.ApplicationStatus != 1 {
  5014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5015. return
  5016. }
  5017. }
  5018. }
  5019. err := service.SaveHisProject(&project)
  5020. if err == nil {
  5021. c.ServeSuccessJSON(map[string]interface{}{
  5022. "project": project,
  5023. })
  5024. } else {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5026. return
  5027. }
  5028. } else {
  5029. // 查询信息规挡的设置天数
  5030. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5031. if infor.ID > 0 {
  5032. var cha_time int64
  5033. timeNowStr := time.Now().Format("2006-01-02")
  5034. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5035. //今日的日期减去设置的日期
  5036. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5037. if cha_time >= project.RecordDate {
  5038. //查询审核是否允许
  5039. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5040. //申请状态不允许的情况 拒绝修改
  5041. if infor.ApplicationStatus != 1 {
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5043. return
  5044. }
  5045. }
  5046. }
  5047. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5048. var ids []int64
  5049. for _, items := range ps {
  5050. ids = append(ids, items.ID)
  5051. }
  5052. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5053. if err == nil {
  5054. c.ServeSuccessJSON(map[string]interface{}{
  5055. "project": project,
  5056. })
  5057. } else {
  5058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5059. return
  5060. }
  5061. }
  5062. }
  5063. }
  5064. func (c *PatientApiController) CheckProject() {
  5065. adminInfo := c.GetMobileAdminUserInfo()
  5066. project_id, _ := c.GetInt64("project_id")
  5067. team_id, _ := c.GetInt64("team_id")
  5068. is_check_team, _ := c.GetInt64("is_check_team")
  5069. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5070. if project.CheckState == 1 {
  5071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5072. return
  5073. }
  5074. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5076. return
  5077. }
  5078. project.Checker = adminInfo.AdminUser.Id
  5079. project.CheckTime = time.Now().Unix()
  5080. project.CheckState = 1
  5081. if team_id == 0 {
  5082. // 查询信息规挡的设置天数
  5083. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5084. if infor.ID > 0 {
  5085. var cha_time int64
  5086. timeNowStr := time.Now().Format("2006-01-02")
  5087. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5088. //今日的日期减去设置的日期
  5089. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5090. if cha_time >= project.RecordDate {
  5091. //查询审核是否允许
  5092. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5093. //申请状态不允许的情况 拒绝修改
  5094. if infor.ApplicationStatus != 1 {
  5095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5096. return
  5097. }
  5098. }
  5099. }
  5100. err := service.SaveHisProject(&project)
  5101. if err == nil {
  5102. c.ServeSuccessJSON(map[string]interface{}{
  5103. "msg": "ok",
  5104. "project": project,
  5105. })
  5106. } else {
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5108. return
  5109. }
  5110. } else {
  5111. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5112. // 查询信息规挡的设置天数
  5113. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5114. if infor.ID > 0 {
  5115. var cha_time int64
  5116. timeNowStr := time.Now().Format("2006-01-02")
  5117. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5118. //今日的日期减去设置的日期
  5119. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5120. if cha_time >= project.RecordDate {
  5121. //查询审核是否允许
  5122. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5123. //申请状态不允许的情况 拒绝修改
  5124. if infor.ApplicationStatus != 1 {
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5126. return
  5127. }
  5128. }
  5129. }
  5130. err := service.SaveHisProject(&project)
  5131. if err == nil {
  5132. c.ServeSuccessJSON(map[string]interface{}{
  5133. "msg": "ok",
  5134. "project": project,
  5135. })
  5136. } else {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5138. return
  5139. }
  5140. } else {
  5141. // 查询信息规挡的设置天数
  5142. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5143. if infor.ID > 0 {
  5144. var cha_time int64
  5145. timeNowStr := time.Now().Format("2006-01-02")
  5146. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5147. //今日的日期减去设置的日期
  5148. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5149. if cha_time >= project.RecordDate {
  5150. //查询审核是否允许
  5151. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5152. //申请状态不允许的情况 拒绝修改
  5153. if infor.ApplicationStatus != 1 {
  5154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5155. return
  5156. }
  5157. }
  5158. }
  5159. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5160. var ids []int64
  5161. for _, items := range ps {
  5162. ids = append(ids, items.ID)
  5163. }
  5164. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5165. if err == nil {
  5166. c.ServeSuccessJSON(map[string]interface{}{
  5167. "project": project,
  5168. })
  5169. } else {
  5170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5171. return
  5172. }
  5173. }
  5174. }
  5175. }