dialysis_api_controller.go 269KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "math"
  16. )
  17. // type DialysisTestAPIController struct {
  18. // MobileBaseAPIController
  19. // }
  20. // [get]/m/api/test
  21. // func (this *DialysisTestAPIController) Test() {
  22. // orgID := int64(3907)
  23. // now := time.Now()
  24. // nextWeek := now.AddDate(0, 0, 7)
  25. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  26. // nextTwoWeek := now.AddDate(0, 0, 14)
  27. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  28. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  29. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  30. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  31. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. // return
  33. // }
  34. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  35. // if exchangeErr != nil {
  36. // this.ErrorLog("%v", exchangeErr)
  37. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. // return
  39. // }
  40. // this.ServeSuccessJSON(map[string]interface{}{
  41. // // "now": now,
  42. // // "next_week": nextWeek,f
  43. // // "next_week_mon": nextWeekMon,
  44. // // "next_week_sun": nextWeekSun,
  45. // // "next_two_week_mon": nextTwoWeekMon,
  46. // // "next_two_week_sun": nextTwoWeekSun,
  47. // "next_week_schs": nextWeekSchs,
  48. // "next_two_week_schs": nextTwoWeekSchs,
  49. // })
  50. // }
  51. type DialysisAPIController struct {
  52. MobileBaseAPIAuthController
  53. }
  54. // /m/api/scheduals [get]
  55. // @param type:int
  56. // @param date:string
  57. func (this *DialysisAPIController) Scheduals() {
  58. schedualType, _ := this.GetInt64("type")
  59. schedualDate := this.GetString("date")
  60. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  61. schedualType = 0
  62. }
  63. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  64. if parseDateErr != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. adminInfo := this.GetMobileAdminUserInfo()
  69. orgID := adminInfo.Org.Id
  70. redis := service.RedisClient()
  71. defer redis.Close()
  72. // cur_date := time.Now().Format("2006-01-02")
  73. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  74. scheduals_json_str, _ := redis.Get(key).Result()
  75. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  76. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  77. if err != nil {
  78. this.ErrorLog("获取排班信息失败:%v", err)
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  80. } else {
  81. if len(scheduals) > 0 {
  82. //缓存数据
  83. scheduals_json, err := json.Marshal(scheduals)
  84. if err == nil {
  85. redis.Set(key, scheduals_json, time.Minute*1)
  86. }
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "scheduals": scheduals,
  90. })
  91. }
  92. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  93. var dat []map[string]interface{}
  94. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  95. } else {
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "scheduals": dat,
  99. "redis": "true",
  100. "date": schedualDate,
  101. })
  102. }
  103. }
  104. // /m/api/waiting_scheduals [get]
  105. // @param date:string
  106. func (this *DialysisAPIController) WaitingScheduals() {
  107. schedualDate := this.GetString("date")
  108. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  109. if parseDateErr != nil && len(schedualDate) != 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. adminInfo := this.GetMobileAdminUserInfo()
  114. orgID := adminInfo.Org.Id
  115. redis := service.RedisClient()
  116. defer redis.Close()
  117. // cur_date := time.Now().Format("2006-01-02")
  118. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  119. wait_scheduals, _ := redis.Get(key).Result()
  120. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  121. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  122. if err != nil {
  123. this.ErrorLog("获取排班信息失败:%v", err)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. } else {
  126. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  127. for _, s := range scheduals {
  128. returnScheduals = append(returnScheduals, s)
  129. }
  130. if len(returnScheduals) > 0 {
  131. //缓存数据
  132. wait_scheduals_json, err := json.Marshal(scheduals)
  133. if err == nil {
  134. redis.Set(key, wait_scheduals_json, time.Minute*2)
  135. }
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "scheduals": scheduals,
  139. })
  140. }
  141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  142. var dat []map[string]interface{}
  143. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  144. } else {
  145. }
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "scheduals": dat,
  148. "redis": "true",
  149. "date": schedualDate,
  150. })
  151. }
  152. }
  153. //else{
  154. // fmt.Println("33333333")
  155. //
  156. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  157. // if err != nil {
  158. // this.ErrorLog("获取排班信息失败:%v", err)
  159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. // } else {
  161. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  162. // for _, s := range scheduals {
  163. //
  164. // returnScheduals = append(returnScheduals, s)
  165. // }
  166. //
  167. // this.ServeSuccessJSON(map[string]interface{}{
  168. // "scheduals": returnScheduals,
  169. // })
  170. // }
  171. //
  172. // }
  173. //if err == nil{
  174. //
  175. //
  176. //
  177. //
  178. //
  179. //}else{
  180. //}
  181. // /m/api/dialysis/record [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisAPIController) DialysisRecord() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetMobileAdminUserInfo()
  201. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  202. if getPatientErr != nil {
  203. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. } else if patient == nil {
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  211. // this.TraceLog("==================================%+v", schedual)
  212. if getSchedualErr != nil {
  213. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  218. if getRTARErr != nil {
  219. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  224. if getPEErr != nil {
  225. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  230. if getLPEErr != nil {
  231. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  236. if getDoctorAdvicesErr != nil {
  237. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  242. if getDialysisOrderErr != nil {
  243. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. return
  246. }
  247. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  248. if getDoubleCheckErr != nil {
  249. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  254. if getMonitorRecordsErr != nil {
  255. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  257. return
  258. }
  259. var lastMonitorRecord *models.MonitoringRecord
  260. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  261. if getLastErr != nil {
  262. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  264. return
  265. }
  266. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  267. if getAADErr != nil {
  268. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  270. return
  271. }
  272. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  273. if getLAADErr != nil {
  274. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  276. return
  277. }
  278. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  279. if getTreatmentSummaryErr != nil {
  280. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  282. return
  283. }
  284. dialysisPrescribe, getDialysisPrescribeErr := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  285. if getDialysisPrescribeErr != nil {
  286. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  288. return
  289. }
  290. dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  291. if getDialysisSolutionErr != nil {
  292. this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  294. return
  295. }
  296. lastDialysisPrescribe, getDialysisPrescribeErr := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  297. if getDialysisPrescribeErr != nil {
  298. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  300. return
  301. }
  302. //获取系统透析处方模版
  303. systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  304. if getSystemDialysisPrescribeErr != nil {
  305. this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  307. return
  308. }
  309. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  310. operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  311. if getLPEErr != nil {
  312. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  314. return
  315. }
  316. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  317. if getDryErr != nil {
  318. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  320. return
  321. }
  322. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  323. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  324. goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  325. goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  326. returnData := map[string]interface{}{
  327. "patient": patient,
  328. "schedual": schedual,
  329. "prescription": dialysisPrescribe,
  330. "solution": dialysisSolution,
  331. "last_prescription": lastDialysisPrescribe,
  332. "receiver_treatment_access": receiverTreatmentAccess,
  333. "predialysis_evaluation": predialysisEvaluation,
  334. "doctor_advices": doctorAdvices,
  335. "double_check": doubleCheck,
  336. "assessment_after_dislysis": assessmentAfterDislysis,
  337. "treatment_summary": treatmentSummary,
  338. "monitor_records": monitorRecords,
  339. "dialysis_order": dialysisOrder,
  340. "operators": operators,
  341. "last_predialysis_evaluation": lastPredialysisEvaluation,
  342. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  343. "last_monitor_record": lastMonitorRecord,
  344. "special_premission": headNurses,
  345. "config": gobalConfig,
  346. "types": goodTypes,
  347. "goodInfos": goodInfos,
  348. "dry_weight": lastDryWeightDislysis,
  349. "system_prescription": systemDialysisPrescribe,
  350. }
  351. this.ServeSuccessJSON(returnData)
  352. }
  353. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  354. adminInfo := c.GetMobileAdminUserInfo()
  355. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  356. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  357. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  358. returnData := map[string]interface{}{
  359. "admin_users": adminUsers,
  360. "devices": devices,
  361. "device_numbers": device_numbers,
  362. }
  363. c.ServeSuccessJSON(returnData)
  364. }
  365. func (c *DialysisAPIController) PostAtreatmentInfo() {
  366. id, _ := c.GetInt64("patient", 0)
  367. recordDateStr := c.GetString("record_date")
  368. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  369. summaryContent := c.GetString("summaryContent")
  370. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  371. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  372. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  373. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  374. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  375. adminUserInfo := c.GetMobileAdminUserInfo()
  376. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  377. checkStaffId = adminUserInfo.AdminUser.Id
  378. deboardNurseId = adminUserInfo.AdminUser.Id
  379. treatDoctor = adminUserInfo.AdminUser.Id
  380. if id <= 0 {
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  385. if patient.ID == 0 {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  387. return
  388. }
  389. if len(recordDateStr) == 0 {
  390. recordDateStr = time.Now().Format("2006-01-02")
  391. }
  392. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  393. if parseDateErr != nil {
  394. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  396. return
  397. }
  398. //now := time.Now()
  399. //year, month, day := now.Date()
  400. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  401. //todayTimeStamp := today_time.Unix()
  402. summary := models.TreatmentSummary{
  403. UserOrgId: adminUserInfo.Org.Id,
  404. PatientId: id,
  405. AssessmentDate: recordDate.Unix(),
  406. Mission: propagandaAndEducationContent,
  407. DialysisSummary: summaryContent,
  408. SjNurse: changeMedicalNurseId,
  409. ZlNurse: treatNurseId,
  410. HdNurse: checkStaffId,
  411. XjNurse: deboardNurseId,
  412. ZlDoctor: treatDoctor,
  413. CreatedTime: time.Now().Unix(),
  414. Status: 1,
  415. }
  416. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  417. if treatmentSummary.ID == 0 { //新增
  418. summary.Creater = adminUserInfo.AdminUser.Id
  419. service.AddSigleSummaryRecord(&summary)
  420. c.ServeSuccessJSON(map[string]interface{}{
  421. "summary": summary,
  422. })
  423. } else { //修改
  424. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  425. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  426. // if getPermissionErr != nil {
  427. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  428. // return
  429. // } else if headNursePermission == nil {
  430. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  431. // return
  432. // }
  433. //}
  434. summary.Creater = treatmentSummary.Creater
  435. summary.CreatedTime = treatmentSummary.CreatedTime
  436. summary.Modifier = adminUserInfo.AdminUser.Id
  437. summary.ID = treatmentSummary.ID
  438. service.UpdateSummeRecord(&summary)
  439. c.ServeSuccessJSON(map[string]interface{}{
  440. "summary": summary,
  441. })
  442. }
  443. }
  444. func (c *DialysisAPIController) PostDoubleCheck() {
  445. id, _ := c.GetInt64("patient", 0)
  446. recordDateStr := c.GetString("record_date")
  447. checkTimeStr := c.GetString("check_time")
  448. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  449. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  450. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  451. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  452. dialysis_item_desc := c.GetString("dialysis_item_desc")
  453. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  454. vascular_access_desc := c.GetString("vascular_access_desc")
  455. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  456. collator, _ := c.GetInt64("collator", 0)
  457. if id <= 0 {
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. adminUserInfo := c.GetMobileAdminUserInfo()
  462. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  463. if patient.ID == 0 {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  465. return
  466. }
  467. if len(recordDateStr) == 0 {
  468. recordDateStr = time.Now().Format("2006-01-02")
  469. }
  470. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  471. if parseDateErr != nil {
  472. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  474. return
  475. }
  476. if len(checkTimeStr) == 0 {
  477. checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
  478. }
  479. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  480. //now := time.Now()
  481. //year, month, day := now.Date()
  482. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  483. //todayTimeStamp := today_time.Unix()
  484. doubleCheck := models.DoubleCheck{
  485. UserOrgId: adminUserInfo.Org.Id,
  486. PatientId: id,
  487. DialysisItemCheck: dialysis_item_check,
  488. DialysisParameterCheck: dialysis_parameter_check,
  489. VascularAccessVerification: vascular_access_verification,
  490. PipelineConnectionCheck: pipeline_connection_check,
  491. DialysisItemDesc: dialysis_item_desc,
  492. DialysisParameterDesc: dialysis_parameter_desc,
  493. VascularAccessDesc: vascular_access_desc,
  494. PipelineConnectionDesc: pipeline_connection_desc,
  495. Collator: collator,
  496. Status: 1,
  497. CreatedTime: time.Now().Unix(),
  498. UpdatedTime: time.Now().Unix(),
  499. CheckDate: recordDate.Unix(),
  500. }
  501. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  502. if check.ID == 0 { //新增
  503. doubleCheck.FirstCheckTime = checkDate.Unix()
  504. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  505. err := service.AddSigleDoubleCheck(&doubleCheck)
  506. if err == nil {
  507. c.ServeSuccessJSON(map[string]interface{}{
  508. "doubleCheck": &doubleCheck,
  509. })
  510. }
  511. } else { //修改
  512. if check.Modifier != 0 {
  513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  514. } else {
  515. if adminUserInfo.AdminUser.Id == check.Creater {
  516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  517. return
  518. }
  519. doubleCheck.FirstCheckTime = check.FirstCheckTime
  520. doubleCheck.CheckTime = checkDate.Unix()
  521. doubleCheck.Creater = check.Creater
  522. doubleCheck.CreatedTime = check.CreatedTime
  523. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  524. doubleCheck.ID = check.ID
  525. err := service.UpdateDoubleCheck(&doubleCheck)
  526. if err == nil {
  527. c.ServeSuccessJSON(map[string]interface{}{
  528. "doubleCheck": &doubleCheck,
  529. })
  530. }
  531. }
  532. }
  533. }
  534. func (c *DialysisAPIController) PostAcceptsAssessment() {
  535. id, _ := c.GetInt64("patient", 0)
  536. recordDateStr := c.GetString("record_date")
  537. way, _ := c.GetInt64("way", 0)
  538. consciousness, _ := c.GetInt64("consciousness", 0)
  539. appetite, _ := c.GetInt64("appetite", 0)
  540. condition, _ := c.GetInt64("condition", 0)
  541. posture, _ := c.GetInt64("posture")
  542. sick_condition, _ := c.GetInt64("sick_condition", 0)
  543. danger_level, _ := c.GetInt64("danger_level", 0)
  544. intake, _ := c.GetInt64("intake", 0)
  545. nutrition, _ := c.GetInt64("nutrition", 0)
  546. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  547. psychological_assessment_other := c.GetString("psychological_assessment_other")
  548. score := c.GetString("score")
  549. sick_condition_other := c.GetString("sick_condition_other")
  550. precaution, _ := c.GetInt64("precaution", 0)
  551. precaution_other := c.GetString("precaution_other")
  552. psychological_other := c.GetString("psychological_other")
  553. admission_number := c.GetString("admission_number")
  554. if id <= 0 {
  555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  556. return
  557. }
  558. adminUserInfo := c.GetMobileAdminUserInfo()
  559. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  560. if patient.ID == 0 {
  561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  562. return
  563. }
  564. //now := time.Now()
  565. //year, month, day := now.Date()
  566. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  567. //todayTimeStamp := today_time.Unix()
  568. if len(recordDateStr) == 0 {
  569. recordDateStr = time.Now().Format("2006-01-02")
  570. }
  571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  572. if parseDateErr != nil {
  573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  578. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  579. UserOrgId: adminUserInfo.Org.Id,
  580. PatientId: id,
  581. RecordDate: recordDate.Unix(),
  582. Way: way,
  583. Consciousness: consciousness,
  584. Appetite: appetite,
  585. Condition: condition,
  586. SickCondition: sick_condition,
  587. DangerLevel: danger_level,
  588. Intake: intake,
  589. Nutrition: nutrition,
  590. PsychologicalAssessment: psychological_assessment,
  591. PsychologicalAssessmentOther: psychological_assessment_other,
  592. SickConditionOther: sick_condition_other,
  593. Posture: posture,
  594. CreatedTime: time.Now().Unix(),
  595. UpdateTime: time.Now().Unix(),
  596. Status: 1,
  597. Score: score,
  598. Precaution: precaution,
  599. PrecautionOther: precaution_other,
  600. PsychologicalOther: psychological_other,
  601. AdmissionNumber: admission_number,
  602. }
  603. if receiveTreatment.ID == 0 { //新增
  604. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  605. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  606. if err == nil {
  607. c.ServeSuccessJSON(map[string]interface{}{
  608. "receiveTreatmentAsses": receiveTreatmentAsses,
  609. })
  610. }
  611. } else { //修改
  612. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  613. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  614. // if getPermissionErr != nil {
  615. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  616. // return
  617. // } else if headNursePermission == nil {
  618. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  619. // return
  620. // }
  621. //}
  622. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  623. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  624. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  625. receiveTreatmentAsses.ID = receiveTreatment.ID
  626. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  627. if err == nil {
  628. c.ServeSuccessJSON(map[string]interface{}{
  629. "receiveTreatmentAsses": receiveTreatmentAsses,
  630. })
  631. }
  632. }
  633. }
  634. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  635. id, _ := c.GetInt64("patient", 0)
  636. recordDateStr := c.GetString("record_date")
  637. weightAfter, _ := c.GetFloat("weight_after", 0)
  638. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  639. weightReduce, _ := c.GetFloat("weight_loss", 0)
  640. temperature, _ := c.GetFloat("temperature", 0)
  641. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  642. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  643. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  644. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  645. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  646. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  647. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  648. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  649. cruor := c.GetString("cruor")
  650. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  651. internalFistula := c.GetString("internal_fistula")
  652. catheter := c.GetString("catheter")
  653. complications := c.GetString("complication")
  654. remark := c.GetString("remark")
  655. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  656. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  657. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  658. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  659. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  660. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  661. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  662. patientGose, _ := c.GetInt64("patient_gose", 0)
  663. inpatientDepartment := c.GetString("inpatient_department")
  664. observationContent := c.GetString("observation_content")
  665. observationContentOther := c.GetString("observation_content_other")
  666. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  667. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  668. in_advance_reason := c.GetString("in_advance_reason")
  669. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  670. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  671. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  672. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  673. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  674. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  675. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  676. dialyzer, _ := c.GetInt64("dialyzer", 0)
  677. in_advance_reason_other := c.GetString("in_advance_reason_other")
  678. is_eat, _ := c.GetInt64("is_eat", 0)
  679. if id <= 0 {
  680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  681. return
  682. }
  683. adminUserInfo := c.GetMobileAdminUserInfo()
  684. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  685. if patient.ID == 0 {
  686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  687. return
  688. }
  689. if len(recordDateStr) == 0 {
  690. recordDateStr = time.Now().Format("2006-01-02")
  691. }
  692. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  693. if parseDateErr != nil {
  694. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. //now := time.Now()
  699. //year, month, day := now.Date()
  700. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  701. //todayTimeStamp := today_time.Unix()
  702. _, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  703. if evaluation.ID > 0 {
  704. if evaluation.WeightBefore > 0 && weightAfter > 0 {
  705. if (evaluation.WeightBefore-evaluation.AdditionalWeight)-(weightAfter-additionalWeight) > 0 {
  706. weightReduce = (evaluation.WeightBefore - evaluation.AdditionalWeight) - (weightAfter - additionalWeight)
  707. } else {
  708. weightReduce = 0
  709. }
  710. }
  711. }
  712. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  713. UserOrgId: adminUserInfo.Org.Id,
  714. PatientId: id,
  715. AssessmentDate: recordDate.Unix(),
  716. Temperature: temperature,
  717. PulseFrequency: pulse_frequency,
  718. BreathingRate: breathing_rate,
  719. SystolicBloodPressure: systolic_blood_pressure,
  720. DiastolicBloodPressure: diastolic_blood_pressure,
  721. ActualUltrafiltration: actual_ultrafiltration,
  722. ActualDisplacement: actual_displacement,
  723. ActualTreatmentHour: actualtreatHour,
  724. ActualTreatmentMinute: actualtreatmin,
  725. WeightAfter: weightAfter,
  726. AdditionalWeight: additionalWeight,
  727. WeightLoss: weightReduce,
  728. Cruor: cruor,
  729. SymptomAfterDialysis: symptomsAfterDialysi,
  730. InternalFistula: internalFistula,
  731. Catheter: catheter,
  732. Complication: complications,
  733. DialysisIntakes: dialysateVolume,
  734. CreatedTime: time.Now().Unix(),
  735. Status: 1,
  736. Remark: remark,
  737. BloodAccessPartId: blood_access_part_id,
  738. BloodAccessPartOperaId: blood_access_part_opera_id,
  739. DialysisIntakesUnit: dialysis_intakes_unit,
  740. PuncturePointOozingBlood: puncturePointOozingBlood,
  741. PuncturePointHaematoma: puncturePointHaematoma,
  742. InternalFistulaTremorAc: internalFistulaTremorAc,
  743. PatientGose: patientGose,
  744. InpatientDepartment: inpatientDepartment,
  745. ObservationContent: observationContent,
  746. ObservationContentOther: observationContentOther,
  747. DialysisProcess: dialysis_process,
  748. InAdvanceMinute: in_advance_minute,
  749. InAdvanceReason: in_advance_reason,
  750. HemostasisMinute: hemostasis_minute,
  751. HemostasisOpera: hemostasis_opera,
  752. TremorNoise: tremor_noise,
  753. DisequilibriumSyndrome: disequilibrium_syndrome,
  754. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  755. ArterialTube: arterial_tube,
  756. IntravenousTube: intravenous_tube,
  757. Dialyzer: dialyzer,
  758. InAdvanceReasonOther: in_advance_reason_other,
  759. IsEat: is_eat,
  760. }
  761. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  762. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  763. if assessmentAfter.ID == 0 { //新增
  764. if appRole.UserType == 2 || appRole.UserType == 1 {
  765. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  766. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  767. } else {
  768. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  769. }
  770. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  771. if err == nil {
  772. c.ServeSuccessJSON(map[string]interface{}{
  773. "assessmentAfterDislysis": assessmentAfterDislysis,
  774. })
  775. }
  776. } else { //修改
  777. if appRole.UserType == 2 || appRole.UserType == 1 {
  778. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  779. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  780. } else {
  781. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  782. if assessmentAfterDislysis.Creater == 0 {
  783. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  784. }
  785. }
  786. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  787. assessmentAfterDislysis.ID = assessmentAfter.ID
  788. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  789. if err == nil {
  790. c.ServeSuccessJSON(map[string]interface{}{
  791. "assessmentAfterDislysis": assessmentAfterDislysis,
  792. })
  793. }
  794. }
  795. }
  796. func (c *DialysisAPIController) PostDialysisPrescription() {
  797. id, _ := c.GetInt64("patient", 0)
  798. recordDateStr := c.GetString("record_date")
  799. if id <= 0 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  801. return
  802. }
  803. adminUserInfo := c.GetMobileAdminUserInfo()
  804. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  805. if patient.ID == 0 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  807. return
  808. }
  809. if len(recordDateStr) == 0 {
  810. recordDateStr = time.Now().Format("2006-01-02")
  811. }
  812. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  813. if parseDateErr != nil {
  814. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  816. return
  817. }
  818. mode_id, _ := c.GetInt64("mode_id", 0)
  819. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  820. dialyzer, _ := c.GetInt64("dialyzer", 0)
  821. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  822. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  823. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  824. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  825. replacement_total, _ := c.GetFloat("replacement_total", 0)
  826. replacement_way, _ := c.GetInt64("replacement_way", 0)
  827. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  828. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  829. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  830. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  831. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  832. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  833. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  834. kalium, _ := c.GetFloat("kalium", 0)
  835. sodium, _ := c.GetFloat("sodium", 0)
  836. calcium, _ := c.GetFloat("calcium", 0)
  837. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  838. glucose, _ := c.GetFloat("glucose", 0)
  839. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  840. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  841. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  842. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  843. conductivity, _ := c.GetFloat("conductivity", 0)
  844. remark := c.GetString("remark")
  845. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  846. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  847. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  848. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  849. body_fluid, _ := c.GetInt64("body_fluid", 0)
  850. special_medicine, _ := c.GetInt64("special_medicine", 0)
  851. special_medicine_other := c.GetString("special_medicine_other")
  852. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  853. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  854. blood_access, _ := c.GetInt64("blood_access", 0)
  855. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  856. body_fluid_other := c.GetString("body_fluid_other")
  857. niprocart, _ := c.GetInt64("niprocart", 0)
  858. jms, _ := c.GetInt64("jms", 0)
  859. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  860. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  861. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  862. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  863. filtryzer, _ := c.GetInt64("filtryzer", 0)
  864. target_ktv, _ := c.GetFloat("target_ktv", 0)
  865. dialyzers, _ := c.GetInt64("dialyzers", 0)
  866. injector, _ := c.GetInt64("injector", 0)
  867. bloodlines, _ := c.GetInt64("bloodlines", 0)
  868. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  869. safe_package, _ := c.GetInt64("package", 0)
  870. a_liquid, _ := c.GetInt64("a_liquid", 0)
  871. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  872. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  873. //
  874. //if template.TemplateId == 2 || template.TemplateId == 6 {
  875. // if appRole.UserType == 3 {
  876. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  877. // if getPermissionErr != nil {
  878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  879. // return
  880. // } else if headNursePermission == nil {
  881. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  882. // return
  883. // }
  884. // }
  885. //}
  886. //TODO 需要根据角色去判断
  887. prescription := models.DialysisPrescription{
  888. UserOrgId: adminUserInfo.Org.Id,
  889. PatientId: id,
  890. RecordDate: recordDate.Unix(),
  891. ModeId: mode_id,
  892. DialysisDuration: dialysis_duration,
  893. Dialyzer: dialyzer,
  894. PerfusionApparatus: perfusion_apparatus,
  895. BloodFlowVolume: blood_flow_volume,
  896. DewaterAmount: dewater_amount,
  897. DisplaceLiqui: displace_liqui,
  898. ReplacementWay: replacement_way,
  899. Anticoagulant: anticoagulant,
  900. AnticoagulantShouji: anticoagulant_shouji,
  901. AnticoagulantWeichi: anticoagulant_weichi,
  902. AnticoagulantZongliang: anticoagulant_zongliang,
  903. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  904. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  905. Kalium: kalium,
  906. Sodium: sodium,
  907. Calcium: calcium,
  908. Bicarbonate: bicarbonate,
  909. Glucose: glucose,
  910. // DryWeight: dry_weight,
  911. DialysateFlow: dialysate_flow,
  912. DialysateTemperature: dialysate_temperature,
  913. PrescriptionDoctor: prescription_doctor,
  914. ReplacementTotal: replacement_total,
  915. Conductivity: conductivity,
  916. Remark: remark,
  917. Status: 1,
  918. CreatedTime: time.Now().Unix(),
  919. UpdatedTime: time.Now().Unix(),
  920. DialysisDurationMinute: dialysisDurationMinute,
  921. DialysisDurationHour: dialysisDurationHour,
  922. TargetUltrafiltration: targetUltrafiltration,
  923. DialysateFormulation: dialysateFormulation,
  924. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  925. BodyFluid: body_fluid,
  926. SpecialMedicine: special_medicine,
  927. SpecialMedicineOther: special_medicine_other,
  928. DisplaceLiquiPart: displace_liqui_part,
  929. DisplaceLiquiValue: displace_liqui_value,
  930. BloodAccess: blood_access,
  931. Ultrafiltration: ultrafiltration,
  932. BodyFluidOther: body_fluid_other,
  933. Niprocart: niprocart,
  934. Jms: jms,
  935. FistulaNeedleSet: fistula_needle_set,
  936. FistulaNeedleSet16: fistula_needle_set_16,
  937. Hemoperfusion: hemoperfusion,
  938. DialyserSterilised: dialyser_sterilised,
  939. Filtryzer: filtryzer,
  940. Dialyzers: dialyzers,
  941. Injector: injector,
  942. Bloodlines: bloodlines,
  943. TubingHemodialysis: tubing_hemodialysis,
  944. Package: safe_package,
  945. ALiquid: a_liquid,
  946. TargetKtv: target_ktv,
  947. }
  948. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  949. if dialysisPrescription.ID == 0 { //新增
  950. //if mode_id > 0 {
  951. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  952. //}
  953. if appRole.UserType == 2 || appRole.UserType == 1 {
  954. prescription_doctor = adminUserInfo.AdminUser.Id
  955. } else {
  956. prescription_doctor = 0
  957. }
  958. prescription.Creater = adminUserInfo.AdminUser.Id
  959. err := service.AddSigleRecord(&prescription)
  960. if err == nil {
  961. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  962. if updateErr != nil {
  963. utils.ErrorLog("%v", updateErr)
  964. }
  965. c.ServeSuccessJSON(map[string]interface{}{
  966. "prescription": prescription,
  967. })
  968. }
  969. } else { //修改
  970. //if mode_id > 0 {
  971. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  972. //}
  973. //if template.TemplateId == 1 {
  974. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  975. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  976. // if getPermissionErr != nil {
  977. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  978. // return
  979. // } else if headNursePermission == nil {
  980. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  981. // return
  982. // }
  983. // }
  984. //}
  985. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  986. if record.IsOpen == 1 {
  987. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  988. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  989. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  990. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  991. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  992. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  993. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  994. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  995. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  996. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  997. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  998. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  999. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1000. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1001. if err == nil {
  1002. if order.ID > 0 {
  1003. if dialysisPrescription.Niprocart != niprocart {
  1004. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1005. //1.用上机透析日期查出当天的订单
  1006. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1007. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1008. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1009. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1010. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1011. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1012. warehouseOutInfo := &models.WarehouseOutInfo{
  1013. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1014. WarehouseOutId: out.ID,
  1015. Count: 1,
  1016. Status: 1,
  1017. Ctime: time.Now().Unix(),
  1018. Remark: "",
  1019. OrgId: adminUserInfo.Org.Id,
  1020. Type: 1,
  1021. Manufacturer: 0,
  1022. Dealer: 0,
  1023. IsSys: 1,
  1024. SysRecordTime: order.StartTime,
  1025. }
  1026. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  1027. warehouseOutInfo.Price = stockInInfo.Price
  1028. warehouseOutInfo.GoodId = niprocart
  1029. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1030. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1031. if err == nil {
  1032. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1033. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1034. if err == gorm.ErrRecordNotFound {
  1035. details := &models.AutomaticReduceDetail{
  1036. WarehouseOutId: warehouseOutInfo.ID,
  1037. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1038. PatientId: id,
  1039. Ctime: time.Now().Unix(),
  1040. Mtime: time.Now().Unix(),
  1041. Status: 1,
  1042. RecordTime: order.StartTime,
  1043. OrgId: adminUserInfo.Org.Id,
  1044. GoodId: niprocart,
  1045. GoodTypeId: niprocart_good_type_id,
  1046. }
  1047. service.AddSigleAutoReduceRecordInfo(details)
  1048. } else if err == nil {
  1049. if user.ID > 0 {
  1050. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  1051. }
  1052. }
  1053. }
  1054. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1055. if newOut.ID > 0 {
  1056. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1057. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1058. if err == gorm.ErrRecordNotFound {
  1059. details := &models.AutomaticReduceDetail{
  1060. WarehouseOutId: newOut.ID,
  1061. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1062. PatientId: id,
  1063. Ctime: time.Now().Unix(),
  1064. Mtime: time.Now().Unix(),
  1065. Status: 1,
  1066. RecordTime: order.StartTime,
  1067. OrgId: adminUserInfo.Org.Id,
  1068. GoodId: niprocart,
  1069. GoodTypeId: niprocart_good_type_id,
  1070. }
  1071. service.AddSigleAutoReduceRecordInfo(details)
  1072. } else if err == nil {
  1073. if user.ID > 0 {
  1074. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. if dialysisPrescription.Jms != jms {
  1081. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1082. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1083. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1084. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1085. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1086. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1087. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1088. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1089. warehouseOutInfo := &models.WarehouseOutInfo{
  1090. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1091. WarehouseOutId: out.ID,
  1092. Count: 1,
  1093. Status: 1,
  1094. Ctime: time.Now().Unix(),
  1095. Remark: "",
  1096. OrgId: adminUserInfo.Org.Id,
  1097. Type: 1,
  1098. Manufacturer: 0,
  1099. Dealer: 0,
  1100. IsSys: 1,
  1101. SysRecordTime: order.StartTime,
  1102. }
  1103. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  1104. warehouseOutInfo.Price = stockInInfo.Price
  1105. warehouseOutInfo.GoodId = jms
  1106. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1107. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1108. if err == nil {
  1109. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1110. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1111. if err == gorm.ErrRecordNotFound {
  1112. details := &models.AutomaticReduceDetail{
  1113. WarehouseOutId: warehouseOutInfo.ID,
  1114. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1115. PatientId: id,
  1116. Ctime: time.Now().Unix(),
  1117. Mtime: time.Now().Unix(),
  1118. Status: 1,
  1119. RecordTime: order.StartTime,
  1120. OrgId: adminUserInfo.Org.Id,
  1121. GoodId: jms,
  1122. GoodTypeId: jms_good_type_id,
  1123. }
  1124. service.AddSigleAutoReduceRecordInfo(details)
  1125. } else if err == nil {
  1126. if user.ID > 0 {
  1127. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1128. }
  1129. }
  1130. }
  1131. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1132. if newOut.ID > 0 {
  1133. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1134. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1135. if err == gorm.ErrRecordNotFound {
  1136. details := &models.AutomaticReduceDetail{
  1137. WarehouseOutId: newOut.ID,
  1138. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1139. PatientId: id,
  1140. Ctime: time.Now().Unix(),
  1141. Mtime: time.Now().Unix(),
  1142. Status: 1,
  1143. RecordTime: order.StartTime,
  1144. OrgId: adminUserInfo.Org.Id,
  1145. GoodId: jms,
  1146. GoodTypeId: jms_good_type_id,
  1147. }
  1148. service.AddSigleAutoReduceRecordInfo(details)
  1149. } else if err == nil {
  1150. if user.ID > 0 {
  1151. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1158. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1159. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1160. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1161. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1162. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1163. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1164. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1165. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1166. warehouseOutInfo := &models.WarehouseOutInfo{
  1167. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1168. WarehouseOutId: out.ID,
  1169. Count: 1,
  1170. Status: 1,
  1171. Ctime: time.Now().Unix(),
  1172. Remark: "",
  1173. OrgId: adminUserInfo.Org.Id,
  1174. Type: 1,
  1175. Manufacturer: 0,
  1176. Dealer: 0,
  1177. IsSys: 1,
  1178. SysRecordTime: order.StartTime,
  1179. }
  1180. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  1181. warehouseOutInfo.Price = stockInInfo.Price
  1182. warehouseOutInfo.GoodId = fistula_needle_set
  1183. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1184. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1185. if err == nil {
  1186. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1187. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1188. if err == gorm.ErrRecordNotFound {
  1189. details := &models.AutomaticReduceDetail{
  1190. WarehouseOutId: warehouseOutInfo.ID,
  1191. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1192. PatientId: id,
  1193. Ctime: time.Now().Unix(),
  1194. Mtime: time.Now().Unix(),
  1195. Status: 1,
  1196. RecordTime: order.StartTime,
  1197. OrgId: adminUserInfo.Org.Id,
  1198. GoodId: fistula_needle_set,
  1199. GoodTypeId: fistula_needle_set_good_type_id,
  1200. }
  1201. service.AddSigleAutoReduceRecordInfo(details)
  1202. } else if err == nil {
  1203. if user.ID > 0 {
  1204. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1205. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1206. }
  1207. }
  1208. }
  1209. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1210. if newOut.ID > 0 {
  1211. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1212. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1213. if err == gorm.ErrRecordNotFound {
  1214. details := &models.AutomaticReduceDetail{
  1215. WarehouseOutId: newOut.ID,
  1216. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1217. PatientId: id,
  1218. Ctime: time.Now().Unix(),
  1219. Mtime: time.Now().Unix(),
  1220. Status: 1,
  1221. RecordTime: order.StartTime,
  1222. OrgId: adminUserInfo.Org.Id,
  1223. GoodId: fistula_needle_set,
  1224. GoodTypeId: fistula_needle_set_good_type_id,
  1225. }
  1226. service.AddSigleAutoReduceRecordInfo(details)
  1227. } else if err == nil {
  1228. if user.ID > 0 {
  1229. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1230. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1237. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1238. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1239. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1240. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1241. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1242. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1243. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1244. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1245. warehouseOutInfo := &models.WarehouseOutInfo{
  1246. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1247. WarehouseOutId: out.ID,
  1248. Count: 1,
  1249. Status: 1,
  1250. Ctime: time.Now().Unix(),
  1251. Remark: "",
  1252. OrgId: adminUserInfo.Org.Id,
  1253. Type: 1,
  1254. Manufacturer: 0,
  1255. Dealer: 0,
  1256. IsSys: 1,
  1257. SysRecordTime: order.StartTime,
  1258. }
  1259. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  1260. warehouseOutInfo.Price = stockInInfo.Price
  1261. warehouseOutInfo.GoodId = fistula_needle_set_16
  1262. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1263. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1264. if err == nil {
  1265. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1266. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1267. if err == gorm.ErrRecordNotFound {
  1268. details := &models.AutomaticReduceDetail{
  1269. WarehouseOutId: warehouseOutInfo.ID,
  1270. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1271. PatientId: id,
  1272. Ctime: time.Now().Unix(),
  1273. Mtime: time.Now().Unix(),
  1274. Status: 1,
  1275. RecordTime: order.StartTime,
  1276. OrgId: adminUserInfo.Org.Id,
  1277. GoodId: fistula_needle_set_16,
  1278. GoodTypeId: fistula_needle_set_16_good_type_id,
  1279. }
  1280. service.AddSigleAutoReduceRecordInfo(details)
  1281. } else if err == nil {
  1282. if user.ID > 0 {
  1283. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1284. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1285. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  1286. }
  1287. }
  1288. }
  1289. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1290. if newOut.ID > 0 {
  1291. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1292. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1293. if err == gorm.ErrRecordNotFound {
  1294. details := &models.AutomaticReduceDetail{
  1295. WarehouseOutId: newOut.ID,
  1296. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1297. PatientId: id,
  1298. Ctime: time.Now().Unix(),
  1299. Mtime: time.Now().Unix(),
  1300. Status: 1,
  1301. RecordTime: order.StartTime,
  1302. OrgId: adminUserInfo.Org.Id,
  1303. GoodId: fistula_needle_set_good_type_id,
  1304. GoodTypeId: fistula_needle_set_16_good_type_id,
  1305. }
  1306. service.AddSigleAutoReduceRecordInfo(details)
  1307. } else if err == nil {
  1308. if user.ID > 0 {
  1309. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1316. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1317. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1318. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1319. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1320. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1321. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1322. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1323. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1324. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1325. warehouseOutInfo := &models.WarehouseOutInfo{
  1326. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1327. WarehouseOutId: out.ID,
  1328. Count: 1,
  1329. Status: 1,
  1330. Ctime: time.Now().Unix(),
  1331. Remark: "",
  1332. OrgId: adminUserInfo.Org.Id,
  1333. Type: 1,
  1334. Manufacturer: 0,
  1335. Dealer: 0,
  1336. IsSys: 1,
  1337. SysRecordTime: order.StartTime,
  1338. }
  1339. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  1340. warehouseOutInfo.Price = stockInInfo.Price
  1341. warehouseOutInfo.GoodId = hemoperfusion
  1342. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1343. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1344. if err == nil {
  1345. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1346. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1347. if err == gorm.ErrRecordNotFound {
  1348. details := &models.AutomaticReduceDetail{
  1349. WarehouseOutId: warehouseOutInfo.ID,
  1350. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1351. PatientId: id,
  1352. Ctime: time.Now().Unix(),
  1353. Mtime: time.Now().Unix(),
  1354. Status: 1,
  1355. RecordTime: order.StartTime,
  1356. OrgId: adminUserInfo.Org.Id,
  1357. GoodId: hemoperfusion,
  1358. GoodTypeId: hemoperfusion_good_type_id,
  1359. }
  1360. service.AddSigleAutoReduceRecordInfo(details)
  1361. } else if err == nil {
  1362. if user.ID > 0 {
  1363. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1364. }
  1365. }
  1366. }
  1367. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1368. if newOut.ID > 0 {
  1369. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1370. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1371. if err == gorm.ErrRecordNotFound {
  1372. details := &models.AutomaticReduceDetail{
  1373. WarehouseOutId: newOut.ID,
  1374. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1375. PatientId: id,
  1376. Ctime: time.Now().Unix(),
  1377. Mtime: time.Now().Unix(),
  1378. Status: 1,
  1379. RecordTime: order.StartTime,
  1380. OrgId: adminUserInfo.Org.Id,
  1381. GoodId: hemoperfusion,
  1382. GoodTypeId: hemoperfusion_good_type_id,
  1383. }
  1384. service.AddSigleAutoReduceRecordInfo(details)
  1385. } else if err == nil {
  1386. if user.ID > 0 {
  1387. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1394. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1395. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1396. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1397. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1398. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1399. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1400. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1401. if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
  1402. warehouseOutInfo := &models.WarehouseOutInfo{
  1403. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1404. WarehouseOutId: out.WarehouseOutId,
  1405. Count: 1,
  1406. Status: 1,
  1407. Ctime: time.Now().Unix(),
  1408. Remark: "",
  1409. OrgId: adminUserInfo.Org.Id,
  1410. Type: 1,
  1411. Manufacturer: 0,
  1412. Dealer: 0,
  1413. IsSys: 1,
  1414. SysRecordTime: order.StartTime,
  1415. }
  1416. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  1417. warehouseOutInfo.Price = stockInInfo.Price
  1418. warehouseOutInfo.GoodId = dialyser_sterilised
  1419. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1420. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1421. if err == nil {
  1422. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1423. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1424. if err == gorm.ErrRecordNotFound {
  1425. details := &models.AutomaticReduceDetail{
  1426. WarehouseOutId: warehouseOutInfo.ID,
  1427. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1428. PatientId: id,
  1429. Ctime: time.Now().Unix(),
  1430. Mtime: time.Now().Unix(),
  1431. Status: 1,
  1432. RecordTime: order.StartTime,
  1433. OrgId: adminUserInfo.Org.Id,
  1434. GoodId: dialyser_sterilised,
  1435. GoodTypeId: dialyser_sterilised_good_type_id,
  1436. }
  1437. service.AddSigleAutoReduceRecordInfo(details)
  1438. } else if err == nil {
  1439. if user.ID > 0 {
  1440. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1441. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  1442. }
  1443. }
  1444. }
  1445. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1446. if newOut.ID > 0 {
  1447. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1448. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1449. if err == gorm.ErrRecordNotFound {
  1450. details := &models.AutomaticReduceDetail{
  1451. WarehouseOutId: newOut.ID,
  1452. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1453. PatientId: id,
  1454. Ctime: time.Now().Unix(),
  1455. Mtime: time.Now().Unix(),
  1456. Status: 1,
  1457. RecordTime: order.StartTime,
  1458. OrgId: adminUserInfo.Org.Id,
  1459. GoodId: dialyser_sterilised,
  1460. GoodTypeId: dialyser_sterilised_good_type_id,
  1461. }
  1462. service.AddSigleAutoReduceRecordInfo(details)
  1463. } else if err == nil {
  1464. if user.ID > 0 {
  1465. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. if dialysisPrescription.Filtryzer != filtryzer {
  1472. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1473. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1474. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1475. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1476. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1477. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1478. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1479. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1480. warehouseOutInfo := &models.WarehouseOutInfo{
  1481. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1482. WarehouseOutId: out.ID,
  1483. Count: 1,
  1484. Status: 1,
  1485. Ctime: time.Now().Unix(),
  1486. Remark: "",
  1487. OrgId: adminUserInfo.Org.Id,
  1488. Type: 1,
  1489. Manufacturer: 0,
  1490. Dealer: 0,
  1491. IsSys: 1,
  1492. SysRecordTime: order.StartTime,
  1493. }
  1494. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  1495. warehouseOutInfo.Price = stockInInfo.Price
  1496. warehouseOutInfo.GoodId = filtryzer
  1497. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1498. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1499. if err == nil {
  1500. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1501. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1502. if err == gorm.ErrRecordNotFound {
  1503. details := &models.AutomaticReduceDetail{
  1504. WarehouseOutId: warehouseOutInfo.ID,
  1505. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1506. PatientId: id,
  1507. Ctime: time.Now().Unix(),
  1508. Mtime: time.Now().Unix(),
  1509. Status: 1,
  1510. RecordTime: order.StartTime,
  1511. OrgId: adminUserInfo.Org.Id,
  1512. GoodId: filtryzer,
  1513. GoodTypeId: filtryzer_good_type_id,
  1514. }
  1515. service.AddSigleAutoReduceRecordInfo(details)
  1516. } else if err == nil {
  1517. if user.ID > 0 {
  1518. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  1519. }
  1520. }
  1521. }
  1522. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1523. if newOut.ID > 0 {
  1524. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1525. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1526. if err == gorm.ErrRecordNotFound {
  1527. details := &models.AutomaticReduceDetail{
  1528. WarehouseOutId: newOut.ID,
  1529. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1530. PatientId: id,
  1531. Ctime: time.Now().Unix(),
  1532. Mtime: time.Now().Unix(),
  1533. Status: 1,
  1534. RecordTime: order.StartTime,
  1535. OrgId: adminUserInfo.Org.Id,
  1536. GoodId: filtryzer,
  1537. GoodTypeId: filtryzer_good_type_id,
  1538. }
  1539. service.AddSigleAutoReduceRecordInfo(details)
  1540. } else if err == nil {
  1541. if user.ID > 0 {
  1542. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  1543. }
  1544. }
  1545. }
  1546. }
  1547. }
  1548. if dialysisPrescription.Dialyzers != dialyzers {
  1549. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1550. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1551. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1552. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1553. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1554. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1555. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1556. warehouseOutInfo := &models.WarehouseOutInfo{
  1557. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1558. WarehouseOutId: out.ID,
  1559. Count: 1,
  1560. Status: 1,
  1561. Ctime: time.Now().Unix(),
  1562. Remark: "",
  1563. OrgId: adminUserInfo.Org.Id,
  1564. Type: 1,
  1565. Manufacturer: 0,
  1566. Dealer: 0,
  1567. IsSys: 1,
  1568. SysRecordTime: order.StartTime,
  1569. }
  1570. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  1571. warehouseOutInfo.Price = stockInInfo.Price
  1572. warehouseOutInfo.GoodId = dialyzers
  1573. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  1574. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1575. if err == nil {
  1576. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1577. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1578. if err == gorm.ErrRecordNotFound {
  1579. details := &models.AutomaticReduceDetail{
  1580. WarehouseOutId: warehouseOutInfo.ID,
  1581. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1582. PatientId: id,
  1583. Ctime: time.Now().Unix(),
  1584. Mtime: time.Now().Unix(),
  1585. Status: 1,
  1586. RecordTime: order.StartTime,
  1587. OrgId: adminUserInfo.Org.Id,
  1588. GoodId: dialyzers,
  1589. GoodTypeId: dialyzers_good_type_id,
  1590. }
  1591. service.AddSigleAutoReduceRecordInfo(details)
  1592. } else if err == nil {
  1593. if user.ID > 0 {
  1594. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  1595. }
  1596. }
  1597. }
  1598. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1599. if newOut.ID > 0 {
  1600. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1601. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1602. if err == gorm.ErrRecordNotFound {
  1603. details := &models.AutomaticReduceDetail{
  1604. WarehouseOutId: newOut.ID,
  1605. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1606. PatientId: id,
  1607. Ctime: time.Now().Unix(),
  1608. Mtime: time.Now().Unix(),
  1609. Status: 1,
  1610. RecordTime: order.StartTime,
  1611. OrgId: adminUserInfo.Org.Id,
  1612. GoodId: dialyzers,
  1613. GoodTypeId: dialyzers_good_type_id,
  1614. }
  1615. service.AddSigleAutoReduceRecordInfo(details)
  1616. } else if err == nil {
  1617. if user.ID > 0 {
  1618. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. if dialysisPrescription.Injector != injector {
  1625. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1626. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1627. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1628. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1629. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1630. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1631. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1632. warehouseOutInfo := &models.WarehouseOutInfo{
  1633. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1634. WarehouseOutId: out.ID,
  1635. Count: 1,
  1636. Status: 1,
  1637. Ctime: time.Now().Unix(),
  1638. Remark: "",
  1639. OrgId: adminUserInfo.Org.Id,
  1640. Type: 1,
  1641. Manufacturer: 0,
  1642. Dealer: 0,
  1643. IsSys: 1,
  1644. SysRecordTime: order.StartTime,
  1645. }
  1646. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  1647. warehouseOutInfo.Price = stockInInfo.Price
  1648. warehouseOutInfo.GoodId = injector
  1649. warehouseOutInfo.GoodTypeId = injector_good_type_id
  1650. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1651. if err == nil {
  1652. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1653. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1654. if err == gorm.ErrRecordNotFound {
  1655. details := &models.AutomaticReduceDetail{
  1656. WarehouseOutId: warehouseOutInfo.ID,
  1657. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1658. PatientId: id,
  1659. Ctime: time.Now().Unix(),
  1660. Mtime: time.Now().Unix(),
  1661. Status: 1,
  1662. RecordTime: order.StartTime,
  1663. OrgId: adminUserInfo.Org.Id,
  1664. GoodId: injector,
  1665. GoodTypeId: injector_good_type_id,
  1666. }
  1667. service.AddSigleAutoReduceRecordInfo(details)
  1668. } else if err == nil {
  1669. if user.ID > 0 {
  1670. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  1671. }
  1672. }
  1673. }
  1674. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1675. if newOut.ID > 0 {
  1676. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1677. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1678. if err == gorm.ErrRecordNotFound {
  1679. details := &models.AutomaticReduceDetail{
  1680. WarehouseOutId: newOut.ID,
  1681. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1682. PatientId: id,
  1683. Ctime: time.Now().Unix(),
  1684. Mtime: time.Now().Unix(),
  1685. Status: 1,
  1686. RecordTime: order.StartTime,
  1687. OrgId: adminUserInfo.Org.Id,
  1688. GoodId: injector,
  1689. GoodTypeId: injector_good_type_id,
  1690. }
  1691. service.AddSigleAutoReduceRecordInfo(details)
  1692. } else if err == nil {
  1693. if user.ID > 0 {
  1694. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }
  1700. if dialysisPrescription.Bloodlines != bloodlines {
  1701. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1702. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1703. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1704. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1705. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1706. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1707. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1708. warehouseOutInfo := &models.WarehouseOutInfo{
  1709. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1710. WarehouseOutId: out.ID,
  1711. Count: 1,
  1712. Status: 1,
  1713. Ctime: time.Now().Unix(),
  1714. Remark: "",
  1715. OrgId: adminUserInfo.Org.Id,
  1716. Type: 1,
  1717. Manufacturer: 0,
  1718. Dealer: 0,
  1719. IsSys: 1,
  1720. SysRecordTime: order.StartTime,
  1721. }
  1722. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  1723. warehouseOutInfo.Price = stockInInfo.Price
  1724. warehouseOutInfo.GoodId = bloodlines
  1725. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  1726. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1727. if err == nil {
  1728. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1729. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1730. if err == gorm.ErrRecordNotFound {
  1731. details := &models.AutomaticReduceDetail{
  1732. WarehouseOutId: warehouseOutInfo.ID,
  1733. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1734. PatientId: id,
  1735. Ctime: time.Now().Unix(),
  1736. Mtime: time.Now().Unix(),
  1737. Status: 1,
  1738. RecordTime: order.StartTime,
  1739. OrgId: adminUserInfo.Org.Id,
  1740. GoodId: bloodlines,
  1741. GoodTypeId: bloodlines_good_type_id,
  1742. }
  1743. service.AddSigleAutoReduceRecordInfo(details)
  1744. } else if err == nil {
  1745. if user.ID > 0 {
  1746. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  1747. }
  1748. }
  1749. }
  1750. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1751. if newOut.ID > 0 {
  1752. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1753. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1754. if err == gorm.ErrRecordNotFound {
  1755. details := &models.AutomaticReduceDetail{
  1756. WarehouseOutId: newOut.ID,
  1757. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1758. PatientId: id,
  1759. Ctime: time.Now().Unix(),
  1760. Mtime: time.Now().Unix(),
  1761. Status: 1,
  1762. RecordTime: order.StartTime,
  1763. OrgId: adminUserInfo.Org.Id,
  1764. GoodId: bloodlines,
  1765. GoodTypeId: bloodlines_good_type_id,
  1766. }
  1767. service.AddSigleAutoReduceRecordInfo(details)
  1768. } else if err == nil {
  1769. if user.ID > 0 {
  1770. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1777. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1778. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1779. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1780. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1781. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1782. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1783. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1784. warehouseOutInfo := &models.WarehouseOutInfo{
  1785. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1786. WarehouseOutId: out.ID,
  1787. Count: 1,
  1788. Status: 1,
  1789. Ctime: time.Now().Unix(),
  1790. Remark: "",
  1791. OrgId: adminUserInfo.Org.Id,
  1792. Type: 1,
  1793. Manufacturer: 0,
  1794. Dealer: 0,
  1795. IsSys: 1,
  1796. SysRecordTime: order.StartTime,
  1797. }
  1798. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  1799. warehouseOutInfo.Price = stockInInfo.Price
  1800. warehouseOutInfo.GoodId = tubing_hemodialysis
  1801. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1802. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1803. if err == nil {
  1804. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1805. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1806. if err == gorm.ErrRecordNotFound {
  1807. details := &models.AutomaticReduceDetail{
  1808. WarehouseOutId: warehouseOutInfo.ID,
  1809. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1810. PatientId: id,
  1811. Ctime: time.Now().Unix(),
  1812. Mtime: time.Now().Unix(),
  1813. Status: 1,
  1814. RecordTime: order.StartTime,
  1815. OrgId: adminUserInfo.Org.Id,
  1816. GoodId: tubing_hemodialysis,
  1817. GoodTypeId: tubingHemodialysis_good_type_id,
  1818. }
  1819. service.AddSigleAutoReduceRecordInfo(details)
  1820. } else if err == nil {
  1821. if user.ID > 0 {
  1822. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  1823. }
  1824. }
  1825. }
  1826. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1827. if newOut.ID > 0 {
  1828. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1829. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1830. if err == gorm.ErrRecordNotFound {
  1831. details := &models.AutomaticReduceDetail{
  1832. WarehouseOutId: newOut.ID,
  1833. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1834. PatientId: id,
  1835. Ctime: time.Now().Unix(),
  1836. Mtime: time.Now().Unix(),
  1837. Status: 1,
  1838. RecordTime: order.StartTime,
  1839. OrgId: adminUserInfo.Org.Id,
  1840. GoodId: tubing_hemodialysis,
  1841. GoodTypeId: tubingHemodialysis_good_type_id,
  1842. }
  1843. service.AddSigleAutoReduceRecordInfo(details)
  1844. } else if err == nil {
  1845. if user.ID > 0 {
  1846. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. if dialysisPrescription.Package != safe_package {
  1853. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1854. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1855. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1856. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1857. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1858. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1859. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1860. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1861. warehouseOutInfo := &models.WarehouseOutInfo{
  1862. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1863. WarehouseOutId: out.ID,
  1864. Count: 1,
  1865. Status: 1,
  1866. Ctime: time.Now().Unix(),
  1867. Remark: "",
  1868. OrgId: adminUserInfo.Org.Id,
  1869. Type: 1,
  1870. Manufacturer: 0,
  1871. Dealer: 0,
  1872. IsSys: 1,
  1873. SysRecordTime: order.StartTime,
  1874. }
  1875. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  1876. warehouseOutInfo.Price = stockInInfo.Price
  1877. warehouseOutInfo.GoodId = safe_package
  1878. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1879. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1880. if err == nil {
  1881. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1882. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1883. if err == gorm.ErrRecordNotFound {
  1884. details := &models.AutomaticReduceDetail{
  1885. WarehouseOutId: warehouseOutInfo.ID,
  1886. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1887. PatientId: id,
  1888. Ctime: time.Now().Unix(),
  1889. Mtime: time.Now().Unix(),
  1890. Status: 1,
  1891. RecordTime: order.StartTime,
  1892. OrgId: adminUserInfo.Org.Id,
  1893. GoodId: safe_package,
  1894. GoodTypeId: safe_package_good_type_id,
  1895. }
  1896. service.AddSigleAutoReduceRecordInfo(details)
  1897. } else if err == nil {
  1898. if user.ID > 0 {
  1899. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  1900. }
  1901. }
  1902. }
  1903. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1904. if newOut.ID > 0 {
  1905. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1906. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1907. if err == gorm.ErrRecordNotFound {
  1908. details := &models.AutomaticReduceDetail{
  1909. WarehouseOutId: newOut.ID,
  1910. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1911. PatientId: id,
  1912. Ctime: time.Now().Unix(),
  1913. Mtime: time.Now().Unix(),
  1914. Status: 1,
  1915. RecordTime: order.StartTime,
  1916. OrgId: adminUserInfo.Org.Id,
  1917. GoodId: safe_package,
  1918. GoodTypeId: safe_package_good_type_id,
  1919. }
  1920. service.AddSigleAutoReduceRecordInfo(details)
  1921. } else if err == nil {
  1922. if user.ID > 0 {
  1923. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. if dialysisPrescription.ALiquid != a_liquid {
  1930. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1931. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1932. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1933. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1934. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1935. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1936. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1937. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1938. warehouseOutInfo := &models.WarehouseOutInfo{
  1939. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1940. WarehouseOutId: out.ID,
  1941. Count: 1,
  1942. Status: 1,
  1943. Ctime: time.Now().Unix(),
  1944. Remark: "",
  1945. OrgId: adminUserInfo.Org.Id,
  1946. Type: 1,
  1947. Manufacturer: 0,
  1948. Dealer: 0,
  1949. IsSys: 1,
  1950. SysRecordTime: order.StartTime,
  1951. }
  1952. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  1953. warehouseOutInfo.Price = stockInInfo.Price
  1954. warehouseOutInfo.GoodId = a_liquid
  1955. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1956. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1957. if err == nil {
  1958. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1959. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1960. if err == gorm.ErrRecordNotFound {
  1961. details := &models.AutomaticReduceDetail{
  1962. WarehouseOutId: warehouseOutInfo.ID,
  1963. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1964. PatientId: id,
  1965. Ctime: time.Now().Unix(),
  1966. Mtime: time.Now().Unix(),
  1967. Status: 1,
  1968. RecordTime: order.StartTime,
  1969. OrgId: adminUserInfo.Org.Id,
  1970. GoodId: a_liquid,
  1971. GoodTypeId: aliquid_good_type_id,
  1972. }
  1973. service.AddSigleAutoReduceRecordInfo(details)
  1974. } else if err == nil {
  1975. if user.ID > 0 {
  1976. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  1977. }
  1978. }
  1979. }
  1980. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1981. if newOut.ID > 0 {
  1982. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1983. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1984. if err == gorm.ErrRecordNotFound {
  1985. details := &models.AutomaticReduceDetail{
  1986. WarehouseOutId: newOut.ID,
  1987. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1988. PatientId: id,
  1989. Ctime: time.Now().Unix(),
  1990. Mtime: time.Now().Unix(),
  1991. Status: 1,
  1992. RecordTime: order.StartTime,
  1993. OrgId: adminUserInfo.Org.Id,
  1994. GoodId: a_liquid,
  1995. GoodTypeId: aliquid_good_type_id,
  1996. }
  1997. service.AddSigleAutoReduceRecordInfo(details)
  1998. } else if err == nil {
  1999. if user.ID > 0 {
  2000. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2010. prescription.Modifier = adminUserInfo.AdminUser.Id
  2011. if dialysisPrescription.Creater == 0 {
  2012. prescription.Creater = adminUserInfo.AdminUser.Id
  2013. if appRole.UserType == 2 || appRole.UserType == 1 {
  2014. prescription_doctor = adminUserInfo.AdminUser.Id
  2015. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2016. } else {
  2017. prescription_doctor = 0
  2018. }
  2019. } else {
  2020. prescription.Creater = dialysisPrescription.Creater
  2021. }
  2022. prescription.ID = dialysisPrescription.ID
  2023. err := service.UpDateDialysisPrescription(&prescription)
  2024. if err == nil {
  2025. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2026. if updateErr != nil {
  2027. utils.ErrorLog("%v", updateErr)
  2028. }
  2029. c.ServeSuccessJSON(map[string]interface{}{
  2030. "prescription": prescription,
  2031. })
  2032. }
  2033. }
  2034. }
  2035. func (c *DialysisAPIController) Finish() {
  2036. id, _ := c.GetInt64("patient", 0)
  2037. recordDateStr := c.GetString("record_date")
  2038. nurseID, _ := c.GetInt64("nurse")
  2039. end_time := c.GetString("end_time")
  2040. if id <= 0 || nurseID <= 0 {
  2041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2042. return
  2043. }
  2044. adminUserInfo := c.GetMobileAdminUserInfo()
  2045. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2046. if patient.ID == 0 {
  2047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2048. return
  2049. }
  2050. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2051. if getNurseErr != nil {
  2052. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2054. return
  2055. } else if nurse == nil {
  2056. c.ErrorLog("护士不存在")
  2057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2058. return
  2059. }
  2060. if len(recordDateStr) == 0 {
  2061. recordDateStr = time.Now().Format("2006-01-02")
  2062. }
  2063. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2064. if parseDateErr != nil {
  2065. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2067. return
  2068. }
  2069. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2070. if parseEndDateErr != nil {
  2071. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2073. return
  2074. }
  2075. //now := time.Now()
  2076. //year, month, day := now.Date()
  2077. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2078. //todayTimeStamp := today_time.Unix()
  2079. // 获取当天的第一条透析纪录
  2080. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2081. if getMonitorRecordsErr != nil {
  2082. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2084. return
  2085. }
  2086. // 获取当前的最后一条透析纪录
  2087. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  2088. if getMonitorRecordsErr != nil {
  2089. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2091. return
  2092. }
  2093. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2094. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2095. if getAADErr != nil {
  2096. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2098. return
  2099. }
  2100. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2101. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2102. if assessmentAfterDislysis != nil {
  2103. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2104. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2105. } else {
  2106. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2107. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2108. tempassessmentAfterDislysis.Status = 1
  2109. tempassessmentAfterDislysis.PatientId = id
  2110. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2111. }
  2112. if dialysisOrder.Stage == 1 {
  2113. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2114. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2115. fmt.Println(value)
  2116. a, b := math.Modf(value)
  2117. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2118. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2119. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2120. fmt.Println(hour)
  2121. fmt.Println(minute)
  2122. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2123. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2124. }
  2125. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2126. //var num1 int64
  2127. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2128. //fmt.Println(num1)
  2129. //sub := float64(num1 / 3600)
  2130. //fmt.Println(sub)
  2131. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2132. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2133. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2134. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2135. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2136. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2137. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2138. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2139. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2140. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2141. }
  2142. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2143. if err != nil {
  2144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2145. return
  2146. }
  2147. if dialysisOrder == nil {
  2148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2149. return
  2150. }
  2151. if dialysisOrder.Stage == 2 {
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2153. return
  2154. }
  2155. if dialysisOrder.Stage == 1 {
  2156. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2157. //结束时候透析次数加1
  2158. service.UpdateSolutionByPatientId(id)
  2159. dialysisOrder.Stage = 2
  2160. dialysisOrder.FinishNurse = nurseID
  2161. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2162. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2163. dialysisOrder.EndTime = endDate.Unix()
  2164. if err == nil {
  2165. c.ServeSuccessJSON(map[string]interface{}{
  2166. "dialysisOrder": dialysisOrder,
  2167. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2168. })
  2169. } else {
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2171. }
  2172. }
  2173. }
  2174. func (c *DialysisAPIController) GetAllZone() {
  2175. adminUserInfo := c.GetMobileAdminUserInfo()
  2176. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2177. if err == nil {
  2178. c.ServeSuccessJSON(map[string]interface{}{
  2179. "zone": zone,
  2180. })
  2181. }
  2182. }
  2183. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2184. adminUserInfo := c.GetMobileAdminUserInfo()
  2185. page, _ := c.GetInt64("page", 1)
  2186. limit, _ := c.GetInt64("limit", 10)
  2187. schedulType, _ := c.GetInt64("schedul_type", 0)
  2188. startTime, _ := c.GetInt64("schedul_time", 0)
  2189. partitionType, _ := c.GetInt64("partition_type", 0)
  2190. keywords := c.GetString("keywords")
  2191. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2192. if err == nil {
  2193. c.ServeSuccessJSON(map[string]interface{}{
  2194. "schedule": dialysisSchedule,
  2195. })
  2196. }
  2197. return
  2198. }
  2199. // /m/api/dialysis/start [post]
  2200. // @param patient_id:int
  2201. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2202. // @param nurse:int 上机护士
  2203. // @param bed:int 床位号
  2204. func (this *DialysisAPIController) StartDialysis() {
  2205. patientID, _ := this.GetInt64("patient_id")
  2206. recordDateStr := this.GetString("record_date")
  2207. nurseID, _ := this.GetInt64("nurse")
  2208. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2209. blood_drawing, _ := this.GetInt64("blood_drawing")
  2210. schedual_type, _ := this.GetInt64("schedual_type")
  2211. bedID, _ := this.GetInt64("bed")
  2212. start_time := this.GetString("start_time")
  2213. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2218. if parseStartDateErr != nil {
  2219. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2221. return
  2222. }
  2223. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2224. if parseErr != nil {
  2225. this.ErrorLog("时间解析失败:%v", parseErr)
  2226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. adminUserInfo := this.GetMobileAdminUserInfo()
  2230. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2231. if getPatientErr != nil {
  2232. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2234. return
  2235. } else if patient == nil {
  2236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2237. return
  2238. }
  2239. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2240. if getNurseErr != nil {
  2241. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2243. return
  2244. } else if nurse == nil {
  2245. this.ErrorLog("护士不存在")
  2246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2247. return
  2248. }
  2249. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2250. if getNurseErr != nil {
  2251. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2253. return
  2254. } else if nurse == nil {
  2255. this.ErrorLog("护士不存在")
  2256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2257. return
  2258. }
  2259. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2260. if getDeviceNumberErr != nil {
  2261. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2263. return
  2264. } else if deviceNumber == nil {
  2265. this.ErrorLog("床位号不存在")
  2266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2267. return
  2268. }
  2269. _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2270. if configs.IsOpen == 1 {
  2271. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2272. if prescription.ID == 0 {
  2273. this.ErrorLog("上机失败,还没开处方")
  2274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  2275. return
  2276. }
  2277. }
  2278. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2279. if getRecordErr != nil {
  2280. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2282. return
  2283. } else if dialysisRecord != nil {
  2284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2285. return
  2286. }
  2287. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2288. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2289. timeLayout := "2006-01-02 15:04:05"
  2290. loc, _ := time.LoadLocation("Local")
  2291. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2292. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2293. schedulestartTime := theStartTime.Unix()
  2294. scheduleendTime := theEndTime.Unix()
  2295. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2296. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2297. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2298. if err == gorm.ErrRecordNotFound { //空床位
  2299. // 修改了床位逻辑
  2300. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2301. if daySchedule.ID > 0 {
  2302. daySchedule.PartitionId = deviceNumber.ZoneID
  2303. daySchedule.BedId = bedID
  2304. daySchedule.ScheduleType = schedual_type
  2305. daySchedule.UpdatedTime = time.Now().Unix()
  2306. err := service.UpdateSchedule(&daySchedule)
  2307. if err != nil {
  2308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2309. return
  2310. }
  2311. }
  2312. } else if err == nil {
  2313. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2314. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2315. if daySchedule.ID > 0 {
  2316. daySchedule.PartitionId = deviceNumber.ZoneID
  2317. daySchedule.BedId = bedID
  2318. daySchedule.ScheduleType = schedual_type
  2319. daySchedule.UpdatedTime = time.Now().Unix()
  2320. err := service.UpdateSchedule(&daySchedule)
  2321. if err != nil {
  2322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2323. return
  2324. }
  2325. }
  2326. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2328. return
  2329. }
  2330. } else if err != nil {
  2331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2332. return
  2333. }
  2334. dialysisRecord = &models.DialysisOrder{
  2335. DialysisDate: recordDate.Unix(),
  2336. UserOrgId: adminUserInfo.Org.Id,
  2337. PatientId: patientID,
  2338. Stage: 1,
  2339. BedID: bedID,
  2340. StartNurse: nurseID,
  2341. Status: 1,
  2342. StartTime: startDate.Unix(),
  2343. CreatedTime: time.Now().Unix(),
  2344. UpdatedTime: time.Now().Unix(),
  2345. PunctureNurse: puncture_nurse,
  2346. Creator: adminUserInfo.AdminUser.Id,
  2347. Modifier: adminUserInfo.AdminUser.Id,
  2348. SchedualType: schedual_type,
  2349. }
  2350. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2351. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2352. var tempdispose string
  2353. // 只针对中能建
  2354. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2355. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2356. }
  2357. var ultrafiltration_rate float64
  2358. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2359. if prescription.ID > 0 {
  2360. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2361. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2362. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  2363. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2364. }
  2365. // 只针对方济医院
  2366. if template.TemplateId == 1 {
  2367. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2368. ultrafiltration_rate = value
  2369. }
  2370. }
  2371. }
  2372. record := models.MonitoringRecord{
  2373. UserOrgId: adminUserInfo.Org.Id,
  2374. PatientId: patientID,
  2375. DialysisOrderId: dialysisRecord.ID,
  2376. MonitoringDate: schedulestartTime,
  2377. OperateTime: startDate.Unix(),
  2378. // MonitoringTime: recordTime,
  2379. MonitoringNurse: nurseID,
  2380. Dispose: tempdispose,
  2381. UltrafiltrationRate: ultrafiltration_rate,
  2382. UltrafiltrationVolume: 0,
  2383. Status: 1,
  2384. CreatedTime: time.Now().Unix(),
  2385. UpdatedTime: time.Now().Unix(),
  2386. }
  2387. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2388. if newdialysisRecord.ID > 0 {
  2389. err := service.CreateMonitor(&record)
  2390. if err != nil {
  2391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2392. return
  2393. }
  2394. }
  2395. //是否启动自动扣减功能
  2396. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2397. //启动的话
  2398. if config.IsOpen == 1 {
  2399. niprocart, _ := beego.AppConfig.Int64("niprocart")
  2400. jms, _ := beego.AppConfig.Int64("jms")
  2401. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  2402. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  2403. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  2404. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  2405. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  2406. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  2407. injector, _ := beego.AppConfig.Int64("injector")
  2408. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  2409. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  2410. safe_package, _ := beego.AppConfig.Int64("package")
  2411. aliquid, _ := beego.AppConfig.Int64("aliquid")
  2412. //库存自动扣减功能
  2413. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2414. if prescription.ID > 0 {
  2415. out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
  2416. if err == gorm.ErrRecordNotFound {
  2417. //没有记录,则创建出库单
  2418. timeStr := time.Now().Format("2006-01-02")
  2419. timeArr := strings.Split(timeStr, "-")
  2420. total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  2421. total = total + 1
  2422. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2423. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2424. number = number + total
  2425. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2426. creater := adminUserInfo.AdminUser.Id
  2427. warehouseOut := models.WarehouseOut{
  2428. WarehouseOutOrderNumber: warehousing_out_order,
  2429. OperationTime: time.Now().Unix(),
  2430. OrgId: adminUserInfo.Org.Id,
  2431. Creater: creater,
  2432. Ctime: time.Now().Unix(),
  2433. Status: 1,
  2434. WarehouseOutTime: recordDate.Unix(),
  2435. Dealer: 0,
  2436. Manufacturer: 0,
  2437. Type: 1,
  2438. IsSys: 1,
  2439. }
  2440. err := service.AddSigleWarehouseOut(&warehouseOut)
  2441. if err != nil {
  2442. utils.TraceLog("创建出库单失败 err = %v", err)
  2443. } else {
  2444. if prescription.Niprocart > 0 {
  2445. warehouseOutInfo := &models.WarehouseOutInfo{
  2446. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2447. WarehouseOutId: warehouseOut.ID,
  2448. Count: 1,
  2449. Status: 1,
  2450. Ctime: time.Now().Unix(),
  2451. Remark: "",
  2452. OrgId: adminUserInfo.Org.Id,
  2453. Type: 1,
  2454. Manufacturer: 0,
  2455. Dealer: 0,
  2456. IsSys: 1,
  2457. SysRecordTime: startDate.Unix(),
  2458. }
  2459. //查出入库记录中最后一条记录
  2460. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2461. warehouseOutInfo.Price = stockInInfo.Price
  2462. warehouseOutInfo.GoodId = prescription.Niprocart
  2463. warehouseOutInfo.GoodTypeId = niprocart
  2464. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2465. if err == nil {
  2466. details := &models.AutomaticReduceDetail{
  2467. WarehouseOutId: warehouseOutInfo.ID,
  2468. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2469. PatientId: patientID,
  2470. Ctime: time.Now().Unix(),
  2471. Mtime: time.Now().Unix(),
  2472. Status: 1,
  2473. RecordTime: startDate.Unix(),
  2474. OrgId: adminUserInfo.Org.Id,
  2475. GoodId: prescription.Niprocart,
  2476. GoodTypeId: niprocart,
  2477. }
  2478. service.AddSigleAutoReduceRecordInfo(details)
  2479. }
  2480. }
  2481. if prescription.Jms > 0 {
  2482. warehouseOutInfo := &models.WarehouseOutInfo{
  2483. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2484. WarehouseOutId: warehouseOut.ID,
  2485. Count: 1,
  2486. Status: 1,
  2487. Ctime: time.Now().Unix(),
  2488. Remark: "",
  2489. OrgId: adminUserInfo.Org.Id,
  2490. Type: 1,
  2491. Manufacturer: 0,
  2492. Dealer: 0,
  2493. IsSys: 1,
  2494. SysRecordTime: startDate.Unix(),
  2495. }
  2496. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2497. warehouseOutInfo.Price = stockInInfo.Price
  2498. warehouseOutInfo.GoodId = prescription.Jms
  2499. warehouseOutInfo.GoodTypeId = jms
  2500. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2501. if err == nil {
  2502. details := &models.AutomaticReduceDetail{
  2503. WarehouseOutId: warehouseOutInfo.ID,
  2504. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2505. PatientId: patientID,
  2506. Ctime: time.Now().Unix(),
  2507. Mtime: time.Now().Unix(),
  2508. Status: 1,
  2509. RecordTime: startDate.Unix(),
  2510. OrgId: adminUserInfo.Org.Id,
  2511. GoodId: prescription.Jms,
  2512. GoodTypeId: jms,
  2513. }
  2514. service.AddSigleAutoReduceRecordInfo(details)
  2515. }
  2516. }
  2517. if prescription.FistulaNeedleSet > 0 {
  2518. warehouseOutInfo := &models.WarehouseOutInfo{
  2519. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2520. WarehouseOutId: warehouseOut.ID,
  2521. Count: 1,
  2522. Status: 1,
  2523. Ctime: time.Now().Unix(),
  2524. Remark: "",
  2525. OrgId: adminUserInfo.Org.Id,
  2526. Type: 1,
  2527. Manufacturer: 0,
  2528. Dealer: 0,
  2529. IsSys: 1,
  2530. SysRecordTime: startDate.Unix(),
  2531. }
  2532. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  2533. warehouseOutInfo.Price = stockInInfo.Price
  2534. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  2535. warehouseOutInfo.GoodTypeId = fistula_needle_set
  2536. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2537. if err == nil {
  2538. details := &models.AutomaticReduceDetail{
  2539. WarehouseOutId: warehouseOutInfo.ID,
  2540. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2541. PatientId: patientID,
  2542. Ctime: time.Now().Unix(),
  2543. Mtime: time.Now().Unix(),
  2544. Status: 1,
  2545. RecordTime: startDate.Unix(),
  2546. OrgId: adminUserInfo.Org.Id,
  2547. GoodId: prescription.FistulaNeedleSet,
  2548. GoodTypeId: fistula_needle_set,
  2549. }
  2550. service.AddSigleAutoReduceRecordInfo(details)
  2551. }
  2552. }
  2553. if prescription.FistulaNeedleSet16 > 0 {
  2554. warehouseOutInfo := &models.WarehouseOutInfo{
  2555. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2556. WarehouseOutId: warehouseOut.ID,
  2557. Count: 1,
  2558. Status: 1,
  2559. Ctime: time.Now().Unix(),
  2560. Remark: "",
  2561. OrgId: adminUserInfo.Org.Id,
  2562. Type: 1,
  2563. Manufacturer: 0,
  2564. Dealer: 0,
  2565. IsSys: 1,
  2566. SysRecordTime: startDate.Unix(),
  2567. }
  2568. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  2569. warehouseOutInfo.Price = stockInInfo.Price
  2570. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  2571. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  2572. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2573. if err == nil {
  2574. details := &models.AutomaticReduceDetail{
  2575. WarehouseOutId: warehouseOutInfo.ID,
  2576. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2577. PatientId: patientID,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: time.Now().Unix(),
  2580. Status: 1,
  2581. RecordTime: startDate.Unix(),
  2582. OrgId: adminUserInfo.Org.Id,
  2583. GoodId: prescription.FistulaNeedleSet16,
  2584. GoodTypeId: fistula_needle_set_16,
  2585. }
  2586. service.AddSigleAutoReduceRecordInfo(details)
  2587. }
  2588. }
  2589. if prescription.Hemoperfusion > 0 {
  2590. warehouseOutInfo := &models.WarehouseOutInfo{
  2591. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2592. WarehouseOutId: warehouseOut.ID,
  2593. Count: 1,
  2594. Status: 1,
  2595. Ctime: time.Now().Unix(),
  2596. Remark: "",
  2597. OrgId: adminUserInfo.Org.Id,
  2598. Type: 1,
  2599. Manufacturer: 0,
  2600. Dealer: 0,
  2601. IsSys: 1,
  2602. SysRecordTime: startDate.Unix(),
  2603. }
  2604. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  2605. warehouseOutInfo.Price = stockInInfo.Price
  2606. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  2607. warehouseOutInfo.GoodTypeId = hemoperfusion
  2608. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2609. if err == nil {
  2610. details := &models.AutomaticReduceDetail{
  2611. WarehouseOutId: warehouseOutInfo.ID,
  2612. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2613. PatientId: patientID,
  2614. Ctime: time.Now().Unix(),
  2615. Mtime: time.Now().Unix(),
  2616. Status: 1,
  2617. RecordTime: startDate.Unix(),
  2618. OrgId: adminUserInfo.Org.Id,
  2619. GoodId: prescription.Hemoperfusion,
  2620. GoodTypeId: hemoperfusion,
  2621. }
  2622. service.AddSigleAutoReduceRecordInfo(details)
  2623. }
  2624. }
  2625. if prescription.DialyserSterilised > 0 {
  2626. warehouseOutInfo := &models.WarehouseOutInfo{
  2627. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2628. WarehouseOutId: warehouseOut.ID,
  2629. Count: 1,
  2630. Status: 1,
  2631. Ctime: time.Now().Unix(),
  2632. Remark: "",
  2633. OrgId: adminUserInfo.Org.Id,
  2634. Type: 1,
  2635. Manufacturer: 0,
  2636. Dealer: 0,
  2637. IsSys: 1,
  2638. SysRecordTime: startDate.Unix(),
  2639. }
  2640. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  2641. warehouseOutInfo.Price = stockInInfo.Price
  2642. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  2643. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  2644. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2645. if err == nil {
  2646. details := &models.AutomaticReduceDetail{
  2647. WarehouseOutId: warehouseOutInfo.ID,
  2648. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2649. PatientId: patientID,
  2650. Ctime: time.Now().Unix(),
  2651. Mtime: time.Now().Unix(),
  2652. Status: 1,
  2653. RecordTime: startDate.Unix(),
  2654. OrgId: adminUserInfo.Org.Id,
  2655. GoodId: prescription.DialyserSterilised,
  2656. GoodTypeId: dialyser_sterilised,
  2657. }
  2658. service.AddSigleAutoReduceRecordInfo(details)
  2659. }
  2660. }
  2661. if prescription.Filtryzer > 0 {
  2662. warehouseOutInfo := &models.WarehouseOutInfo{
  2663. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2664. WarehouseOutId: warehouseOut.ID,
  2665. Count: 1,
  2666. Status: 1,
  2667. Ctime: time.Now().Unix(),
  2668. Remark: "",
  2669. OrgId: adminUserInfo.Org.Id,
  2670. Type: 1,
  2671. Manufacturer: 0,
  2672. Dealer: 0,
  2673. IsSys: 1,
  2674. SysRecordTime: startDate.Unix(),
  2675. }
  2676. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  2677. warehouseOutInfo.Price = stockInInfo.Price
  2678. warehouseOutInfo.GoodId = prescription.Filtryzer
  2679. warehouseOutInfo.GoodTypeId = filtryzer
  2680. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2681. if err == nil {
  2682. details := &models.AutomaticReduceDetail{
  2683. WarehouseOutId: warehouseOutInfo.ID,
  2684. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2685. PatientId: patientID,
  2686. Ctime: time.Now().Unix(),
  2687. Mtime: time.Now().Unix(),
  2688. Status: 1,
  2689. RecordTime: startDate.Unix(),
  2690. OrgId: adminUserInfo.Org.Id,
  2691. GoodId: prescription.Filtryzer,
  2692. GoodTypeId: filtryzer,
  2693. }
  2694. service.AddSigleAutoReduceRecordInfo(details)
  2695. }
  2696. }
  2697. if prescription.Dialyzers > 0 {
  2698. warehouseOutInfo := &models.WarehouseOutInfo{
  2699. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2700. WarehouseOutId: warehouseOut.ID,
  2701. Count: 1,
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Remark: "",
  2705. OrgId: adminUserInfo.Org.Id,
  2706. Type: 1,
  2707. Manufacturer: 0,
  2708. Dealer: 0,
  2709. IsSys: 1,
  2710. SysRecordTime: startDate.Unix(),
  2711. }
  2712. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  2713. warehouseOutInfo.Price = stockInInfo.Price
  2714. warehouseOutInfo.GoodId = prescription.Dialyzers
  2715. warehouseOutInfo.GoodTypeId = dialyzers
  2716. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2717. if err == nil {
  2718. details := &models.AutomaticReduceDetail{
  2719. WarehouseOutId: warehouseOutInfo.ID,
  2720. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2721. PatientId: patientID,
  2722. Ctime: time.Now().Unix(),
  2723. Mtime: time.Now().Unix(),
  2724. Status: 1,
  2725. RecordTime: startDate.Unix(),
  2726. OrgId: adminUserInfo.Org.Id,
  2727. GoodId: prescription.Dialyzers,
  2728. GoodTypeId: dialyzers,
  2729. }
  2730. service.AddSigleAutoReduceRecordInfo(details)
  2731. }
  2732. }
  2733. if prescription.Injector > 0 {
  2734. warehouseOutInfo := &models.WarehouseOutInfo{
  2735. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2736. WarehouseOutId: warehouseOut.ID,
  2737. Count: 1,
  2738. Status: 1,
  2739. Ctime: time.Now().Unix(),
  2740. Remark: "",
  2741. OrgId: adminUserInfo.Org.Id,
  2742. Type: 1,
  2743. Manufacturer: 0,
  2744. Dealer: 0,
  2745. IsSys: 1,
  2746. SysRecordTime: startDate.Unix(),
  2747. }
  2748. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  2749. warehouseOutInfo.Price = stockInInfo.Price
  2750. warehouseOutInfo.GoodId = prescription.Injector
  2751. warehouseOutInfo.GoodTypeId = injector
  2752. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2753. if err == nil {
  2754. details := &models.AutomaticReduceDetail{
  2755. WarehouseOutId: warehouseOutInfo.ID,
  2756. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2757. PatientId: patientID,
  2758. Ctime: time.Now().Unix(),
  2759. Mtime: time.Now().Unix(),
  2760. Status: 1,
  2761. RecordTime: startDate.Unix(),
  2762. OrgId: adminUserInfo.Org.Id,
  2763. GoodId: prescription.Injector,
  2764. GoodTypeId: injector,
  2765. }
  2766. service.AddSigleAutoReduceRecordInfo(details)
  2767. }
  2768. }
  2769. if prescription.Bloodlines > 0 {
  2770. warehouseOutInfo := &models.WarehouseOutInfo{
  2771. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2772. WarehouseOutId: warehouseOut.ID,
  2773. Count: 1,
  2774. Status: 1,
  2775. Ctime: time.Now().Unix(),
  2776. Remark: "",
  2777. OrgId: adminUserInfo.Org.Id,
  2778. Type: 1,
  2779. Manufacturer: 0,
  2780. Dealer: 0,
  2781. IsSys: 1,
  2782. SysRecordTime: startDate.Unix(),
  2783. }
  2784. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  2785. warehouseOutInfo.Price = stockInInfo.Price
  2786. warehouseOutInfo.GoodId = prescription.Bloodlines
  2787. warehouseOutInfo.GoodTypeId = bloodlines
  2788. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2789. if err == nil {
  2790. details := &models.AutomaticReduceDetail{
  2791. WarehouseOutId: warehouseOutInfo.ID,
  2792. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2793. PatientId: patientID,
  2794. Ctime: time.Now().Unix(),
  2795. Mtime: time.Now().Unix(),
  2796. Status: 1,
  2797. RecordTime: startDate.Unix(),
  2798. OrgId: adminUserInfo.Org.Id,
  2799. GoodId: prescription.Bloodlines,
  2800. GoodTypeId: bloodlines,
  2801. }
  2802. service.AddSigleAutoReduceRecordInfo(details)
  2803. }
  2804. }
  2805. if prescription.TubingHemodialysis > 0 {
  2806. warehouseOutInfo := &models.WarehouseOutInfo{
  2807. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2808. WarehouseOutId: warehouseOut.ID,
  2809. Count: 1,
  2810. Status: 1,
  2811. Ctime: time.Now().Unix(),
  2812. Remark: "",
  2813. OrgId: adminUserInfo.Org.Id,
  2814. Type: 1,
  2815. Manufacturer: 0,
  2816. Dealer: 0,
  2817. IsSys: 1,
  2818. SysRecordTime: startDate.Unix(),
  2819. }
  2820. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  2821. warehouseOutInfo.Price = stockInInfo.Price
  2822. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  2823. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  2824. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2825. if err == nil {
  2826. details := &models.AutomaticReduceDetail{
  2827. WarehouseOutId: warehouseOutInfo.ID,
  2828. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2829. PatientId: patientID,
  2830. Ctime: time.Now().Unix(),
  2831. Mtime: time.Now().Unix(),
  2832. Status: 1,
  2833. RecordTime: startDate.Unix(),
  2834. OrgId: adminUserInfo.Org.Id,
  2835. GoodId: prescription.TubingHemodialysis,
  2836. GoodTypeId: tubingHemodialysis,
  2837. }
  2838. service.AddSigleAutoReduceRecordInfo(details)
  2839. }
  2840. }
  2841. if prescription.Package > 0 {
  2842. warehouseOutInfo := &models.WarehouseOutInfo{
  2843. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2844. WarehouseOutId: warehouseOut.ID,
  2845. Count: 1,
  2846. Status: 1,
  2847. Ctime: time.Now().Unix(),
  2848. Remark: "",
  2849. OrgId: adminUserInfo.Org.Id,
  2850. Type: 1,
  2851. Manufacturer: 0,
  2852. Dealer: 0,
  2853. IsSys: 1,
  2854. SysRecordTime: startDate.Unix(),
  2855. }
  2856. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  2857. warehouseOutInfo.Price = stockInInfo.Price
  2858. warehouseOutInfo.GoodId = prescription.Package
  2859. warehouseOutInfo.GoodTypeId = safe_package
  2860. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2861. if err == nil {
  2862. details := &models.AutomaticReduceDetail{
  2863. WarehouseOutId: warehouseOutInfo.ID,
  2864. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2865. PatientId: patientID,
  2866. Ctime: time.Now().Unix(),
  2867. Mtime: time.Now().Unix(),
  2868. Status: 1,
  2869. RecordTime: startDate.Unix(),
  2870. OrgId: adminUserInfo.Org.Id,
  2871. GoodId: prescription.Package,
  2872. GoodTypeId: safe_package,
  2873. }
  2874. service.AddSigleAutoReduceRecordInfo(details)
  2875. }
  2876. }
  2877. if prescription.ALiquid > 0 {
  2878. warehouseOutInfo := &models.WarehouseOutInfo{
  2879. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2880. WarehouseOutId: warehouseOut.ID,
  2881. Count: 1,
  2882. Status: 1,
  2883. Ctime: time.Now().Unix(),
  2884. Remark: "",
  2885. OrgId: adminUserInfo.Org.Id,
  2886. Type: 1,
  2887. Manufacturer: 0,
  2888. Dealer: 0,
  2889. IsSys: 1,
  2890. SysRecordTime: startDate.Unix(),
  2891. }
  2892. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  2893. warehouseOutInfo.Price = stockInInfo.Price
  2894. warehouseOutInfo.GoodId = prescription.ALiquid
  2895. warehouseOutInfo.GoodTypeId = aliquid
  2896. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2897. if err == nil {
  2898. details := &models.AutomaticReduceDetail{
  2899. WarehouseOutId: warehouseOutInfo.ID,
  2900. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2901. PatientId: patientID,
  2902. Ctime: time.Now().Unix(),
  2903. Mtime: time.Now().Unix(),
  2904. Status: 1,
  2905. RecordTime: startDate.Unix(),
  2906. OrgId: adminUserInfo.Org.Id,
  2907. GoodId: prescription.ALiquid,
  2908. GoodTypeId: aliquid,
  2909. }
  2910. service.AddSigleAutoReduceRecordInfo(details)
  2911. }
  2912. }
  2913. }
  2914. } else if err == nil {
  2915. if out.ID > 0 {
  2916. if prescription.Niprocart > 0 {
  2917. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
  2918. if err == gorm.ErrRecordNotFound {
  2919. warehouseOutInfo := &models.WarehouseOutInfo{
  2920. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2921. WarehouseOutId: out.ID,
  2922. Status: 1,
  2923. Ctime: time.Now().Unix(),
  2924. Remark: "",
  2925. OrgId: adminUserInfo.Org.Id,
  2926. Type: 1,
  2927. Manufacturer: 0,
  2928. Dealer: 0,
  2929. IsSys: 1,
  2930. SysRecordTime: startDate.Unix(),
  2931. }
  2932. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2933. warehouseOutInfo.Price = stockInInfo.Price
  2934. warehouseOutInfo.GoodId = prescription.Niprocart
  2935. warehouseOutInfo.GoodTypeId = niprocart
  2936. warehouseOutInfo.Count = 1
  2937. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2938. if err == nil {
  2939. details := &models.AutomaticReduceDetail{
  2940. WarehouseOutId: warehouseOutInfo.ID,
  2941. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2942. PatientId: patientID,
  2943. Ctime: time.Now().Unix(),
  2944. Mtime: time.Now().Unix(),
  2945. Status: 1,
  2946. RecordTime: startDate.Unix(),
  2947. OrgId: adminUserInfo.Org.Id,
  2948. GoodId: prescription.Niprocart,
  2949. GoodTypeId: niprocart,
  2950. }
  2951. service.AddSigleAutoReduceRecordInfo(details)
  2952. }
  2953. } else if err == nil { //记录存在,则将数量加1
  2954. if outInfo.ID > 0 {
  2955. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  2956. }
  2957. details := &models.AutomaticReduceDetail{
  2958. WarehouseOutId: outInfo.ID,
  2959. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2960. PatientId: patientID,
  2961. Ctime: time.Now().Unix(),
  2962. Mtime: time.Now().Unix(),
  2963. Status: 1,
  2964. RecordTime: startDate.Unix(),
  2965. OrgId: adminUserInfo.Org.Id,
  2966. GoodId: prescription.Niprocart,
  2967. GoodTypeId: niprocart,
  2968. }
  2969. service.AddSigleAutoReduceRecordInfo(details)
  2970. }
  2971. }
  2972. if prescription.Jms > 0 {
  2973. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.WarehouseOutOrderNumber)
  2974. if err == gorm.ErrRecordNotFound {
  2975. warehouseOutInfo := &models.WarehouseOutInfo{
  2976. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2977. WarehouseOutId: out.ID,
  2978. Status: 1,
  2979. Ctime: time.Now().Unix(),
  2980. Remark: "",
  2981. OrgId: adminUserInfo.Org.Id,
  2982. Type: 1,
  2983. Manufacturer: 0,
  2984. Dealer: 0,
  2985. IsSys: 1,
  2986. SysRecordTime: startDate.Unix(),
  2987. }
  2988. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2989. warehouseOutInfo.Price = stockInInfo.Price
  2990. warehouseOutInfo.GoodId = prescription.Jms
  2991. warehouseOutInfo.GoodTypeId = jms
  2992. warehouseOutInfo.Count = 1
  2993. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2994. if err == nil {
  2995. details := &models.AutomaticReduceDetail{
  2996. WarehouseOutId: warehouseOutInfo.ID,
  2997. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2998. PatientId: patientID,
  2999. Ctime: time.Now().Unix(),
  3000. Mtime: time.Now().Unix(),
  3001. Status: 1,
  3002. RecordTime: startDate.Unix(),
  3003. OrgId: adminUserInfo.Org.Id,
  3004. GoodId: prescription.Jms,
  3005. GoodTypeId: jms,
  3006. }
  3007. service.AddSigleAutoReduceRecordInfo(details)
  3008. }
  3009. } else if err == nil { //记录存在,则将数量加1
  3010. if outInfo.ID > 0 {
  3011. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3012. }
  3013. details := &models.AutomaticReduceDetail{
  3014. WarehouseOutId: outInfo.ID,
  3015. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3016. PatientId: patientID,
  3017. Ctime: time.Now().Unix(),
  3018. Mtime: time.Now().Unix(),
  3019. Status: 1,
  3020. RecordTime: startDate.Unix(),
  3021. OrgId: adminUserInfo.Org.Id,
  3022. GoodId: prescription.Jms,
  3023. GoodTypeId: jms,
  3024. }
  3025. service.AddSigleAutoReduceRecordInfo(details)
  3026. }
  3027. }
  3028. if prescription.FistulaNeedleSet > 0 {
  3029. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
  3030. if err == gorm.ErrRecordNotFound {
  3031. warehouseOutInfo := &models.WarehouseOutInfo{
  3032. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3033. WarehouseOutId: out.ID,
  3034. Status: 1,
  3035. Ctime: time.Now().Unix(),
  3036. Remark: "",
  3037. OrgId: adminUserInfo.Org.Id,
  3038. Type: 1,
  3039. Manufacturer: 0,
  3040. Dealer: 0,
  3041. IsSys: 1,
  3042. SysRecordTime: startDate.Unix(),
  3043. }
  3044. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  3045. warehouseOutInfo.Price = stockInInfo.Price
  3046. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  3047. warehouseOutInfo.GoodTypeId = fistula_needle_set
  3048. warehouseOutInfo.Count = 1
  3049. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3050. if err == nil {
  3051. details := &models.AutomaticReduceDetail{
  3052. WarehouseOutId: warehouseOutInfo.ID,
  3053. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3054. PatientId: patientID,
  3055. Ctime: time.Now().Unix(),
  3056. Mtime: time.Now().Unix(),
  3057. Status: 1,
  3058. RecordTime: startDate.Unix(),
  3059. OrgId: adminUserInfo.Org.Id,
  3060. GoodId: prescription.FistulaNeedleSet,
  3061. GoodTypeId: fistula_needle_set,
  3062. }
  3063. service.AddSigleAutoReduceRecordInfo(details)
  3064. }
  3065. } else if err == nil { //记录存在,则将数量加1
  3066. if outInfo.ID > 0 {
  3067. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3068. }
  3069. details := &models.AutomaticReduceDetail{
  3070. WarehouseOutId: outInfo.ID,
  3071. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3072. PatientId: patientID,
  3073. Ctime: time.Now().Unix(),
  3074. Mtime: time.Now().Unix(),
  3075. Status: 1,
  3076. RecordTime: startDate.Unix(),
  3077. OrgId: adminUserInfo.Org.Id,
  3078. GoodId: prescription.FistulaNeedleSet,
  3079. GoodTypeId: fistula_needle_set,
  3080. }
  3081. service.AddSigleAutoReduceRecordInfo(details)
  3082. }
  3083. }
  3084. if prescription.FistulaNeedleSet16 > 0 {
  3085. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
  3086. if err == gorm.ErrRecordNotFound {
  3087. warehouseOutInfo := &models.WarehouseOutInfo{
  3088. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3089. WarehouseOutId: out.ID,
  3090. Status: 1,
  3091. Ctime: time.Now().Unix(),
  3092. Remark: "",
  3093. OrgId: adminUserInfo.Org.Id,
  3094. Type: 1,
  3095. Manufacturer: 0,
  3096. Dealer: 0,
  3097. IsSys: 1,
  3098. SysRecordTime: startDate.Unix(),
  3099. }
  3100. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  3101. warehouseOutInfo.Price = stockInInfo.Price
  3102. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  3103. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  3104. warehouseOutInfo.Count = 1
  3105. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3106. if err == nil {
  3107. details := &models.AutomaticReduceDetail{
  3108. WarehouseOutId: warehouseOutInfo.ID,
  3109. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3110. PatientId: patientID,
  3111. Ctime: time.Now().Unix(),
  3112. Mtime: time.Now().Unix(),
  3113. Status: 1,
  3114. RecordTime: startDate.Unix(),
  3115. OrgId: adminUserInfo.Org.Id,
  3116. GoodId: prescription.FistulaNeedleSet16,
  3117. GoodTypeId: fistula_needle_set_16,
  3118. }
  3119. service.AddSigleAutoReduceRecordInfo(details)
  3120. }
  3121. } else if err == nil { //记录存在,则将数量加1
  3122. if outInfo.ID > 0 {
  3123. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3124. }
  3125. details := &models.AutomaticReduceDetail{
  3126. WarehouseOutId: outInfo.ID,
  3127. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3128. PatientId: patientID,
  3129. Ctime: time.Now().Unix(),
  3130. Mtime: time.Now().Unix(),
  3131. Status: 1,
  3132. RecordTime: startDate.Unix(),
  3133. OrgId: adminUserInfo.Org.Id,
  3134. GoodId: prescription.FistulaNeedleSet16,
  3135. GoodTypeId: fistula_needle_set_16,
  3136. }
  3137. service.AddSigleAutoReduceRecordInfo(details)
  3138. }
  3139. }
  3140. if prescription.Hemoperfusion > 0 {
  3141. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
  3142. if err == gorm.ErrRecordNotFound {
  3143. warehouseOutInfo := &models.WarehouseOutInfo{
  3144. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3145. WarehouseOutId: out.ID,
  3146. Status: 1,
  3147. Ctime: time.Now().Unix(),
  3148. Remark: "",
  3149. OrgId: adminUserInfo.Org.Id,
  3150. Type: 1,
  3151. Manufacturer: 0,
  3152. Dealer: 0,
  3153. IsSys: 1,
  3154. SysRecordTime: startDate.Unix(),
  3155. }
  3156. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  3157. warehouseOutInfo.Price = stockInInfo.Price
  3158. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  3159. warehouseOutInfo.GoodTypeId = hemoperfusion
  3160. warehouseOutInfo.Count = 1
  3161. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3162. if err == nil {
  3163. details := &models.AutomaticReduceDetail{
  3164. WarehouseOutId: warehouseOutInfo.ID,
  3165. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3166. PatientId: patientID,
  3167. Ctime: time.Now().Unix(),
  3168. Mtime: time.Now().Unix(),
  3169. Status: 1,
  3170. RecordTime: startDate.Unix(),
  3171. OrgId: adminUserInfo.Org.Id,
  3172. GoodId: prescription.Hemoperfusion,
  3173. GoodTypeId: hemoperfusion,
  3174. }
  3175. service.AddSigleAutoReduceRecordInfo(details)
  3176. }
  3177. } else if err == nil { //记录存在,则将数量加1
  3178. if outInfo.ID > 0 {
  3179. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3180. }
  3181. details := &models.AutomaticReduceDetail{
  3182. WarehouseOutId: outInfo.ID,
  3183. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3184. PatientId: patientID,
  3185. Ctime: time.Now().Unix(),
  3186. Mtime: time.Now().Unix(),
  3187. Status: 1,
  3188. RecordTime: startDate.Unix(),
  3189. OrgId: adminUserInfo.Org.Id,
  3190. GoodId: prescription.Hemoperfusion,
  3191. GoodTypeId: hemoperfusion,
  3192. }
  3193. service.AddSigleAutoReduceRecordInfo(details)
  3194. }
  3195. }
  3196. if prescription.DialyserSterilised > 0 {
  3197. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
  3198. if err == gorm.ErrRecordNotFound {
  3199. warehouseOutInfo := &models.WarehouseOutInfo{
  3200. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3201. WarehouseOutId: out.ID,
  3202. Status: 1,
  3203. Ctime: time.Now().Unix(),
  3204. Remark: "",
  3205. OrgId: adminUserInfo.Org.Id,
  3206. Type: 1,
  3207. Manufacturer: 0,
  3208. Dealer: 0,
  3209. IsSys: 1,
  3210. SysRecordTime: startDate.Unix(),
  3211. }
  3212. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  3213. warehouseOutInfo.Price = stockInInfo.Price
  3214. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  3215. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  3216. warehouseOutInfo.Count = 1
  3217. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3218. if err == nil {
  3219. details := &models.AutomaticReduceDetail{
  3220. WarehouseOutId: warehouseOutInfo.ID,
  3221. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3222. PatientId: patientID,
  3223. Ctime: time.Now().Unix(),
  3224. Mtime: time.Now().Unix(),
  3225. Status: 1,
  3226. RecordTime: startDate.Unix(),
  3227. OrgId: adminUserInfo.Org.Id,
  3228. GoodId: prescription.DialyserSterilised,
  3229. GoodTypeId: dialyser_sterilised,
  3230. }
  3231. service.AddSigleAutoReduceRecordInfo(details)
  3232. }
  3233. } else if err == nil { //记录存在,则将数量加1
  3234. if outInfo.ID > 0 {
  3235. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3236. }
  3237. details := &models.AutomaticReduceDetail{
  3238. WarehouseOutId: outInfo.ID,
  3239. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3240. PatientId: patientID,
  3241. Ctime: time.Now().Unix(),
  3242. Mtime: time.Now().Unix(),
  3243. Status: 1,
  3244. RecordTime: startDate.Unix(),
  3245. OrgId: adminUserInfo.Org.Id,
  3246. GoodId: prescription.DialyserSterilised,
  3247. GoodTypeId: dialyser_sterilised,
  3248. }
  3249. service.AddSigleAutoReduceRecordInfo(details)
  3250. }
  3251. }
  3252. if prescription.Filtryzer > 0 {
  3253. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
  3254. if err == gorm.ErrRecordNotFound {
  3255. warehouseOutInfo := &models.WarehouseOutInfo{
  3256. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3257. WarehouseOutId: out.ID,
  3258. Status: 1,
  3259. Ctime: time.Now().Unix(),
  3260. Remark: "",
  3261. OrgId: adminUserInfo.Org.Id,
  3262. Type: 1,
  3263. Manufacturer: 0,
  3264. Dealer: 0,
  3265. IsSys: 1,
  3266. SysRecordTime: startDate.Unix(),
  3267. }
  3268. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  3269. warehouseOutInfo.Price = stockInInfo.Price
  3270. warehouseOutInfo.GoodId = prescription.Filtryzer
  3271. warehouseOutInfo.GoodTypeId = filtryzer
  3272. warehouseOutInfo.Count = 1
  3273. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3274. if err == nil {
  3275. details := &models.AutomaticReduceDetail{
  3276. WarehouseOutId: warehouseOutInfo.ID,
  3277. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3278. PatientId: patientID,
  3279. Ctime: time.Now().Unix(),
  3280. Mtime: time.Now().Unix(),
  3281. Status: 1,
  3282. RecordTime: startDate.Unix(),
  3283. OrgId: adminUserInfo.Org.Id,
  3284. GoodId: prescription.Filtryzer,
  3285. GoodTypeId: filtryzer,
  3286. }
  3287. service.AddSigleAutoReduceRecordInfo(details)
  3288. }
  3289. } else if err == nil { //记录存在,则将耗材使用数量加1
  3290. if outInfo.ID > 0 {
  3291. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3292. }
  3293. //插入病人耗材使用记录
  3294. details := &models.AutomaticReduceDetail{
  3295. WarehouseOutId: outInfo.ID,
  3296. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3297. PatientId: patientID,
  3298. Ctime: time.Now().Unix(),
  3299. Mtime: time.Now().Unix(),
  3300. Status: 1,
  3301. RecordTime: startDate.Unix(),
  3302. OrgId: adminUserInfo.Org.Id,
  3303. GoodId: prescription.Filtryzer,
  3304. GoodTypeId: filtryzer,
  3305. }
  3306. service.AddSigleAutoReduceRecordInfo(details)
  3307. }
  3308. }
  3309. if prescription.Dialyzers > 0 {
  3310. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
  3311. if err == gorm.ErrRecordNotFound {
  3312. warehouseOutInfo := &models.WarehouseOutInfo{
  3313. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3314. WarehouseOutId: out.ID,
  3315. Status: 1,
  3316. Ctime: time.Now().Unix(),
  3317. Remark: "",
  3318. OrgId: adminUserInfo.Org.Id,
  3319. Type: 1,
  3320. Manufacturer: 0,
  3321. Dealer: 0,
  3322. IsSys: 1,
  3323. SysRecordTime: startDate.Unix(),
  3324. }
  3325. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  3326. warehouseOutInfo.Price = stockInInfo.Price
  3327. warehouseOutInfo.GoodId = prescription.Dialyzers
  3328. warehouseOutInfo.GoodTypeId = dialyzers
  3329. warehouseOutInfo.Count = 1
  3330. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3331. if err == nil {
  3332. details := &models.AutomaticReduceDetail{
  3333. WarehouseOutId: warehouseOutInfo.ID,
  3334. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3335. PatientId: patientID,
  3336. Ctime: time.Now().Unix(),
  3337. Mtime: time.Now().Unix(),
  3338. Status: 1,
  3339. RecordTime: startDate.Unix(),
  3340. OrgId: adminUserInfo.Org.Id,
  3341. GoodId: prescription.Dialyzers,
  3342. GoodTypeId: dialyzers,
  3343. }
  3344. service.AddSigleAutoReduceRecordInfo(details)
  3345. }
  3346. } else if err == nil { //记录存在,则将耗材使用数量加1
  3347. if outInfo.ID > 0 {
  3348. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3349. }
  3350. //插入病人耗材使用记录
  3351. details := &models.AutomaticReduceDetail{
  3352. WarehouseOutId: outInfo.ID,
  3353. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3354. PatientId: patientID,
  3355. Ctime: time.Now().Unix(),
  3356. Mtime: time.Now().Unix(),
  3357. Status: 1,
  3358. RecordTime: startDate.Unix(),
  3359. OrgId: adminUserInfo.Org.Id,
  3360. GoodId: prescription.Dialyzer,
  3361. GoodTypeId: dialyzers,
  3362. }
  3363. service.AddSigleAutoReduceRecordInfo(details)
  3364. }
  3365. }
  3366. if prescription.Injector > 0 {
  3367. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.WarehouseOutOrderNumber)
  3368. if err == gorm.ErrRecordNotFound {
  3369. warehouseOutInfo := &models.WarehouseOutInfo{
  3370. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3371. WarehouseOutId: out.ID,
  3372. Status: 1,
  3373. Ctime: time.Now().Unix(),
  3374. Remark: "",
  3375. OrgId: adminUserInfo.Org.Id,
  3376. Type: 1,
  3377. Manufacturer: 0,
  3378. Dealer: 0,
  3379. IsSys: 1,
  3380. SysRecordTime: startDate.Unix(),
  3381. }
  3382. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  3383. warehouseOutInfo.Price = stockInInfo.Price
  3384. warehouseOutInfo.GoodId = prescription.Injector
  3385. warehouseOutInfo.GoodTypeId = injector
  3386. warehouseOutInfo.Count = 1
  3387. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3388. if err == nil {
  3389. details := &models.AutomaticReduceDetail{
  3390. WarehouseOutId: warehouseOutInfo.ID,
  3391. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3392. PatientId: patientID,
  3393. Ctime: time.Now().Unix(),
  3394. Mtime: time.Now().Unix(),
  3395. Status: 1,
  3396. RecordTime: startDate.Unix(),
  3397. OrgId: adminUserInfo.Org.Id,
  3398. GoodId: prescription.Injector,
  3399. GoodTypeId: injector,
  3400. }
  3401. service.AddSigleAutoReduceRecordInfo(details)
  3402. }
  3403. } else if err == nil { //记录存在,则将耗材使用数量加1
  3404. if outInfo.ID > 0 {
  3405. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3406. }
  3407. //插入病人耗材使用记录
  3408. details := &models.AutomaticReduceDetail{
  3409. WarehouseOutId: outInfo.ID,
  3410. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3411. PatientId: patientID,
  3412. Ctime: time.Now().Unix(),
  3413. Mtime: time.Now().Unix(),
  3414. Status: 1,
  3415. RecordTime: startDate.Unix(),
  3416. OrgId: adminUserInfo.Org.Id,
  3417. GoodId: prescription.Injector,
  3418. GoodTypeId: injector,
  3419. }
  3420. service.AddSigleAutoReduceRecordInfo(details)
  3421. }
  3422. }
  3423. if prescription.Bloodlines > 0 {
  3424. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
  3425. if err == gorm.ErrRecordNotFound {
  3426. warehouseOutInfo := &models.WarehouseOutInfo{
  3427. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3428. WarehouseOutId: out.ID,
  3429. Status: 1,
  3430. Ctime: time.Now().Unix(),
  3431. Remark: "",
  3432. OrgId: adminUserInfo.Org.Id,
  3433. Type: 1,
  3434. Manufacturer: 0,
  3435. Dealer: 0,
  3436. IsSys: 1,
  3437. SysRecordTime: startDate.Unix(),
  3438. }
  3439. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  3440. warehouseOutInfo.Price = stockInInfo.Price
  3441. warehouseOutInfo.GoodId = prescription.Bloodlines
  3442. warehouseOutInfo.GoodTypeId = bloodlines
  3443. warehouseOutInfo.Count = 1
  3444. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3445. if err == nil {
  3446. details := &models.AutomaticReduceDetail{
  3447. WarehouseOutId: warehouseOutInfo.ID,
  3448. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3449. PatientId: patientID,
  3450. Ctime: time.Now().Unix(),
  3451. Mtime: time.Now().Unix(),
  3452. Status: 1,
  3453. RecordTime: startDate.Unix(),
  3454. OrgId: adminUserInfo.Org.Id,
  3455. GoodId: prescription.Bloodlines,
  3456. GoodTypeId: bloodlines,
  3457. }
  3458. service.AddSigleAutoReduceRecordInfo(details)
  3459. }
  3460. } else if err == nil { //记录存在,则将耗材使用数量加1
  3461. if outInfo.ID > 0 {
  3462. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3463. }
  3464. //插入病人耗材使用记录
  3465. details := &models.AutomaticReduceDetail{
  3466. WarehouseOutId: outInfo.ID,
  3467. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3468. PatientId: patientID,
  3469. Ctime: time.Now().Unix(),
  3470. Mtime: time.Now().Unix(),
  3471. Status: 1,
  3472. RecordTime: startDate.Unix(),
  3473. OrgId: adminUserInfo.Org.Id,
  3474. GoodId: prescription.Bloodlines,
  3475. GoodTypeId: bloodlines,
  3476. }
  3477. service.AddSigleAutoReduceRecordInfo(details)
  3478. }
  3479. }
  3480. if prescription.TubingHemodialysis > 0 {
  3481. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
  3482. if err == gorm.ErrRecordNotFound {
  3483. warehouseOutInfo := &models.WarehouseOutInfo{
  3484. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3485. WarehouseOutId: out.ID,
  3486. Status: 1,
  3487. Ctime: time.Now().Unix(),
  3488. Remark: "",
  3489. OrgId: adminUserInfo.Org.Id,
  3490. Type: 1,
  3491. Manufacturer: 0,
  3492. Dealer: 0,
  3493. IsSys: 1,
  3494. SysRecordTime: startDate.Unix(),
  3495. }
  3496. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  3497. warehouseOutInfo.Price = stockInInfo.Price
  3498. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  3499. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  3500. warehouseOutInfo.Count = 1
  3501. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3502. if err == nil {
  3503. details := &models.AutomaticReduceDetail{
  3504. WarehouseOutId: warehouseOutInfo.ID,
  3505. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3506. PatientId: patientID,
  3507. Ctime: time.Now().Unix(),
  3508. Mtime: time.Now().Unix(),
  3509. Status: 1,
  3510. RecordTime: startDate.Unix(),
  3511. OrgId: adminUserInfo.Org.Id,
  3512. GoodId: prescription.TubingHemodialysis,
  3513. GoodTypeId: tubingHemodialysis,
  3514. }
  3515. service.AddSigleAutoReduceRecordInfo(details)
  3516. }
  3517. } else if err == nil { //记录存在,则将耗材使用数量加1
  3518. if outInfo.ID > 0 {
  3519. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3520. }
  3521. //插入病人耗材使用记录
  3522. details := &models.AutomaticReduceDetail{
  3523. WarehouseOutId: outInfo.ID,
  3524. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3525. PatientId: patientID,
  3526. Ctime: time.Now().Unix(),
  3527. Mtime: time.Now().Unix(),
  3528. Status: 1,
  3529. RecordTime: startDate.Unix(),
  3530. OrgId: adminUserInfo.Org.Id,
  3531. GoodId: prescription.TubingHemodialysis,
  3532. GoodTypeId: tubingHemodialysis,
  3533. }
  3534. service.AddSigleAutoReduceRecordInfo(details)
  3535. }
  3536. }
  3537. if prescription.Package > 0 {
  3538. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
  3539. if err == gorm.ErrRecordNotFound {
  3540. warehouseOutInfo := &models.WarehouseOutInfo{
  3541. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3542. WarehouseOutId: out.ID,
  3543. Status: 1,
  3544. Ctime: time.Now().Unix(),
  3545. Remark: "",
  3546. OrgId: adminUserInfo.Org.Id,
  3547. Type: 1,
  3548. Manufacturer: 0,
  3549. Dealer: 0,
  3550. IsSys: 1,
  3551. SysRecordTime: startDate.Unix(),
  3552. }
  3553. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  3554. warehouseOutInfo.Price = stockInInfo.Price
  3555. warehouseOutInfo.GoodId = prescription.Package
  3556. warehouseOutInfo.GoodTypeId = safe_package
  3557. warehouseOutInfo.Count = 1
  3558. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3559. if err == nil {
  3560. details := &models.AutomaticReduceDetail{
  3561. WarehouseOutId: warehouseOutInfo.ID,
  3562. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3563. PatientId: patientID,
  3564. Ctime: time.Now().Unix(),
  3565. Mtime: time.Now().Unix(),
  3566. Status: 1,
  3567. RecordTime: startDate.Unix(),
  3568. OrgId: adminUserInfo.Org.Id,
  3569. GoodId: prescription.Package,
  3570. GoodTypeId: safe_package,
  3571. }
  3572. service.AddSigleAutoReduceRecordInfo(details)
  3573. }
  3574. } else if err == nil { //记录存在,则将耗材使用数量加1
  3575. if outInfo.ID > 0 {
  3576. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3577. }
  3578. //插入病人耗材使用记录
  3579. details := &models.AutomaticReduceDetail{
  3580. WarehouseOutId: outInfo.ID,
  3581. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3582. PatientId: patientID,
  3583. Ctime: time.Now().Unix(),
  3584. Mtime: time.Now().Unix(),
  3585. Status: 1,
  3586. RecordTime: startDate.Unix(),
  3587. OrgId: adminUserInfo.Org.Id,
  3588. GoodId: prescription.Package,
  3589. GoodTypeId: safe_package,
  3590. }
  3591. service.AddSigleAutoReduceRecordInfo(details)
  3592. }
  3593. }
  3594. if prescription.ALiquid > 0 {
  3595. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
  3596. if err == gorm.ErrRecordNotFound {
  3597. warehouseOutInfo := &models.WarehouseOutInfo{
  3598. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3599. WarehouseOutId: out.ID,
  3600. Status: 1,
  3601. Ctime: time.Now().Unix(),
  3602. Remark: "",
  3603. OrgId: adminUserInfo.Org.Id,
  3604. Type: 1,
  3605. Manufacturer: 0,
  3606. Dealer: 0,
  3607. IsSys: 1,
  3608. SysRecordTime: startDate.Unix(),
  3609. }
  3610. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3611. warehouseOutInfo.Price = stockInInfo.Price
  3612. warehouseOutInfo.GoodId = prescription.ALiquid
  3613. warehouseOutInfo.GoodTypeId = aliquid
  3614. warehouseOutInfo.Count = 1
  3615. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3616. if err == nil {
  3617. details := &models.AutomaticReduceDetail{
  3618. WarehouseOutId: warehouseOutInfo.ID,
  3619. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3620. PatientId: patientID,
  3621. Ctime: time.Now().Unix(),
  3622. Mtime: time.Now().Unix(),
  3623. Status: 1,
  3624. RecordTime: startDate.Unix(),
  3625. OrgId: adminUserInfo.Org.Id,
  3626. GoodId: prescription.ALiquid,
  3627. GoodTypeId: aliquid,
  3628. }
  3629. service.AddSigleAutoReduceRecordInfo(details)
  3630. }
  3631. } else if err == nil { //记录存在,则将耗材使用数量加1
  3632. if outInfo.ID > 0 {
  3633. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3634. }
  3635. //插入病人耗材使用记录
  3636. details := &models.AutomaticReduceDetail{
  3637. WarehouseOutId: outInfo.ID,
  3638. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3639. PatientId: patientID,
  3640. Ctime: time.Now().Unix(),
  3641. Mtime: time.Now().Unix(),
  3642. Status: 1,
  3643. RecordTime: startDate.Unix(),
  3644. OrgId: adminUserInfo.Org.Id,
  3645. GoodId: prescription.ALiquid,
  3646. GoodTypeId: aliquid,
  3647. }
  3648. service.AddSigleAutoReduceRecordInfo(details)
  3649. }
  3650. }
  3651. }
  3652. }
  3653. } else {
  3654. this.ErrorLog("上机失败,还没开处方")
  3655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  3656. return
  3657. }
  3658. }
  3659. if createErr != nil {
  3660. this.ErrorLog("上机失败:%v", createErr)
  3661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3662. return
  3663. }
  3664. this.ServeSuccessJSON(map[string]interface{}{
  3665. "dialysis_order": newdialysisRecord,
  3666. "monitor": record,
  3667. })
  3668. }
  3669. func (c *DialysisAPIController) PostSolution() {
  3670. id, _ := c.GetInt64("patient", 0)
  3671. recordDateStr := c.GetString("record_date")
  3672. if id <= 0 {
  3673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3674. return
  3675. }
  3676. adminUserInfo := c.GetMobileAdminUserInfo()
  3677. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3678. if patient.ID == 0 {
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3680. return
  3681. }
  3682. if len(recordDateStr) == 0 {
  3683. recordDateStr = time.Now().Format("2006-01-02")
  3684. }
  3685. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3686. if parseDateErr != nil {
  3687. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3689. return
  3690. }
  3691. mode_id, _ := c.GetInt64("mode_id", 0)
  3692. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3693. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3694. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3695. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3696. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3697. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3698. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3699. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3700. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3701. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3702. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3703. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3704. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3705. kalium, _ := c.GetFloat("kalium", 0)
  3706. sodium, _ := c.GetFloat("sodium", 0)
  3707. calcium, _ := c.GetFloat("calcium", 0)
  3708. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3709. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3710. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3711. glucose, _ := c.GetFloat("glucose", 0)
  3712. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3713. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3714. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3715. conductivity, _ := c.GetFloat("conductivity", 0)
  3716. remark := c.GetString("remark")
  3717. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3718. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3719. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3720. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3721. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3722. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3723. special_medicine_other := c.GetString("special_medicine_other")
  3724. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3725. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3726. blood_access, _ := c.GetInt64("blood_access", 0)
  3727. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3728. body_fluid_other := c.GetString("body_fluid_other")
  3729. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3730. niprocart, _ := c.GetInt64("niprocart", 0)
  3731. jms, _ := c.GetInt64("jms", 0)
  3732. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3733. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3734. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3735. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3736. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3737. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3738. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3739. injector, _ := c.GetInt64("injector", 0)
  3740. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3741. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3742. safe_package, _ := c.GetInt64("package", 0)
  3743. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3744. if mode_id > 0 {
  3745. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  3746. }
  3747. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3748. //
  3749. //if appRole.UserType == 2 || appRole.UserType == 1 {
  3750. // prescription_doctor = appRole.AdminUserId
  3751. //} else {
  3752. // prescription_doctor = 0
  3753. //}
  3754. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3755. //
  3756. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3757. // if appRole.UserType == 3 {
  3758. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3759. // if getPermissionErr != nil {
  3760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3761. // return
  3762. // } else if headNursePermission == nil {
  3763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3764. // return
  3765. // }
  3766. // }
  3767. //}
  3768. prescription := models.DialysisPrescription{
  3769. UserOrgId: adminUserInfo.Org.Id,
  3770. PatientId: id,
  3771. RecordDate: recordDate.Unix(),
  3772. ModeId: mode_id,
  3773. DialysisDuration: dialysis_duration,
  3774. Dialyzer: dialyzer,
  3775. PerfusionApparatus: perfusion_apparatus,
  3776. BloodFlowVolume: blood_flow_volume,
  3777. DewaterAmount: dewater_amount,
  3778. DisplaceLiqui: displace_liqui,
  3779. ReplacementWay: replacement_way,
  3780. Anticoagulant: anticoagulant,
  3781. AnticoagulantShouji: anticoagulant_shouji,
  3782. AnticoagulantWeichi: anticoagulant_weichi,
  3783. AnticoagulantZongliang: anticoagulant_zongliang,
  3784. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3785. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3786. Kalium: kalium,
  3787. Sodium: sodium,
  3788. Calcium: calcium,
  3789. Bicarbonate: bicarbonate,
  3790. Glucose: glucose,
  3791. // DryWeight: dry_weight,
  3792. DialysateFlow: dialysate_flow,
  3793. DialysateTemperature: dialysate_temperature,
  3794. Conductivity: conductivity,
  3795. Remark: remark,
  3796. PrescriptionDoctor: prescription_doctor,
  3797. Status: 1,
  3798. CreatedTime: time.Now().Unix(),
  3799. UpdatedTime: time.Now().Unix(),
  3800. DialysisDurationMinute: dialysisDurationMinute,
  3801. DialysisDurationHour: dialysisDurationHour,
  3802. TargetUltrafiltration: targetUltrafiltration,
  3803. DialysateFormulation: dialysateFormulation,
  3804. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3805. BodyFluid: body_fluid,
  3806. SpecialMedicine: special_medicine,
  3807. SpecialMedicineOther: special_medicine_other,
  3808. DisplaceLiquiPart: displace_liqui_part,
  3809. DisplaceLiquiValue: displace_liqui_value,
  3810. BloodAccess: blood_access,
  3811. Ultrafiltration: ultrafiltration,
  3812. BodyFluidOther: body_fluid_other,
  3813. ReplacementTotal: replacement_total,
  3814. Niprocart: niprocart,
  3815. Jms: jms,
  3816. FistulaNeedleSet: fistula_needle_set,
  3817. FistulaNeedleSet16: fistula_needle_set_16,
  3818. Hemoperfusion: hemoperfusion,
  3819. DialyserSterilised: dialyser_sterilised,
  3820. Filtryzer: filtryzer,
  3821. TargetKtv: target_ktv,
  3822. Dialyzers: dialyzers,
  3823. Injector: injector,
  3824. Bloodlines: bloodlines,
  3825. TubingHemodialysis: tubing_hemodialysis,
  3826. Package: safe_package,
  3827. ALiquid: a_liquid,
  3828. }
  3829. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3830. if dialysisPrescription.ID == 0 { //新增
  3831. prescription.Creater = adminUserInfo.AdminUser.Id
  3832. } else { //修改
  3833. prescription.Creater = adminUserInfo.AdminUser.Id
  3834. //if/**/
  3835. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3836. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3837. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3838. // if getPermissionErr != nil {
  3839. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3840. // return
  3841. // } else if headNursePermission == nil {
  3842. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3843. // return
  3844. // }
  3845. //}
  3846. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  3847. if record.IsOpen == 1 {
  3848. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  3849. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  3850. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  3851. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  3852. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  3853. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  3854. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  3855. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  3856. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  3857. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  3858. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  3859. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  3860. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  3861. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  3862. if err == nil {
  3863. if order.ID > 0 {
  3864. if dialysisPrescription.Niprocart != niprocart {
  3865. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3866. //1.用上机透析日期查出当天的订单
  3867. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3868. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3869. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3870. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3871. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3872. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3873. warehouseOutInfo := &models.WarehouseOutInfo{
  3874. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3875. WarehouseOutId: out.ID,
  3876. Count: 1,
  3877. Status: 1,
  3878. Ctime: time.Now().Unix(),
  3879. Remark: "",
  3880. OrgId: adminUserInfo.Org.Id,
  3881. Type: 1,
  3882. Manufacturer: 0,
  3883. Dealer: 0,
  3884. IsSys: 1,
  3885. SysRecordTime: order.StartTime,
  3886. }
  3887. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  3888. warehouseOutInfo.Price = stockInInfo.Price
  3889. warehouseOutInfo.GoodId = niprocart
  3890. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  3891. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3892. if err == nil {
  3893. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3894. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3895. if err == gorm.ErrRecordNotFound {
  3896. details := &models.AutomaticReduceDetail{
  3897. WarehouseOutId: warehouseOutInfo.ID,
  3898. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3899. PatientId: id,
  3900. Ctime: time.Now().Unix(),
  3901. Mtime: time.Now().Unix(),
  3902. Status: 1,
  3903. RecordTime: order.StartTime,
  3904. OrgId: adminUserInfo.Org.Id,
  3905. GoodId: niprocart,
  3906. GoodTypeId: niprocart_good_type_id,
  3907. }
  3908. service.AddSigleAutoReduceRecordInfo(details)
  3909. } else if err == nil {
  3910. if user.ID > 0 {
  3911. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  3912. }
  3913. }
  3914. }
  3915. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  3916. if newOut.ID > 0 {
  3917. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  3918. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3919. if err == gorm.ErrRecordNotFound {
  3920. details := &models.AutomaticReduceDetail{
  3921. WarehouseOutId: newOut.ID,
  3922. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3923. PatientId: id,
  3924. Ctime: time.Now().Unix(),
  3925. Mtime: time.Now().Unix(),
  3926. Status: 1,
  3927. RecordTime: order.StartTime,
  3928. OrgId: adminUserInfo.Org.Id,
  3929. GoodId: niprocart,
  3930. GoodTypeId: niprocart_good_type_id,
  3931. }
  3932. service.AddSigleAutoReduceRecordInfo(details)
  3933. } else if err == nil {
  3934. if user.ID > 0 {
  3935. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  3936. }
  3937. }
  3938. }
  3939. }
  3940. }
  3941. if dialysisPrescription.Jms != jms {
  3942. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3943. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3944. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3945. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3946. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  3947. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3948. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3949. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3950. warehouseOutInfo := &models.WarehouseOutInfo{
  3951. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3952. WarehouseOutId: out.ID,
  3953. Count: 1,
  3954. Status: 1,
  3955. Ctime: time.Now().Unix(),
  3956. Remark: "",
  3957. OrgId: adminUserInfo.Org.Id,
  3958. Type: 1,
  3959. Manufacturer: 0,
  3960. Dealer: 0,
  3961. IsSys: 1,
  3962. SysRecordTime: order.StartTime,
  3963. }
  3964. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  3965. warehouseOutInfo.Price = stockInInfo.Price
  3966. warehouseOutInfo.GoodId = jms
  3967. warehouseOutInfo.GoodTypeId = jms_good_type_id
  3968. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3969. if err == nil {
  3970. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3971. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3972. if err == gorm.ErrRecordNotFound {
  3973. details := &models.AutomaticReduceDetail{
  3974. WarehouseOutId: warehouseOutInfo.ID,
  3975. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3976. PatientId: id,
  3977. Ctime: time.Now().Unix(),
  3978. Mtime: time.Now().Unix(),
  3979. Status: 1,
  3980. RecordTime: order.StartTime,
  3981. OrgId: adminUserInfo.Org.Id,
  3982. GoodId: jms,
  3983. GoodTypeId: jms_good_type_id,
  3984. }
  3985. service.AddSigleAutoReduceRecordInfo(details)
  3986. } else if err == nil {
  3987. if user.ID > 0 {
  3988. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  3989. }
  3990. }
  3991. }
  3992. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  3993. if newOut.ID > 0 {
  3994. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  3995. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3996. if err == gorm.ErrRecordNotFound {
  3997. details := &models.AutomaticReduceDetail{
  3998. WarehouseOutId: newOut.ID,
  3999. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4000. PatientId: id,
  4001. Ctime: time.Now().Unix(),
  4002. Mtime: time.Now().Unix(),
  4003. Status: 1,
  4004. RecordTime: order.StartTime,
  4005. OrgId: adminUserInfo.Org.Id,
  4006. GoodId: jms,
  4007. GoodTypeId: jms_good_type_id,
  4008. }
  4009. service.AddSigleAutoReduceRecordInfo(details)
  4010. } else if err == nil {
  4011. if user.ID > 0 {
  4012. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  4013. }
  4014. }
  4015. }
  4016. }
  4017. }
  4018. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  4019. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4020. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4021. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4022. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4023. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  4024. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4025. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4026. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4027. warehouseOutInfo := &models.WarehouseOutInfo{
  4028. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4029. WarehouseOutId: out.ID,
  4030. Count: 1,
  4031. Status: 1,
  4032. Ctime: time.Now().Unix(),
  4033. Remark: "",
  4034. OrgId: adminUserInfo.Org.Id,
  4035. Type: 1,
  4036. Manufacturer: 0,
  4037. Dealer: 0,
  4038. IsSys: 1,
  4039. SysRecordTime: order.StartTime,
  4040. }
  4041. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  4042. warehouseOutInfo.Price = stockInInfo.Price
  4043. warehouseOutInfo.GoodId = fistula_needle_set
  4044. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  4045. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4046. if err == nil {
  4047. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4048. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4049. if err == gorm.ErrRecordNotFound {
  4050. details := &models.AutomaticReduceDetail{
  4051. WarehouseOutId: warehouseOutInfo.ID,
  4052. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4053. PatientId: id,
  4054. Ctime: time.Now().Unix(),
  4055. Mtime: time.Now().Unix(),
  4056. Status: 1,
  4057. RecordTime: order.StartTime,
  4058. OrgId: adminUserInfo.Org.Id,
  4059. GoodId: fistula_needle_set,
  4060. GoodTypeId: fistula_needle_set_good_type_id,
  4061. }
  4062. service.AddSigleAutoReduceRecordInfo(details)
  4063. } else if err == nil {
  4064. if user.ID > 0 {
  4065. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4066. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4067. }
  4068. }
  4069. }
  4070. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4071. if newOut.ID > 0 {
  4072. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4073. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4074. if err == gorm.ErrRecordNotFound {
  4075. details := &models.AutomaticReduceDetail{
  4076. WarehouseOutId: newOut.ID,
  4077. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4078. PatientId: id,
  4079. Ctime: time.Now().Unix(),
  4080. Mtime: time.Now().Unix(),
  4081. Status: 1,
  4082. RecordTime: order.StartTime,
  4083. OrgId: adminUserInfo.Org.Id,
  4084. GoodId: fistula_needle_set,
  4085. GoodTypeId: fistula_needle_set_good_type_id,
  4086. }
  4087. service.AddSigleAutoReduceRecordInfo(details)
  4088. } else if err == nil {
  4089. if user.ID > 0 {
  4090. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4091. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  4092. }
  4093. }
  4094. }
  4095. }
  4096. }
  4097. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  4098. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4099. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4100. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4101. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4102. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4103. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4104. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4105. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4106. warehouseOutInfo := &models.WarehouseOutInfo{
  4107. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4108. WarehouseOutId: out.ID,
  4109. Count: 1,
  4110. Status: 1,
  4111. Ctime: time.Now().Unix(),
  4112. Remark: "",
  4113. OrgId: adminUserInfo.Org.Id,
  4114. Type: 1,
  4115. Manufacturer: 0,
  4116. Dealer: 0,
  4117. IsSys: 1,
  4118. SysRecordTime: order.StartTime,
  4119. }
  4120. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  4121. warehouseOutInfo.Price = stockInInfo.Price
  4122. warehouseOutInfo.GoodId = fistula_needle_set_16
  4123. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  4124. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4125. if err == nil {
  4126. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4127. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4128. if err == gorm.ErrRecordNotFound {
  4129. details := &models.AutomaticReduceDetail{
  4130. WarehouseOutId: warehouseOutInfo.ID,
  4131. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4132. PatientId: id,
  4133. Ctime: time.Now().Unix(),
  4134. Mtime: time.Now().Unix(),
  4135. Status: 1,
  4136. RecordTime: order.StartTime,
  4137. OrgId: adminUserInfo.Org.Id,
  4138. GoodId: fistula_needle_set_16,
  4139. GoodTypeId: fistula_needle_set_16_good_type_id,
  4140. }
  4141. service.AddSigleAutoReduceRecordInfo(details)
  4142. } else if err == nil {
  4143. if user.ID > 0 {
  4144. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4145. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4146. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  4147. }
  4148. }
  4149. }
  4150. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4151. if newOut.ID > 0 {
  4152. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4153. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4154. if err == gorm.ErrRecordNotFound {
  4155. details := &models.AutomaticReduceDetail{
  4156. WarehouseOutId: newOut.ID,
  4157. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4158. PatientId: id,
  4159. Ctime: time.Now().Unix(),
  4160. Mtime: time.Now().Unix(),
  4161. Status: 1,
  4162. RecordTime: order.StartTime,
  4163. OrgId: adminUserInfo.Org.Id,
  4164. GoodId: fistula_needle_set_good_type_id,
  4165. GoodTypeId: fistula_needle_set_16_good_type_id,
  4166. }
  4167. service.AddSigleAutoReduceRecordInfo(details)
  4168. } else if err == nil {
  4169. if user.ID > 0 {
  4170. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  4171. }
  4172. }
  4173. }
  4174. }
  4175. }
  4176. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  4177. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4178. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4179. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4180. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4181. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  4182. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4183. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4184. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4185. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4186. warehouseOutInfo := &models.WarehouseOutInfo{
  4187. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4188. WarehouseOutId: out.ID,
  4189. Count: 1,
  4190. Status: 1,
  4191. Ctime: time.Now().Unix(),
  4192. Remark: "",
  4193. OrgId: adminUserInfo.Org.Id,
  4194. Type: 1,
  4195. Manufacturer: 0,
  4196. Dealer: 0,
  4197. IsSys: 1,
  4198. SysRecordTime: order.StartTime,
  4199. }
  4200. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  4201. warehouseOutInfo.Price = stockInInfo.Price
  4202. warehouseOutInfo.GoodId = hemoperfusion
  4203. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  4204. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4205. if err == nil {
  4206. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4207. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4208. if err == gorm.ErrRecordNotFound {
  4209. details := &models.AutomaticReduceDetail{
  4210. WarehouseOutId: warehouseOutInfo.ID,
  4211. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4212. PatientId: id,
  4213. Ctime: time.Now().Unix(),
  4214. Mtime: time.Now().Unix(),
  4215. Status: 1,
  4216. RecordTime: order.StartTime,
  4217. OrgId: adminUserInfo.Org.Id,
  4218. GoodId: hemoperfusion,
  4219. GoodTypeId: hemoperfusion_good_type_id,
  4220. }
  4221. service.AddSigleAutoReduceRecordInfo(details)
  4222. } else if err == nil {
  4223. if user.ID > 0 {
  4224. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4225. }
  4226. }
  4227. }
  4228. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4229. if newOut.ID > 0 {
  4230. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4231. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4232. if err == gorm.ErrRecordNotFound {
  4233. details := &models.AutomaticReduceDetail{
  4234. WarehouseOutId: newOut.ID,
  4235. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4236. PatientId: id,
  4237. Ctime: time.Now().Unix(),
  4238. Mtime: time.Now().Unix(),
  4239. Status: 1,
  4240. RecordTime: order.StartTime,
  4241. OrgId: adminUserInfo.Org.Id,
  4242. GoodId: hemoperfusion,
  4243. GoodTypeId: hemoperfusion_good_type_id,
  4244. }
  4245. service.AddSigleAutoReduceRecordInfo(details)
  4246. } else if err == nil {
  4247. if user.ID > 0 {
  4248. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  4249. }
  4250. }
  4251. }
  4252. }
  4253. }
  4254. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  4255. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4256. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4257. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4258. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  4259. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4260. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4261. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4262. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4263. warehouseOutInfo := &models.WarehouseOutInfo{
  4264. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4265. WarehouseOutId: out.WarehouseOutId,
  4266. Count: 1,
  4267. Status: 1,
  4268. Ctime: time.Now().Unix(),
  4269. Remark: "",
  4270. OrgId: adminUserInfo.Org.Id,
  4271. Type: 1,
  4272. Manufacturer: 0,
  4273. Dealer: 0,
  4274. IsSys: 1,
  4275. SysRecordTime: order.StartTime,
  4276. }
  4277. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  4278. warehouseOutInfo.Price = stockInInfo.Price
  4279. warehouseOutInfo.GoodId = dialyser_sterilised
  4280. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  4281. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4282. if err == nil {
  4283. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4284. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4285. if err == gorm.ErrRecordNotFound {
  4286. details := &models.AutomaticReduceDetail{
  4287. WarehouseOutId: warehouseOutInfo.ID,
  4288. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4289. PatientId: id,
  4290. Ctime: time.Now().Unix(),
  4291. Mtime: time.Now().Unix(),
  4292. Status: 1,
  4293. RecordTime: order.StartTime,
  4294. OrgId: adminUserInfo.Org.Id,
  4295. GoodId: dialyser_sterilised,
  4296. GoodTypeId: dialyser_sterilised_good_type_id,
  4297. }
  4298. service.AddSigleAutoReduceRecordInfo(details)
  4299. } else if err == nil {
  4300. if user.ID > 0 {
  4301. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4302. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  4303. }
  4304. }
  4305. }
  4306. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4307. if newOut.ID > 0 {
  4308. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4309. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4310. if err == gorm.ErrRecordNotFound {
  4311. details := &models.AutomaticReduceDetail{
  4312. WarehouseOutId: newOut.ID,
  4313. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4314. PatientId: id,
  4315. Ctime: time.Now().Unix(),
  4316. Mtime: time.Now().Unix(),
  4317. Status: 1,
  4318. RecordTime: order.StartTime,
  4319. OrgId: adminUserInfo.Org.Id,
  4320. GoodId: dialyser_sterilised,
  4321. GoodTypeId: dialyser_sterilised_good_type_id,
  4322. }
  4323. service.AddSigleAutoReduceRecordInfo(details)
  4324. } else if err == nil {
  4325. if user.ID > 0 {
  4326. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  4327. }
  4328. }
  4329. }
  4330. }
  4331. }
  4332. if dialysisPrescription.Filtryzer != filtryzer {
  4333. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4334. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4335. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4336. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4337. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  4338. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4339. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4340. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4341. warehouseOutInfo := &models.WarehouseOutInfo{
  4342. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4343. WarehouseOutId: out.ID,
  4344. Count: 1,
  4345. Status: 1,
  4346. Ctime: time.Now().Unix(),
  4347. Remark: "",
  4348. OrgId: adminUserInfo.Org.Id,
  4349. Type: 1,
  4350. Manufacturer: 0,
  4351. Dealer: 0,
  4352. IsSys: 1,
  4353. SysRecordTime: order.StartTime,
  4354. }
  4355. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  4356. warehouseOutInfo.Price = stockInInfo.Price
  4357. warehouseOutInfo.GoodId = filtryzer
  4358. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  4359. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4360. if err == nil {
  4361. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4362. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4363. if err == gorm.ErrRecordNotFound {
  4364. details := &models.AutomaticReduceDetail{
  4365. WarehouseOutId: warehouseOutInfo.ID,
  4366. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4367. PatientId: id,
  4368. Ctime: time.Now().Unix(),
  4369. Mtime: time.Now().Unix(),
  4370. Status: 1,
  4371. RecordTime: order.StartTime,
  4372. OrgId: adminUserInfo.Org.Id,
  4373. GoodId: filtryzer,
  4374. GoodTypeId: filtryzer_good_type_id,
  4375. }
  4376. service.AddSigleAutoReduceRecordInfo(details)
  4377. } else if err == nil {
  4378. if user.ID > 0 {
  4379. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  4380. }
  4381. }
  4382. }
  4383. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4384. if newOut.ID > 0 {
  4385. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4386. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4387. if err == gorm.ErrRecordNotFound {
  4388. details := &models.AutomaticReduceDetail{
  4389. WarehouseOutId: newOut.ID,
  4390. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4391. PatientId: id,
  4392. Ctime: time.Now().Unix(),
  4393. Mtime: time.Now().Unix(),
  4394. Status: 1,
  4395. RecordTime: order.StartTime,
  4396. OrgId: adminUserInfo.Org.Id,
  4397. GoodId: filtryzer,
  4398. GoodTypeId: filtryzer_good_type_id,
  4399. }
  4400. service.AddSigleAutoReduceRecordInfo(details)
  4401. } else if err == nil {
  4402. if user.ID > 0 {
  4403. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  4404. }
  4405. }
  4406. }
  4407. }
  4408. }
  4409. if dialysisPrescription.Dialyzers != dialyzers {
  4410. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4411. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4412. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4413. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4414. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4415. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4416. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4417. warehouseOutInfo := &models.WarehouseOutInfo{
  4418. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4419. WarehouseOutId: out.ID,
  4420. Count: 1,
  4421. Status: 1,
  4422. Ctime: time.Now().Unix(),
  4423. Remark: "",
  4424. OrgId: adminUserInfo.Org.Id,
  4425. Type: 1,
  4426. Manufacturer: 0,
  4427. Dealer: 0,
  4428. IsSys: 1,
  4429. SysRecordTime: order.StartTime,
  4430. }
  4431. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  4432. warehouseOutInfo.Price = stockInInfo.Price
  4433. warehouseOutInfo.GoodId = dialyzers
  4434. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  4435. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4436. if err == nil {
  4437. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4438. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4439. if err == gorm.ErrRecordNotFound {
  4440. details := &models.AutomaticReduceDetail{
  4441. WarehouseOutId: warehouseOutInfo.ID,
  4442. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4443. PatientId: id,
  4444. Ctime: time.Now().Unix(),
  4445. Mtime: time.Now().Unix(),
  4446. Status: 1,
  4447. RecordTime: order.StartTime,
  4448. OrgId: adminUserInfo.Org.Id,
  4449. GoodId: dialyzers,
  4450. GoodTypeId: dialyzers_good_type_id,
  4451. }
  4452. service.AddSigleAutoReduceRecordInfo(details)
  4453. } else if err == nil {
  4454. if user.ID > 0 {
  4455. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  4456. }
  4457. }
  4458. }
  4459. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4460. if newOut.ID > 0 {
  4461. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4462. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4463. if err == gorm.ErrRecordNotFound {
  4464. details := &models.AutomaticReduceDetail{
  4465. WarehouseOutId: newOut.ID,
  4466. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4467. PatientId: id,
  4468. Ctime: time.Now().Unix(),
  4469. Mtime: time.Now().Unix(),
  4470. Status: 1,
  4471. RecordTime: order.StartTime,
  4472. OrgId: adminUserInfo.Org.Id,
  4473. GoodId: dialyzers,
  4474. GoodTypeId: dialyzers_good_type_id,
  4475. }
  4476. service.AddSigleAutoReduceRecordInfo(details)
  4477. } else if err == nil {
  4478. if user.ID > 0 {
  4479. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  4480. }
  4481. }
  4482. }
  4483. }
  4484. }
  4485. if dialysisPrescription.Injector != injector {
  4486. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4487. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4488. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4489. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4490. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4491. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4492. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4493. warehouseOutInfo := &models.WarehouseOutInfo{
  4494. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4495. WarehouseOutId: out.ID,
  4496. Count: 1,
  4497. Status: 1,
  4498. Ctime: time.Now().Unix(),
  4499. Remark: "",
  4500. OrgId: adminUserInfo.Org.Id,
  4501. Type: 1,
  4502. Manufacturer: 0,
  4503. Dealer: 0,
  4504. IsSys: 1,
  4505. SysRecordTime: order.StartTime,
  4506. }
  4507. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  4508. warehouseOutInfo.Price = stockInInfo.Price
  4509. warehouseOutInfo.GoodId = injector
  4510. warehouseOutInfo.GoodTypeId = injector_good_type_id
  4511. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4512. if err == nil {
  4513. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4514. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4515. if err == gorm.ErrRecordNotFound {
  4516. details := &models.AutomaticReduceDetail{
  4517. WarehouseOutId: warehouseOutInfo.ID,
  4518. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4519. PatientId: id,
  4520. Ctime: time.Now().Unix(),
  4521. Mtime: time.Now().Unix(),
  4522. Status: 1,
  4523. RecordTime: order.StartTime,
  4524. OrgId: adminUserInfo.Org.Id,
  4525. GoodId: injector,
  4526. GoodTypeId: injector_good_type_id,
  4527. }
  4528. service.AddSigleAutoReduceRecordInfo(details)
  4529. } else if err == nil {
  4530. if user.ID > 0 {
  4531. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  4532. }
  4533. }
  4534. }
  4535. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4536. if newOut.ID > 0 {
  4537. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4538. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4539. if err == gorm.ErrRecordNotFound {
  4540. details := &models.AutomaticReduceDetail{
  4541. WarehouseOutId: newOut.ID,
  4542. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4543. PatientId: id,
  4544. Ctime: time.Now().Unix(),
  4545. Mtime: time.Now().Unix(),
  4546. Status: 1,
  4547. RecordTime: order.StartTime,
  4548. OrgId: adminUserInfo.Org.Id,
  4549. GoodId: injector,
  4550. GoodTypeId: injector_good_type_id,
  4551. }
  4552. service.AddSigleAutoReduceRecordInfo(details)
  4553. } else if err == nil {
  4554. if user.ID > 0 {
  4555. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  4556. }
  4557. }
  4558. }
  4559. }
  4560. }
  4561. if dialysisPrescription.Bloodlines != bloodlines {
  4562. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4563. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4564. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4565. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4566. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4567. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4568. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4569. warehouseOutInfo := &models.WarehouseOutInfo{
  4570. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4571. WarehouseOutId: out.ID,
  4572. Count: 1,
  4573. Status: 1,
  4574. Ctime: time.Now().Unix(),
  4575. Remark: "",
  4576. OrgId: adminUserInfo.Org.Id,
  4577. Type: 1,
  4578. Manufacturer: 0,
  4579. Dealer: 0,
  4580. IsSys: 1,
  4581. SysRecordTime: order.StartTime,
  4582. }
  4583. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  4584. warehouseOutInfo.Price = stockInInfo.Price
  4585. warehouseOutInfo.GoodId = bloodlines
  4586. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  4587. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4588. if err == nil {
  4589. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4590. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4591. if err == gorm.ErrRecordNotFound {
  4592. details := &models.AutomaticReduceDetail{
  4593. WarehouseOutId: warehouseOutInfo.ID,
  4594. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4595. PatientId: id,
  4596. Ctime: time.Now().Unix(),
  4597. Mtime: time.Now().Unix(),
  4598. Status: 1,
  4599. RecordTime: order.StartTime,
  4600. OrgId: adminUserInfo.Org.Id,
  4601. GoodId: bloodlines,
  4602. GoodTypeId: bloodlines_good_type_id,
  4603. }
  4604. service.AddSigleAutoReduceRecordInfo(details)
  4605. } else if err == nil {
  4606. if user.ID > 0 {
  4607. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  4608. }
  4609. }
  4610. }
  4611. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4612. if newOut.ID > 0 {
  4613. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4614. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4615. if err == gorm.ErrRecordNotFound {
  4616. details := &models.AutomaticReduceDetail{
  4617. WarehouseOutId: newOut.ID,
  4618. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4619. PatientId: id,
  4620. Ctime: time.Now().Unix(),
  4621. Mtime: time.Now().Unix(),
  4622. Status: 1,
  4623. RecordTime: order.StartTime,
  4624. OrgId: adminUserInfo.Org.Id,
  4625. GoodId: bloodlines,
  4626. GoodTypeId: bloodlines_good_type_id,
  4627. }
  4628. service.AddSigleAutoReduceRecordInfo(details)
  4629. } else if err == nil {
  4630. if user.ID > 0 {
  4631. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  4632. }
  4633. }
  4634. }
  4635. }
  4636. }
  4637. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  4638. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4639. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4640. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4641. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4642. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4643. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4644. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4645. warehouseOutInfo := &models.WarehouseOutInfo{
  4646. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4647. WarehouseOutId: out.ID,
  4648. Count: 1,
  4649. Status: 1,
  4650. Ctime: time.Now().Unix(),
  4651. Remark: "",
  4652. OrgId: adminUserInfo.Org.Id,
  4653. Type: 1,
  4654. Manufacturer: 0,
  4655. Dealer: 0,
  4656. IsSys: 1,
  4657. SysRecordTime: order.StartTime,
  4658. }
  4659. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  4660. warehouseOutInfo.Price = stockInInfo.Price
  4661. warehouseOutInfo.GoodId = tubing_hemodialysis
  4662. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  4663. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4664. if err == nil {
  4665. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4666. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4667. if err == gorm.ErrRecordNotFound {
  4668. details := &models.AutomaticReduceDetail{
  4669. WarehouseOutId: warehouseOutInfo.ID,
  4670. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4671. PatientId: id,
  4672. Ctime: time.Now().Unix(),
  4673. Mtime: time.Now().Unix(),
  4674. Status: 1,
  4675. RecordTime: order.StartTime,
  4676. OrgId: adminUserInfo.Org.Id,
  4677. GoodId: tubing_hemodialysis,
  4678. GoodTypeId: tubingHemodialysis_good_type_id,
  4679. }
  4680. service.AddSigleAutoReduceRecordInfo(details)
  4681. } else if err == nil {
  4682. if user.ID > 0 {
  4683. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  4684. }
  4685. }
  4686. }
  4687. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4688. if newOut.ID > 0 {
  4689. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4690. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4691. if err == gorm.ErrRecordNotFound {
  4692. details := &models.AutomaticReduceDetail{
  4693. WarehouseOutId: newOut.ID,
  4694. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4695. PatientId: id,
  4696. Ctime: time.Now().Unix(),
  4697. Mtime: time.Now().Unix(),
  4698. Status: 1,
  4699. RecordTime: order.StartTime,
  4700. OrgId: adminUserInfo.Org.Id,
  4701. GoodId: tubing_hemodialysis,
  4702. GoodTypeId: tubingHemodialysis_good_type_id,
  4703. }
  4704. service.AddSigleAutoReduceRecordInfo(details)
  4705. } else if err == nil {
  4706. if user.ID > 0 {
  4707. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  4708. }
  4709. }
  4710. }
  4711. }
  4712. }
  4713. if dialysisPrescription.Package != safe_package {
  4714. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4715. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4716. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4717. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4718. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4719. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4720. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4721. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4722. warehouseOutInfo := &models.WarehouseOutInfo{
  4723. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4724. WarehouseOutId: out.ID,
  4725. Count: 1,
  4726. Status: 1,
  4727. Ctime: time.Now().Unix(),
  4728. Remark: "",
  4729. OrgId: adminUserInfo.Org.Id,
  4730. Type: 1,
  4731. Manufacturer: 0,
  4732. Dealer: 0,
  4733. IsSys: 1,
  4734. SysRecordTime: order.StartTime,
  4735. }
  4736. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  4737. warehouseOutInfo.Price = stockInInfo.Price
  4738. warehouseOutInfo.GoodId = safe_package
  4739. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  4740. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4741. if err == nil {
  4742. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4743. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4744. if err == gorm.ErrRecordNotFound {
  4745. details := &models.AutomaticReduceDetail{
  4746. WarehouseOutId: warehouseOutInfo.ID,
  4747. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4748. PatientId: id,
  4749. Ctime: time.Now().Unix(),
  4750. Mtime: time.Now().Unix(),
  4751. Status: 1,
  4752. RecordTime: order.StartTime,
  4753. OrgId: adminUserInfo.Org.Id,
  4754. GoodId: safe_package,
  4755. GoodTypeId: safe_package_good_type_id,
  4756. }
  4757. service.AddSigleAutoReduceRecordInfo(details)
  4758. } else if err == nil {
  4759. if user.ID > 0 {
  4760. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  4761. }
  4762. }
  4763. }
  4764. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4765. if newOut.ID > 0 {
  4766. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4767. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4768. if err == gorm.ErrRecordNotFound {
  4769. details := &models.AutomaticReduceDetail{
  4770. WarehouseOutId: newOut.ID,
  4771. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4772. PatientId: id,
  4773. Ctime: time.Now().Unix(),
  4774. Mtime: time.Now().Unix(),
  4775. Status: 1,
  4776. RecordTime: order.StartTime,
  4777. OrgId: adminUserInfo.Org.Id,
  4778. GoodId: safe_package,
  4779. GoodTypeId: safe_package_good_type_id,
  4780. }
  4781. service.AddSigleAutoReduceRecordInfo(details)
  4782. } else if err == nil {
  4783. if user.ID > 0 {
  4784. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  4785. }
  4786. }
  4787. }
  4788. }
  4789. }
  4790. if dialysisPrescription.ALiquid != a_liquid {
  4791. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4792. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4793. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4794. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4795. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4796. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4797. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4798. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4799. warehouseOutInfo := &models.WarehouseOutInfo{
  4800. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4801. WarehouseOutId: out.ID,
  4802. Count: 1,
  4803. Status: 1,
  4804. Ctime: time.Now().Unix(),
  4805. Remark: "",
  4806. OrgId: adminUserInfo.Org.Id,
  4807. Type: 1,
  4808. Manufacturer: 0,
  4809. Dealer: 0,
  4810. IsSys: 1,
  4811. SysRecordTime: order.StartTime,
  4812. }
  4813. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  4814. warehouseOutInfo.Price = stockInInfo.Price
  4815. warehouseOutInfo.GoodId = a_liquid
  4816. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  4817. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4818. if err == nil {
  4819. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4820. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4821. if err == gorm.ErrRecordNotFound {
  4822. details := &models.AutomaticReduceDetail{
  4823. WarehouseOutId: warehouseOutInfo.ID,
  4824. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4825. PatientId: id,
  4826. Ctime: time.Now().Unix(),
  4827. Mtime: time.Now().Unix(),
  4828. Status: 1,
  4829. RecordTime: order.StartTime,
  4830. OrgId: adminUserInfo.Org.Id,
  4831. GoodId: a_liquid,
  4832. GoodTypeId: aliquid_good_type_id,
  4833. }
  4834. service.AddSigleAutoReduceRecordInfo(details)
  4835. } else if err == nil {
  4836. if user.ID > 0 {
  4837. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  4838. }
  4839. }
  4840. }
  4841. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4842. if newOut.ID > 0 {
  4843. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4844. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4845. if err == gorm.ErrRecordNotFound {
  4846. details := &models.AutomaticReduceDetail{
  4847. WarehouseOutId: newOut.ID,
  4848. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4849. PatientId: id,
  4850. Ctime: time.Now().Unix(),
  4851. Mtime: time.Now().Unix(),
  4852. Status: 1,
  4853. RecordTime: order.StartTime,
  4854. OrgId: adminUserInfo.Org.Id,
  4855. GoodId: a_liquid,
  4856. GoodTypeId: aliquid_good_type_id,
  4857. }
  4858. service.AddSigleAutoReduceRecordInfo(details)
  4859. } else if err == nil {
  4860. if user.ID > 0 {
  4861. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  4862. }
  4863. }
  4864. }
  4865. }
  4866. }
  4867. }
  4868. }
  4869. }
  4870. //prescription.Creater = dialysisPrescription.Creater
  4871. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4872. prescription.Modifier = adminUserInfo.AdminUser.Id
  4873. prescription.ID = dialysisPrescription.ID
  4874. }
  4875. solution := models.DialysisSolution{
  4876. RegistrarsId: adminUserInfo.AdminUser.Id,
  4877. UserOrgId: adminUserInfo.Org.Id,
  4878. Doctor: prescription_doctor,
  4879. PatientId: id,
  4880. ModeId: mode_id,
  4881. DialysisDuration: dialysis_duration,
  4882. PerfusionApparatus: perfusion_apparatus,
  4883. BloodFlowVolume: blood_flow_volume,
  4884. Dewater: dewater_amount,
  4885. DisplaceLiqui: displace_liqui,
  4886. ReplacementWay: replacement_way,
  4887. Anticoagulant: anticoagulant,
  4888. AnticoagulantShouji: anticoagulant_shouji,
  4889. AnticoagulantWeichi: anticoagulant_weichi,
  4890. AnticoagulantZongliang: anticoagulant_zongliang,
  4891. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4892. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4893. Kalium: kalium,
  4894. Sodium: sodium,
  4895. Calcium: calcium,
  4896. Bicarbonate: bicarbonate,
  4897. Glucose: glucose,
  4898. // DryWeight: dry_weight,
  4899. DialysateFlow: dialysate_flow,
  4900. DialysateTemperature: dialysate_temperature,
  4901. Conductivity: conductivity,
  4902. Remark: remark,
  4903. Status: 1,
  4904. CreatedTime: time.Now().Unix(),
  4905. UpdatedTime: time.Now().Unix(),
  4906. DialysisDurationMinute: dialysisDurationMinute,
  4907. DialysisDurationHour: dialysisDurationHour,
  4908. TargetUltrafiltration: targetUltrafiltration,
  4909. DialysateFormulation: dialysateFormulation,
  4910. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4911. BodyFluid: body_fluid,
  4912. SpecialMedicine: special_medicine,
  4913. SpecialMedicineOther: special_medicine_other,
  4914. DisplaceLiquiPart: displace_liqui_part,
  4915. DisplaceLiquiValue: displace_liqui_value,
  4916. BloodAccess: blood_access,
  4917. Ultrafiltration: ultrafiltration,
  4918. BodyFluidOther: body_fluid_other,
  4919. ReplacementTotal: replacement_total,
  4920. TargetKtv: target_ktv,
  4921. }
  4922. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4923. c.ServeSuccessJSON(map[string]interface{}{
  4924. "solution": &solution,
  4925. "prescription": &prescription,
  4926. })
  4927. }
  4928. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4929. patient, _ := c.GetInt64("patient", 0)
  4930. adminUserInfo := c.GetMobileAdminUserInfo()
  4931. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4932. c.ServeSuccessJSON(map[string]interface{}{
  4933. "receiveTreatmentAsses": receiveTreatmentAsses,
  4934. })
  4935. }
  4936. func (this *DialysisAPIController) PostSignInfo() {
  4937. patientID, _ := this.GetInt64("patient_id")
  4938. recordDateStr := this.GetString("date")
  4939. if patientID <= 0 {
  4940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4941. return
  4942. }
  4943. if len(recordDateStr) == 0 {
  4944. recordDateStr = time.Now().Format("2006-01-02")
  4945. }
  4946. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4947. if parseDateErr != nil {
  4948. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4950. return
  4951. }
  4952. adminInfo := this.GetMobileAdminUserInfo()
  4953. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4954. if err != nil {
  4955. this.ErrorLog("签名失败:%v", err)
  4956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4957. return
  4958. }
  4959. this.ServeSuccessJSON(map[string]interface{}{
  4960. "doctor_id": adminInfo.AdminUser.Id,
  4961. })
  4962. }
  4963. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4964. patientID, _ := this.GetInt64("patient_id")
  4965. adminInfo := this.GetMobileAdminUserInfo()
  4966. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4967. this.ServeSuccessJSON(map[string]interface{}{
  4968. "monitor": record,
  4969. })
  4970. }
  4971. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4972. thisTime := time.Now()
  4973. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4974. timeLayout := "2006-01-02 15:04:05"
  4975. loc, _ := time.LoadLocation("Local")
  4976. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4977. theAssessmentDateTime := theStartTime.Unix()
  4978. patientID, _ := this.GetInt64("patient_id")
  4979. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4980. adminInfo := this.GetMobileAdminUserInfo()
  4981. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4982. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4983. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4984. var ultrafiltration_rate float64
  4985. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4986. if prescription.ID > 0 {
  4987. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4988. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4989. if template.TemplateId == 6 {
  4990. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4991. }
  4992. // 只针对方济医院
  4993. if template.TemplateId == 1 {
  4994. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4995. ultrafiltration_rate = value
  4996. }
  4997. }
  4998. }
  4999. record.UltrafiltrationRate = ultrafiltration_rate
  5000. record.UltrafiltrationVolume = 0
  5001. if template.TemplateId == 1 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  5002. if ultrafiltration_rate > 0 {
  5003. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5004. record.UltrafiltrationVolume = value
  5005. }
  5006. }
  5007. if template.TemplateId == 6 { //adminInfo.Org.Id == 9538
  5008. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5009. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5010. record.UltrafiltrationVolume = ultrafiltration_volume
  5011. }
  5012. }
  5013. this.ServeSuccessJSON(map[string]interface{}{
  5014. "monitor": record,
  5015. })
  5016. }
  5017. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5018. record_id, _ := this.GetInt64("id")
  5019. nurseID, _ := this.GetInt64("nurse")
  5020. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5021. bedID, _ := this.GetInt64("bed")
  5022. start_time := this.GetString("start_time")
  5023. schedual_type, _ := this.GetInt64("schedual_type")
  5024. if record_id == 0 {
  5025. this.ErrorLog("id:%v", record_id)
  5026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5027. return
  5028. }
  5029. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5030. if parseStartDateErr != nil {
  5031. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5033. return
  5034. }
  5035. adminUserInfo := this.GetMobileAdminUserInfo()
  5036. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5037. if getNurseErr != nil {
  5038. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5040. return
  5041. } else if nurse == nil {
  5042. this.ErrorLog("护士不存在")
  5043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5044. return
  5045. }
  5046. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5047. if getNurseErr != nil {
  5048. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5050. return
  5051. } else if nurse == nil {
  5052. this.ErrorLog("护士不存在")
  5053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5054. return
  5055. }
  5056. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5057. if getDeviceNumberErr != nil {
  5058. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5060. return
  5061. } else if deviceNumber == nil {
  5062. this.ErrorLog("床位号不存在")
  5063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5064. return
  5065. }
  5066. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5067. //
  5068. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5069. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5070. // if getPermissionErr != nil {
  5071. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5072. // return
  5073. // } else if headNursePermission == nil {
  5074. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5075. // return
  5076. // }
  5077. //}
  5078. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5079. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5080. timeLayout := "2006-01-02 15:04:05"
  5081. loc, _ := time.LoadLocation("Local")
  5082. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5083. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5084. schedulestartTime := theStartTime.Unix()
  5085. scheduleendTime := theEndTime.Unix()
  5086. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5087. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5088. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5089. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5090. if err == gorm.ErrRecordNotFound { //空床位
  5091. // 修改了床位逻辑
  5092. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5093. if daySchedule.ID > 0 {
  5094. daySchedule.BedId = bedID
  5095. daySchedule.PartitionId = deviceNumber.ZoneID
  5096. daySchedule.ScheduleType = schedual_type
  5097. daySchedule.UpdatedTime = time.Now().Unix()
  5098. err := service.UpdateSchedule(&daySchedule)
  5099. if err != nil {
  5100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5101. return
  5102. }
  5103. }
  5104. } else if err == nil {
  5105. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5106. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5107. if daySchedule.ID > 0 {
  5108. daySchedule.BedId = bedID
  5109. daySchedule.PartitionId = deviceNumber.ZoneID
  5110. daySchedule.ScheduleType = schedual_type
  5111. daySchedule.UpdatedTime = time.Now().Unix()
  5112. err := service.UpdateSchedule(&daySchedule)
  5113. if err != nil {
  5114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5115. return
  5116. }
  5117. }
  5118. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5120. return
  5121. }
  5122. } else if err != nil {
  5123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5124. return
  5125. }
  5126. }
  5127. dialysisRecord := &models.DialysisOrder{
  5128. ID: record_id,
  5129. UserOrgId: adminUserInfo.Org.Id,
  5130. BedID: bedID,
  5131. StartNurse: nurseID,
  5132. StartTime: startDate.Unix(),
  5133. PunctureNurse: puncture_nurse,
  5134. Creator: adminUserInfo.AdminUser.Id,
  5135. Modifier: adminUserInfo.AdminUser.Id,
  5136. SchedualType: schedual_type,
  5137. }
  5138. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5139. if updateErr != nil {
  5140. this.ErrorLog("修改上机失败:%v", updateErr)
  5141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5142. return
  5143. }
  5144. if updateErr == nil {
  5145. if tempDialysisRecord.Stage == 2 {
  5146. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5147. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5148. fmt.Println(value)
  5149. a, b := math.Modf(value)
  5150. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5151. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5152. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5153. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5154. if updateAssessmentErr != nil {
  5155. utils.ErrorLog("%v", updateAssessmentErr)
  5156. }
  5157. }
  5158. }
  5159. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5160. this.ServeSuccessJSON(map[string]interface{}{
  5161. "dialysis_order": dialysisRecords,
  5162. })
  5163. }
  5164. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5165. record_id, _ := c.GetInt64("id")
  5166. nurseID, _ := c.GetInt64("nurse")
  5167. end_time := c.GetString("end_time")
  5168. if record_id <= 0 || nurseID <= 0 {
  5169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5170. return
  5171. }
  5172. adminUserInfo := c.GetMobileAdminUserInfo()
  5173. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5174. if getNurseErr != nil {
  5175. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5177. return
  5178. } else if nurse == nil {
  5179. c.ErrorLog("护士不存在")
  5180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5181. return
  5182. }
  5183. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5184. if parseEndDateErr != nil {
  5185. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5187. return
  5188. }
  5189. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5190. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5191. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5192. // if getPermissionErr != nil {
  5193. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5194. // return
  5195. // } else if headNursePermission == nil {
  5196. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5197. // return
  5198. // }
  5199. //}
  5200. dialysisRecord := &models.DialysisOrder{
  5201. ID: record_id,
  5202. UserOrgId: adminUserInfo.Org.Id,
  5203. EndTime: endDate.Unix(),
  5204. FinishNurse: nurseID,
  5205. FinishModifier: adminUserInfo.AdminUser.Id,
  5206. }
  5207. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5208. if updateErr != nil {
  5209. c.ErrorLog("修改下机失败:%v", updateErr)
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5211. return
  5212. }
  5213. if updateErr == nil {
  5214. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5215. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5216. a, b := math.Modf(value)
  5217. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5218. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5219. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5220. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5221. if updateAssessmentErr != nil {
  5222. utils.ErrorLog("%v", updateAssessmentErr)
  5223. }
  5224. }
  5225. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5226. c.ServeSuccessJSON(map[string]interface{}{
  5227. "dialysis_order": dialysisRecords,
  5228. })
  5229. }
  5230. func (c *DialysisAPIController) GetLongAdvice() {
  5231. patient_id, _ := c.GetInt64("id")
  5232. adminUserInfo := c.GetMobileAdminUserInfo()
  5233. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5234. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5235. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5236. c.ServeSuccessJSON(map[string]interface{}{
  5237. "status": "1",
  5238. })
  5239. return
  5240. } else { //开启推送提醒
  5241. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5242. var advice_three []*models.DoctorAdvice
  5243. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  5244. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  5245. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  5246. for _, advice := range advices {
  5247. if advice.FrequencyType == 3 {
  5248. t := time.Now()
  5249. week := int(t.Weekday())
  5250. switch week {
  5251. case 1:
  5252. if strings.Index(advice.WeekDay, "周一") == -1 {
  5253. advice_three = append(advice_three, advice)
  5254. }
  5255. break
  5256. case 2:
  5257. if strings.Index(advice.WeekDay, "周二") == -1 {
  5258. advice_three = append(advice_three, advice)
  5259. }
  5260. break
  5261. case 3:
  5262. if strings.Index(advice.WeekDay, "周三") == -1 {
  5263. advice_three = append(advice_three, advice)
  5264. }
  5265. break
  5266. case 4:
  5267. if strings.Index(advice.WeekDay, "周四") == -1 {
  5268. advice_three = append(advice_three, advice)
  5269. }
  5270. break
  5271. case 5:
  5272. if strings.Index(advice.WeekDay, "周五") == -1 {
  5273. advice_three = append(advice_three, advice)
  5274. }
  5275. break
  5276. case 6:
  5277. if strings.Index(advice.WeekDay, "周六") == -1 {
  5278. advice_three = append(advice_three, advice)
  5279. }
  5280. break
  5281. case 0:
  5282. if strings.Index(advice.WeekDay, "周日") == -1 {
  5283. advice_three = append(advice_three, advice)
  5284. }
  5285. break
  5286. }
  5287. }
  5288. }
  5289. for _, advice := range advices_two {
  5290. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5291. now := p.Unix()
  5292. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5293. dayStr2 := "-" + dayStr
  5294. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5295. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5296. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5297. for _, ad := range advices {
  5298. advice_three = append(advice_three, ad)
  5299. }
  5300. }
  5301. if err == nil {
  5302. c.ServeSuccessJSON(map[string]interface{}{
  5303. "status": "2",
  5304. "advices": advices,
  5305. "advices_two": RemoveRepeatedElement(advice_three),
  5306. "is_open_remind": config.IsOpenRemind,
  5307. })
  5308. }
  5309. }
  5310. }
  5311. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5312. newArr = make([]*models.DoctorAdvice, 0)
  5313. for i := 0; i < len(arr); i++ {
  5314. repeat := false
  5315. for j := i + 1; j < len(arr); j++ {
  5316. if arr[i].ID == arr[j].ID {
  5317. repeat = true
  5318. break
  5319. }
  5320. }
  5321. if !repeat {
  5322. newArr = append(newArr, arr[i])
  5323. }
  5324. }
  5325. return
  5326. }
  5327. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5328. patient, _ := c.GetInt64("id", 0)
  5329. groupNo, _ := c.GetInt64("groupno", 0)
  5330. if patient <= 0 {
  5331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5332. return
  5333. }
  5334. adminUserInfo := c.GetMobileAdminUserInfo()
  5335. dataBody := make(map[string]interface{}, 0)
  5336. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5337. if err != nil {
  5338. utils.ErrorLog(err.Error())
  5339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5340. return
  5341. }
  5342. utils.ErrorLog("%v", dataBody)
  5343. timeLayout := "2006-01-02 15:04"
  5344. loc, _ := time.LoadLocation("Local")
  5345. timeLayout2 := "2006-01-02"
  5346. loc2, _ := time.LoadLocation("Local")
  5347. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5348. utils.ErrorLog("advice_type")
  5349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5350. return
  5351. }
  5352. adviceType := int64(2)
  5353. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5354. utils.ErrorLog("advice_date")
  5355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5356. return
  5357. }
  5358. adviceDate, _ := dataBody["advice_date"].(string)
  5359. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5360. AdviceDate := theTime.Unix()
  5361. RecordDate := theTime.Unix()
  5362. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5363. utils.ErrorLog("start_time")
  5364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5365. return
  5366. }
  5367. startTime, _ := dataBody["start_time"].(string)
  5368. if len(startTime) == 0 {
  5369. utils.ErrorLog("len(start_time) == 0")
  5370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5371. return
  5372. }
  5373. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5374. if err != nil {
  5375. utils.ErrorLog(err.Error())
  5376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5377. return
  5378. }
  5379. StartTime := theTime.Unix()
  5380. Remark := ""
  5381. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5382. remark, _ := dataBody["remark"].(string)
  5383. Remark = remark
  5384. }
  5385. var advices []*models.GroupAdvice
  5386. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5387. utils.ErrorLog("advices")
  5388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5389. return
  5390. }
  5391. adviceNames := dataBody["advices"].([]interface{})
  5392. for _, adviceNameMap := range adviceNames {
  5393. adviceNameM := adviceNameMap.(map[string]interface{})
  5394. var advice models.GroupAdvice
  5395. advice.Remark = Remark
  5396. advice.AdviceType = adviceType
  5397. advice.StartTime = StartTime
  5398. advice.AdviceDate = AdviceDate
  5399. advice.RecordDate = RecordDate
  5400. advice.Status = 1
  5401. advice.CreatedTime = time.Now().Unix()
  5402. advice.UpdatedTime = time.Now().Unix()
  5403. advice.StopState = 2
  5404. advice.ExecutionState = 2
  5405. advice.UserOrgId = adminUserInfo.Org.Id
  5406. advice.PatientId = patient
  5407. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5408. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5409. utils.ErrorLog("advice_name")
  5410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5411. return
  5412. }
  5413. adviceName, _ := adviceNameM["advice_name"].(string)
  5414. if len(adviceName) == 0 {
  5415. utils.ErrorLog("len(advice_name) == 0")
  5416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. advice.AdviceName = adviceName
  5420. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5421. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5422. advice.DrugSpec = drugSpec
  5423. }
  5424. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5425. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5426. advice.AdviceDesc = adviceDesc
  5427. }
  5428. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5429. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5430. advice.DrugSpecUnit = drugSpecUnit
  5431. }
  5432. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5433. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5434. // advice.SingleDose = singleDose
  5435. //}
  5436. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5437. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5438. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5439. }
  5440. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5441. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5442. advice.SingleDoseUnit = singleDoseUnit
  5443. }
  5444. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5445. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5446. // advice.PrescribingNumber = prescribingNumber
  5447. //}
  5448. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5449. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5450. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5451. }
  5452. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5453. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5454. advice.PrescribingNumberUnit = prescribingNumberUnit
  5455. }
  5456. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5457. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5458. advice.DeliveryWay = deliveryWay
  5459. }
  5460. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5461. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5462. advice.ExecutionFrequency = executionFrequency
  5463. }
  5464. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5465. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5466. advice.FrequencyType = frequency_type
  5467. }
  5468. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5469. day_count := int64(adviceNameM["day_count"].(float64))
  5470. advice.DayCount = day_count
  5471. }
  5472. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5473. week_day, _ := adviceNameM["week_day"].(string)
  5474. advice.WeekDay = week_day
  5475. }
  5476. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5477. template_id, _ := adviceNameM["template_id"].(string)
  5478. advice.TemplateId = template_id
  5479. }
  5480. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5481. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5482. advice.ExecutionFrequency = executionFrequency
  5483. }
  5484. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5485. children := adviceNameM["child"].([]interface{})
  5486. if len(children) > 0 {
  5487. for _, childrenMap := range children {
  5488. childMap := childrenMap.(map[string]interface{})
  5489. var child models.GroupAdvice
  5490. child.Remark = Remark
  5491. child.AdviceType = adviceType
  5492. child.StartTime = StartTime
  5493. child.AdviceDate = AdviceDate
  5494. child.RecordDate = RecordDate
  5495. child.Status = 1
  5496. child.CreatedTime = time.Now().Unix()
  5497. child.UpdatedTime = time.Now().Unix()
  5498. child.StopState = 2
  5499. child.ExecutionState = 2
  5500. child.UserOrgId = adminUserInfo.Org.Id
  5501. child.PatientId = patient
  5502. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5503. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5504. utils.ErrorLog("child advice_name")
  5505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5506. return
  5507. }
  5508. childAdviceName, _ := childMap["advice_name"].(string)
  5509. if len(childAdviceName) == 0 {
  5510. utils.ErrorLog("len(child advice_name) == 0")
  5511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5512. return
  5513. }
  5514. child.AdviceName = childAdviceName
  5515. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5516. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5517. child.AdviceDesc = childAdviceDesc
  5518. }
  5519. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5520. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5521. child.DrugSpec = childDrugSpec
  5522. }
  5523. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5524. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5525. child.DrugSpecUnit = childDrugSpecUnit
  5526. }
  5527. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5528. child.SingleDose = childMap["single_dose"].(float64)
  5529. }
  5530. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5531. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5532. child.SingleDoseUnit = childSingleDoseUnit
  5533. }
  5534. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5535. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5536. }
  5537. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5538. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5539. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5540. }
  5541. child.DeliveryWay = advice.DeliveryWay
  5542. child.ExecutionFrequency = advice.ExecutionFrequency
  5543. advice.Children = append(advice.Children, &child)
  5544. }
  5545. }
  5546. }
  5547. advices = append(advices, &advice)
  5548. }
  5549. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5550. if err != nil {
  5551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5552. return
  5553. }
  5554. c.ServeSuccessJSON(map[string]interface{}{
  5555. "msg": "ok",
  5556. "advices": list,
  5557. })
  5558. return
  5559. }
  5560. func (c *DialysisAPIController) UploadDryWeight() {
  5561. patient_id, _ := c.GetInt64("id")
  5562. dry_weight, _ := c.GetFloat("dry_weight")
  5563. doctor_id, _ := c.GetInt64("doctor_id")
  5564. remark := c.GetString("remark")
  5565. adminUserInfo := c.GetMobileAdminUserInfo()
  5566. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5567. if err == gorm.ErrRecordNotFound {
  5568. dryWeight := &models.SgjPatientDryweight{
  5569. PatientId: patient_id,
  5570. DryWeight: dry_weight,
  5571. Remakes: remark,
  5572. Ctime: time.Now().Unix(),
  5573. Mtime: time.Now().Unix(),
  5574. Creator: doctor_id,
  5575. Status: 1,
  5576. UserOrgId: adminUserInfo.Org.Id,
  5577. AdjustedValue: "/",
  5578. UserId: adminUserInfo.AdminUser.Id,
  5579. }
  5580. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5581. if createErr == nil {
  5582. c.ServeSuccessJSON(map[string]interface{}{
  5583. "msg": "提交成功",
  5584. "weight": dryWeight,
  5585. })
  5586. }
  5587. } else {
  5588. dryWeight := &models.SgjPatientDryweight{
  5589. PatientId: patient_id,
  5590. DryWeight: dry_weight,
  5591. Remakes: remark,
  5592. Ctime: time.Now().Unix(),
  5593. Mtime: time.Now().Unix(),
  5594. Creator: doctor_id,
  5595. Status: 1,
  5596. UserOrgId: adminUserInfo.Org.Id,
  5597. AdjustedValue: "/",
  5598. UserId: adminUserInfo.AdminUser.Id,
  5599. }
  5600. var value float64
  5601. value = dry_weight - weightAdjust.DryWeight
  5602. if value < 0 {
  5603. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5604. } else if value == 0 {
  5605. dryWeight.AdjustedValue = "/"
  5606. } else if value > 0 {
  5607. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5608. }
  5609. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5610. if createErr == nil {
  5611. c.ServeSuccessJSON(map[string]interface{}{
  5612. "msg": "提交成功",
  5613. "weight": dryWeight,
  5614. })
  5615. }
  5616. }
  5617. }
  5618. func (c *DialysisAPIController) GetSolution() {
  5619. patient_id, _ := c.GetInt64("patient_id")
  5620. mode_id, _ := c.GetInt64("mode_id")
  5621. adminUserInfo := c.GetMobileAdminUserInfo()
  5622. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5623. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5624. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  5625. if err != nil {
  5626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5627. return
  5628. }
  5629. c.ServeSuccessJSON(map[string]interface{}{
  5630. "solution": solution,
  5631. "prescription": prescription,
  5632. "system_prescription": system_prescription,
  5633. })
  5634. }
  5635. func (c *DialysisAPIController) GetSchedule() {
  5636. schedual_type, _ := c.GetInt64("schedual_type")
  5637. adminUserInfo := c.GetMobileAdminUserInfo()
  5638. timeLayout := "2006-01-02 15:04:05"
  5639. date := time.Now().Format("2006-01-02") + " 00:00:00"
  5640. loc, _ := time.LoadLocation("Local")
  5641. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5642. scheduleTime := theStartTime.Unix()
  5643. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5644. c.ServeSuccessJSON(map[string]interface{}{
  5645. "number": deviceNumber,
  5646. })
  5647. }