patient_api_controller.go 210KB

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