dialysis_api_controller.go 269KB

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