patient_api_controller.go 208KB

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