patient_api_controller.go 210KB

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