1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292 |
- package mobile_api_controllers
-
- import (
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "math"
- )
-
- // type DialysisTestAPIController struct {
- // MobileBaseAPIController
- // }
-
- // [get]/m/api/test
- // func (this *DialysisTestAPIController) Test() {
- // orgID := int64(3907)
-
- // now := time.Now()
- // nextWeek := now.AddDate(0, 0, 7)
- // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
- // nextTwoWeek := now.AddDate(0, 0, 14)
- // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
- // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
- // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
-
- // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
- // if exchangeErr != nil {
- // this.ErrorLog("%v", exchangeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // this.ServeSuccessJSON(map[string]interface{}{
- // // "now": now,
- // // "next_week": nextWeek,f
- // // "next_week_mon": nextWeekMon,
- // // "next_week_sun": nextWeekSun,
- // // "next_two_week_mon": nextTwoWeekMon,
- // // "next_two_week_sun": nextTwoWeekSun,
- // "next_week_schs": nextWeekSchs,
- // "next_two_week_schs": nextTwoWeekSchs,
- // })
- // }
-
- type DialysisAPIController struct {
- MobileBaseAPIAuthController
- }
-
- // /m/api/scheduals [get]
- // @param type:int
- // @param date:string
- func (this *DialysisAPIController) Scheduals() {
- schedualType, _ := this.GetInt64("type")
- schedualDate := this.GetString("date")
-
- if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
- schedualType = 0
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
-
- redis := service.RedisClient()
- defer redis.Close()
-
- // cur_date := time.Now().Format("2006-01-02")
- key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- scheduals_json_str, _ := redis.Get(key).Result()
-
- if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
-
- if len(scheduals) > 0 {
- //缓存数据
- scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, scheduals_json, time.Minute*1)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
-
- var dat []map[string]interface{}
- if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
-
- } else {
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- })
-
- }
-
- }
-
- // /m/api/waiting_scheduals [get]
- // @param date:string
- func (this *DialysisAPIController) WaitingScheduals() {
- schedualDate := this.GetString("date")
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil && len(schedualDate) != 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- redis := service.RedisClient()
- defer redis.Close()
-
- // cur_date := time.Now().Format("2006-01-02")
- key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- wait_scheduals, _ := redis.Get(key).Result()
-
- if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- for _, s := range scheduals {
-
- returnScheduals = append(returnScheduals, s)
- }
-
- if len(returnScheduals) > 0 {
- //缓存数据
- wait_scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, wait_scheduals_json, time.Minute*2)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- var dat []map[string]interface{}
- if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
-
- } else {
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- })
- }
-
- }
-
- //else{
- // fmt.Println("33333333")
- //
- // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- // if err != nil {
- // this.ErrorLog("获取排班信息失败:%v", err)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // } else {
- // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- // for _, s := range scheduals {
- //
- // returnScheduals = append(returnScheduals, s)
- // }
- //
- // this.ServeSuccessJSON(map[string]interface{}{
- // "scheduals": returnScheduals,
- // })
- // }
- //
- // }
-
- //if err == nil{
- //
- //
- //
- //
- //
- //}else{
-
- //}
-
- // /m/api/dialysis/record [get]
- // @param patient_id:int
- // @param date:string (yyyy-MM-dd)
- func (this *DialysisAPIController) DialysisRecord() {
-
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
- // this.TraceLog("==================================%+v", schedual)
- if getSchedualErr != nil {
- this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
- if getRTARErr != nil {
- this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- if getPEErr != nil {
- this.ErrorLog("获取透前评估失败:%v", getPEErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- if getLPEErr != nil {
- this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
- if getDoctorAdvicesErr != nil {
- this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
- fmt.Println("----------------------------", getDialysisOrderErr)
- if getDialysisOrderErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
- if getDoubleCheckErr != nil {
- this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
- if getMonitorRecordsErr != nil {
- this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- var lastMonitorRecord *models.MonitoringRecord
-
- lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
- if getLastErr != nil {
- this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
- if getAADErr != nil {
- this.ErrorLog("获取透后评估失败:%v", getAADErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
- if getLAADErr != nil {
- this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
- if getTreatmentSummaryErr != nil {
- this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
- //if getDialysisPrescribeErr != nil {
- // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //}
-
- dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
- //if getDialysisSolutionErr != nil {
- // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //}
-
- lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
- //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
- //if getDialysisPrescribeErr != nil {
- // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //}
-
- //获取系统透析处方模版
- systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
- //if getSystemDialysisPrescribeErr != nil {
- // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //}
-
- //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
-
- //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
-
- if getLPEErr != nil {
- this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
- if getDryErr != nil {
- this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
-
- _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
- goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
-
- operators, err := service.GetAllStarfEs(adminInfo.Org.Id)
- fmt.Println("报错", err)
-
- returnData := map[string]interface{}{
- "patient": patient,
- "schedual": schedual,
- "prescription": dialysisPrescribe,
- "solution": dialysisSolution,
- "last_prescription": lastDialysisPrescribe,
- "receiver_treatment_access": receiverTreatmentAccess,
- "predialysis_evaluation": predialysisEvaluation,
- "doctor_advices": doctorAdvices,
- "double_check": doubleCheck,
- "assessment_after_dislysis": assessmentAfterDislysis,
- "treatment_summary": treatmentSummary,
- "monitor_records": monitorRecords,
- "dialysis_order": dialysisOrder,
- "operators": operators,
- "last_predialysis_evaluation": lastPredialysisEvaluation,
- "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
- "last_monitor_record": lastMonitorRecord,
- "special_premission": headNurses,
- "config": gobalConfig,
- "types": goodTypes,
- "goodInfos": goodInfos,
- "dry_weight": lastDryWeightDislysis,
- "system_prescription": systemDialysisPrescribe,
- }
- this.ServeSuccessJSON(returnData)
- }
-
- func (c *DialysisAPIController) GetDialysisGlobalConfig() {
- adminInfo := c.GetMobileAdminUserInfo()
-
- adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
- devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
- device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
-
- returnData := map[string]interface{}{
- "admin_users": adminUsers,
- "devices": devices,
- "device_numbers": device_numbers,
- }
- c.ServeSuccessJSON(returnData)
-
- }
-
- func (c *DialysisAPIController) PostAtreatmentInfo() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
- summaryContent := c.GetString("summaryContent")
- changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
- treatNurseId, _ := c.GetInt64("treatNurse", 0)
- checkStaffId, _ := c.GetInt64("checkStaff", 0)
- deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
- treatDoctor, _ := c.GetInt64("treatDoctor", 0)
- nursingRecord := c.GetString("nursing_record")
- fmt.Println("护理记录", nursingRecord)
- specialRecord := c.GetString("special_record")
- fmt.Println("特殊记录", specialRecord)
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- changeMedicalNurseId = adminUserInfo.AdminUser.Id
- checkStaffId = adminUserInfo.AdminUser.Id
- deboardNurseId = adminUserInfo.AdminUser.Id
- treatDoctor = adminUserInfo.AdminUser.Id
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
- summary := models.TreatmentSummary{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Mission: propagandaAndEducationContent,
- DialysisSummary: summaryContent,
- SjNurse: changeMedicalNurseId,
- ZlNurse: treatNurseId,
- HdNurse: checkStaffId,
- XjNurse: deboardNurseId,
- ZlDoctor: treatDoctor,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- NursingRecord: nursingRecord,
- SpecialRecord: specialRecord,
- }
- _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if treatmentSummary.ID == 0 { //新增
- summary.Creater = adminUserInfo.AdminUser.Id
- service.AddSigleSummaryRecord(&summary)
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- } else { //修改
- //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- summary.Creater = treatmentSummary.Creater
- summary.CreatedTime = treatmentSummary.CreatedTime
-
- summary.Modifier = adminUserInfo.AdminUser.Id
- summary.ID = treatmentSummary.ID
- service.UpdateSummeRecord(&summary)
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- }
- }
-
- func (c *DialysisAPIController) PostDoubleCheck() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- checkTimeStr := c.GetString("check_time")
-
- dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
- dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
- vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
- pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
- dialysis_item_desc := c.GetString("dialysis_item_desc")
- dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
- vascular_access_desc := c.GetString("vascular_access_desc")
- pipeline_connection_desc := c.GetString("pipeline_connection_desc")
- collator, _ := c.GetInt64("collator", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(checkTimeStr) == 0 {
- checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
- }
- checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- doubleCheck := models.DoubleCheck{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- DialysisItemCheck: dialysis_item_check,
- DialysisParameterCheck: dialysis_parameter_check,
- VascularAccessVerification: vascular_access_verification,
- PipelineConnectionCheck: pipeline_connection_check,
- DialysisItemDesc: dialysis_item_desc,
- DialysisParameterDesc: dialysis_parameter_desc,
- VascularAccessDesc: vascular_access_desc,
- PipelineConnectionDesc: pipeline_connection_desc,
- Collator: collator,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- CheckDate: recordDate.Unix(),
- }
-
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if check.ID == 0 { //新增
- doubleCheck.FirstCheckTime = checkDate.Unix()
-
- doubleCheck.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleDoubleCheck(&doubleCheck)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- })
- }
- } else { //修改
- if check.Modifier != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
-
- } else {
- if adminUserInfo.AdminUser.Id == check.Creater {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
- return
- }
- doubleCheck.FirstCheckTime = check.FirstCheckTime
- doubleCheck.CheckTime = checkDate.Unix()
- doubleCheck.Creater = check.Creater
- doubleCheck.CreatedTime = check.CreatedTime
- doubleCheck.Modifier = adminUserInfo.AdminUser.Id
- doubleCheck.ID = check.ID
- err := service.UpdateDoubleCheck(&doubleCheck)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- })
- }
-
- }
-
- }
-
- }
- func (c *DialysisAPIController) PostAcceptsAssessment() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- way, _ := c.GetInt64("way", 0)
- consciousness, _ := c.GetInt64("consciousness", 0)
- appetite, _ := c.GetInt64("appetite", 0)
- condition, _ := c.GetInt64("condition", 0)
- posture, _ := c.GetInt64("posture")
- sick_condition, _ := c.GetInt64("sick_condition", 0)
- danger_level, _ := c.GetInt64("danger_level", 0)
- intake, _ := c.GetInt64("intake", 0)
- nutrition, _ := c.GetInt64("nutrition", 0)
- psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
- psychological_assessment_other := c.GetString("psychological_assessment_other")
- score := c.GetString("score")
- sick_condition_other := c.GetString("sick_condition_other")
-
- //precaution, _ := c.GetInt64("precaution", 0)
- precaution := c.GetString("precaution")
- precaution_other := c.GetString("precaution_other")
- psychological_other := c.GetString("psychological_other")
-
- admission_number := c.GetString("admission_number")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- receiveTreatmentAsses := models.ReceiveTreatmentAsses{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- Way: way,
- Consciousness: consciousness,
- Appetite: appetite,
- Condition: condition,
- SickCondition: sick_condition,
- DangerLevel: danger_level,
- Intake: intake,
- Nutrition: nutrition,
- PsychologicalAssessment: psychological_assessment,
- PsychologicalAssessmentOther: psychological_assessment_other,
- SickConditionOther: sick_condition_other,
- Posture: posture,
- CreatedTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- Score: score,
- Precaution: precaution,
- PrecautionOther: precaution_other,
- PsychologicalOther: psychological_other,
- AdmissionNumber: admission_number,
- }
-
- if receiveTreatment.ID == 0 { //新增
- receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- } else { //修改
- //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- receiveTreatmentAsses.Creater = receiveTreatment.Creater
- receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
-
- receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
- receiveTreatmentAsses.ID = receiveTreatment.ID
- err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
- }
-
- }
- func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- weightAfter, _ := c.GetFloat("weight_after", 0)
- additionalWeight, _ := c.GetFloat("additional_weight", 0)
- weightReduce, _ := c.GetFloat("weight_loss", 0)
- temperature, _ := c.GetFloat("temperature", 0)
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
- breathing_rate, _ := c.GetFloat("breathing_rate", 0)
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
- actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
- actual_displacement, _ := c.GetFloat("actual_displacement", 0)
- actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
- actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
- cruor := c.GetString("cruor")
- symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
- internalFistula := c.GetString("internal_fistula")
- catheter := c.GetString("catheter")
- complications := c.GetString("complication")
- remark := c.GetString("remark")
- dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
-
- dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
-
- blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
- blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
-
- puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
- puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
- internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
- patientGose, _ := c.GetInt64("patient_gose", 0)
- inpatientDepartment := c.GetString("inpatient_department")
- observationContent := c.GetString("observation_content")
- observationContentOther := c.GetString("observation_content_other")
- dialysis_process, _ := c.GetInt64("dialysis_process", 0)
-
- in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
- in_advance_reason := c.GetString("in_advance_reason")
- hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
- hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
- tremor_noise, _ := c.GetInt64("tremor_noise", 0)
- disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
- disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
-
- arterial_tube, _ := c.GetInt64("arterial_tube", 0)
- intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- in_advance_reason_other := c.GetString("in_advance_reason_other")
- is_eat, _ := c.GetInt64("is_eat", 0)
-
- cvc_a, _ := c.GetFloat("cvc_a", 0)
- cvc_v, _ := c.GetFloat("cvc_v", 0)
- channels, _ := c.GetInt64("channel", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
-
- assessmentAfterDislysis := models.AssessmentAfterDislysis{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Temperature: temperature,
- PulseFrequency: pulse_frequency,
- BreathingRate: breathing_rate,
- SystolicBloodPressure: systolic_blood_pressure,
- DiastolicBloodPressure: diastolic_blood_pressure,
- ActualUltrafiltration: actual_ultrafiltration,
- ActualDisplacement: actual_displacement,
- ActualTreatmentHour: actualtreatHour,
- ActualTreatmentMinute: actualtreatmin,
- WeightAfter: weightAfter,
- AdditionalWeight: additionalWeight,
- WeightLoss: weightReduce,
- Cruor: cruor,
- SymptomAfterDialysis: symptomsAfterDialysi,
- InternalFistula: internalFistula,
- Catheter: catheter,
- Complication: complications,
- DialysisIntakes: dialysateVolume,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- Remark: remark,
- BloodAccessPartId: blood_access_part_id,
- BloodAccessPartOperaId: blood_access_part_opera_id,
- DialysisIntakesUnit: dialysis_intakes_unit,
- PuncturePointOozingBlood: puncturePointOozingBlood,
- PuncturePointHaematoma: puncturePointHaematoma,
- InternalFistulaTremorAc: internalFistulaTremorAc,
- PatientGose: patientGose,
- InpatientDepartment: inpatientDepartment,
- ObservationContent: observationContent,
- ObservationContentOther: observationContentOther,
- DialysisProcess: dialysis_process,
- InAdvanceMinute: in_advance_minute,
- InAdvanceReason: in_advance_reason,
- HemostasisMinute: hemostasis_minute,
- HemostasisOpera: hemostasis_opera,
- TremorNoise: tremor_noise,
- DisequilibriumSyndrome: disequilibrium_syndrome,
- DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
- ArterialTube: arterial_tube,
- IntravenousTube: intravenous_tube,
- Dialyzer: dialyzer,
- InAdvanceReasonOther: in_advance_reason_other,
- IsEat: is_eat,
- CvcA: cvc_a,
- CvcV: cvc_v,
- Channel: channels,
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if assessmentAfter.ID == 0 { //新增
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
-
- } else {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
-
- }
-
- err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- }
- } else { //修改
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
- } else {
- assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
- if assessmentAfterDislysis.Creater == 0 {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
- }
- }
-
- assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
- assessmentAfterDislysis.ID = assessmentAfter.ID
- err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- }
- }
- }
-
- func (c *DialysisAPIController) PostDialysisPrescription() {
- id, _ := c.GetInt64("patient", 0)
-
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- glucose, _ := c.GetFloat("glucose", 0)
- prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
-
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- //TODO 需要根据角色去判断
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- PrescriptionDoctor: prescription_doctor,
- ReplacementTotal: replacement_total,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- TargetKtv: target_ktv,
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if dialysisPrescription.ID == 0 { //新增
- //if mode_id > 0 {
- // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- //}
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor = adminUserInfo.AdminUser.Id
- } else {
- prescription_doctor = 0
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleRecord(&prescription)
-
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
-
- }
- } else { //修改
- //if mode_id > 0 {
- // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- //}
- //if template.TemplateId == 1 {
- // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
- if record.IsOpen == 1 {
- niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
- jms_good_type_id, _ := beego.AppConfig.Int64("jms")
- fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
- fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
- hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
- dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
- filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
-
- dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
- injector_good_type_id, _ := beego.AppConfig.Int64("injector")
- bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
- tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
- safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
- aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
-
- err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- if err == nil {
- if order.ID > 0 {
- if dialysisPrescription.Niprocart != niprocart {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
-
- //1.用上机透析日期查出当天的订单
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = niprocart
- warehouseOutInfo.GoodTypeId = niprocart_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
- }
- }
- }
- }
- }
- if dialysisPrescription.Jms != jms {
- //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = jms
- warehouseOutInfo.GoodTypeId = jms_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
- }
- }
-
- }
- }
- }
- if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set
- warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set_16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set_good_type_id,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Hemoperfusion != hemoperfusion {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
- _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.WarehouseOutId,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyser_sterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
-
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
-
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Filtryzer != filtryzer {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Dialyzers != dialyzers {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Injector != injector {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = injector
- warehouseOutInfo.GoodTypeId = injector_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Bloodlines != bloodlines {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = tubing_hemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Package != safe_package {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = safe_package
- warehouseOutInfo.GoodTypeId = safe_package_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.ALiquid != a_liquid {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = a_liquid
- warehouseOutInfo.GoodTypeId = aliquid_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
- }
- }
- }
- }
-
- }
-
- }
- }
- }
-
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor := adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
- }
- if dialysisPrescription.Creater == 0 { //体重称
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- } else {
- prescription.Creater = dialysisPrescription.Creater
- }
-
- prescription.ID = dialysisPrescription.ID
- err := service.UpDateDialysisPrescription(&prescription)
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) Finish() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
-
- if id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- // 获取当天的第一条透析纪录
- fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取当前的最后一条透析纪录
- endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- fmt.Println(endmonitorRecords.UltrafiltrationVolume)
-
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- var tempassessmentAfterDislysis models.AssessmentAfterDislysis
-
- if assessmentAfterDislysis != nil {
- tempassessmentAfterDislysis = *assessmentAfterDislysis
- tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
- } else {
- tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
- tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
- tempassessmentAfterDislysis.Status = 1
- tempassessmentAfterDislysis.PatientId = id
- tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
- }
-
- if dialysisOrder.Stage == 1 {
- temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
- fmt.Println(hour)
- fmt.Println(minute)
- tempassessmentAfterDislysis.ActualTreatmentHour = hour
- tempassessmentAfterDislysis.ActualTreatmentMinute = minute
- }
-
- if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
- //var num1 int64
- //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
- //fmt.Println(num1)
- //sub := float64(num1 / 3600)
- //fmt.Println(sub)
- //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
- //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
- //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
-
- tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
- tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
- tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
-
- }
-
- err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if dialysisOrder == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
- return
- }
- if dialysisOrder.Stage == 2 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
- return
- }
- if dialysisOrder.Stage == 1 {
- err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
- //结束时候透析次数加1
- service.UpdateSolutionByPatientId(id)
- dialysisOrder.Stage = 2
- dialysisOrder.FinishNurse = nurseID
- dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
- dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
- dialysisOrder.EndTime = endDate.Unix()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysisOrder": dialysisOrder,
- "assessmentAfterDislysis": tempassessmentAfterDislysis,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- }
-
- func (c *DialysisAPIController) GetAllZone() {
- adminUserInfo := c.GetMobileAdminUserInfo()
- err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "zone": zone,
- })
- }
-
- }
-
- func (c *DialysisAPIController) GetSchedualPatientsList() {
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- startTime, _ := c.GetInt64("schedul_time", 0)
- partitionType, _ := c.GetInt64("partition_type", 0)
- keywords := c.GetString("keywords")
- dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": dialysisSchedule,
- })
- }
- return
- }
-
- // /m/api/dialysis/start [post]
- // @param patient_id:int
- // @param record_date:string 排班时间 (yyyy-mm-dd)
- // @param nurse:int 上机护士
- // @param bed:int 床位号
- func (this *DialysisAPIController) StartDialysis() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("record_date")
- nurseID, _ := this.GetInt64("nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- blood_drawing, _ := this.GetInt64("blood_drawing")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
-
- if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseErr != nil {
- this.ErrorLog("时间解析失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
- if configs.IsOpen == 1 {
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
- if prescription.ID == 0 {
- this.ErrorLog("上机失败,还没开处方")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
- return
- }
- }
-
- dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- if getRecordErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getRecordErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if dialysisRecord != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
- return
- }
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- //查询该床位是否有人用了
- order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.BedId = bedID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- err := service.UpdateSchedule(&daySchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
-
- if order_err == nil {
- if order.ID > 0 { //该机位被其他人占用了
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
-
- } else {
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.BedId = bedID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- err := service.UpdateSchedule(&daySchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- }
- } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.BedId = bedID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- err := service.UpdateSchedule(&daySchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- dialysisRecord = &models.DialysisOrder{
- DialysisDate: recordDate.Unix(),
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- Stage: 1,
- BedID: bedID,
- StartNurse: nurseID,
- Status: 1,
- StartTime: startDate.Unix(),
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- SchedualType: schedual_type,
- }
-
- createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
- newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- var tempdispose string
- // 只针对中能建
- if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
- tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- }
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
- if prescription.ID > 0 {
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- }
- // 只针对方济医院
- if template.TemplateId == 1 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- }
- }
- }
-
- record := models.MonitoringRecord{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- DialysisOrderId: dialysisRecord.ID,
- MonitoringDate: schedulestartTime,
- OperateTime: startDate.Unix(),
- // MonitoringTime: recordTime,
- MonitoringNurse: nurseID,
- Dispose: tempdispose,
- UltrafiltrationRate: ultrafiltration_rate,
- UltrafiltrationVolume: 0,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- }
-
- // 如果当天有插入数据,则不再往透析纪录里插入数据
- if newdialysisRecord.ID > 0 {
- err := service.CreateMonitor(&record)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
- return
- }
- }
-
- //是否启动自动扣减功能
- _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
-
- //启动的话
- if config.IsOpen == 1 {
- niprocart, _ := beego.AppConfig.Int64("niprocart")
- jms, _ := beego.AppConfig.Int64("jms")
- fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
- fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
- hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
- dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
- filtryzer, _ := beego.AppConfig.Int64("filtryzer")
-
- dialyzers, _ := beego.AppConfig.Int64("dialyzers")
- injector, _ := beego.AppConfig.Int64("injector")
- bloodlines, _ := beego.AppConfig.Int64("bloodlines")
- tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
- safe_package, _ := beego.AppConfig.Int64("package")
- aliquid, _ := beego.AppConfig.Int64("aliquid")
-
- //库存自动扣减功能
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
- if prescription.ID > 0 {
- out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- creater := adminUserInfo.AdminUser.Id
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminUserInfo.Org.Id,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: recordDate.Unix(),
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- utils.TraceLog("创建出库单失败 err = %v", err)
- } else {
-
- if prescription.Niprocart > 0 {
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- //查出入库记录中最后一条记录
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Niprocart
- warehouseOutInfo.GoodTypeId = niprocart
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Niprocart,
- GoodTypeId: niprocart,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
- if prescription.Jms > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Jms
- warehouseOutInfo.GoodTypeId = jms
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Jms,
- GoodTypeId: jms,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
- if prescription.FistulaNeedleSet > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
- warehouseOutInfo.GoodTypeId = fistula_needle_set
-
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet,
- GoodTypeId: fistula_needle_set,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
- if prescription.FistulaNeedleSet16 > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16
-
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet16,
- GoodTypeId: fistula_needle_set_16,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
- if prescription.Hemoperfusion > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion
-
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Hemoperfusion,
- GoodTypeId: hemoperfusion,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- }
-
- }
- if prescription.DialyserSterilised > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.DialyserSterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.DialyserSterilised,
- GoodTypeId: dialyser_sterilised,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- }
-
- }
- if prescription.Filtryzer > 0 {
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Filtryzer,
- GoodTypeId: filtryzer,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
- if prescription.Dialyzers > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Dialyzers,
- GoodTypeId: dialyzers,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
- if prescription.Injector > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Injector
- warehouseOutInfo.GoodTypeId = injector
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Injector,
- GoodTypeId: injector,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
- if prescription.Bloodlines > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Bloodlines,
- GoodTypeId: bloodlines,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
- if prescription.TubingHemodialysis > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.TubingHemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.TubingHemodialysis,
- GoodTypeId: tubingHemodialysis,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
- if prescription.Package > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Package
- warehouseOutInfo.GoodTypeId = safe_package
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Package,
- GoodTypeId: safe_package,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.ALiquid > 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.ALiquid
- warehouseOutInfo.GoodTypeId = aliquid
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.ALiquid,
- GoodTypeId: aliquid,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- }
- } else if err == nil {
- if out.ID > 0 {
-
- if prescription.Niprocart > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Niprocart
- warehouseOutInfo.GoodTypeId = niprocart
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Niprocart,
- GoodTypeId: niprocart,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Niprocart,
- GoodTypeId: niprocart,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
-
- if prescription.Jms > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Jms
- warehouseOutInfo.GoodTypeId = jms
- warehouseOutInfo.Count = 1
-
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Jms,
- GoodTypeId: jms,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
-
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Jms,
- GoodTypeId: jms,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.FistulaNeedleSet > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
- warehouseOutInfo.GoodTypeId = fistula_needle_set
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet,
- GoodTypeId: fistula_needle_set,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
-
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet,
- GoodTypeId: fistula_needle_set,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.FistulaNeedleSet16 > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet16,
- GoodTypeId: fistula_needle_set_16,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
-
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.FistulaNeedleSet16,
- GoodTypeId: fistula_needle_set_16,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
-
- if prescription.Hemoperfusion > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Hemoperfusion,
- GoodTypeId: hemoperfusion,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
-
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Hemoperfusion,
- GoodTypeId: hemoperfusion,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
- }
-
- if prescription.DialyserSterilised > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.DialyserSterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.DialyserSterilised,
- GoodTypeId: dialyser_sterilised,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
-
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.DialyserSterilised,
- GoodTypeId: dialyser_sterilised,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.Filtryzer > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Filtryzer,
- GoodTypeId: filtryzer,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Filtryzer,
- GoodTypeId: filtryzer,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.Dialyzers > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Dialyzers,
- GoodTypeId: dialyzers,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Dialyzer,
- GoodTypeId: dialyzers,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.Injector > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Injector
- warehouseOutInfo.GoodTypeId = injector
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Injector,
- GoodTypeId: injector,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Injector,
- GoodTypeId: injector,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.Bloodlines > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Bloodlines,
- GoodTypeId: bloodlines,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Bloodlines,
- GoodTypeId: bloodlines,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.TubingHemodialysis > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.TubingHemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.TubingHemodialysis,
- GoodTypeId: tubingHemodialysis,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.TubingHemodialysis,
- GoodTypeId: tubingHemodialysis,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.Package > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.Package
- warehouseOutInfo.GoodTypeId = safe_package
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Package,
- GoodTypeId: safe_package,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.Package,
- GoodTypeId: safe_package,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- if prescription.ALiquid > 0 {
- outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
-
- if err == gorm.ErrRecordNotFound {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: startDate.Unix(),
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = prescription.ALiquid
- warehouseOutInfo.GoodTypeId = aliquid
- warehouseOutInfo.Count = 1
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.ALiquid,
- GoodTypeId: aliquid,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- } else if err == nil { //记录存在,则将耗材使用数量加1
- if outInfo.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
- }
- //插入病人耗材使用记录
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: outInfo.ID,
- WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
- PatientId: patientID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: startDate.Unix(),
- OrgId: adminUserInfo.Org.Id,
- GoodId: prescription.ALiquid,
- GoodTypeId: aliquid,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- }
-
- }
-
- }
- }
- } else {
- this.ErrorLog("上机失败,还没开处方")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
- return
- }
- }
- if createErr != nil {
- this.ErrorLog("上机失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": newdialysisRecord,
- "monitor": record,
- })
- }
-
- func (c *DialysisAPIController) PostSolution() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- glucose, _ := c.GetFloat("glucose", 0)
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
-
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- if mode_id > 0 {
- service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- //if appRole.UserType == 2 || appRole.UserType == 1 {
- // prescription_doctor = appRole.AdminUserId
- //} else {
- // prescription_doctor = 0
- //}
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
-
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- PrescriptionDoctor: prescription_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
-
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- TargetKtv: target_ktv,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if dialysisPrescription.ID == 0 { //新增
- prescription.Creater = adminUserInfo.AdminUser.Id
- } else { //修改
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- //if/**/
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
- if record.IsOpen == 1 {
- niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
- jms_good_type_id, _ := beego.AppConfig.Int64("jms")
- fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
- fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
- hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
- dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
- filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
-
- dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
- injector_good_type_id, _ := beego.AppConfig.Int64("injector")
- bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
- tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
- safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
- aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
-
- err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- if err == nil {
- if order.ID > 0 {
- if dialysisPrescription.Niprocart != niprocart {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
-
- //1.用上机透析日期查出当天的订单
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = niprocart
- warehouseOutInfo.GoodTypeId = niprocart_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
- }
- }
- }
- }
- }
- if dialysisPrescription.Jms != jms {
- //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = jms
- warehouseOutInfo.GoodTypeId = jms_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
- }
- }
-
- }
- }
- }
- if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set
- warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set_16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: fistula_needle_set_good_type_id,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Hemoperfusion != hemoperfusion {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
- _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.WarehouseOutId,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyser_sterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
-
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
-
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Filtryzer != filtryzer {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Dialyzers != dialyzers {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Injector != injector {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = injector
- warehouseOutInfo.GoodTypeId = injector_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Bloodlines != bloodlines {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = tubing_hemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Package != safe_package {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = safe_package
- warehouseOutInfo.GoodTypeId = safe_package_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.ALiquid != a_liquid {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.Org.Id,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = a_liquid
- warehouseOutInfo.GoodTypeId = aliquid_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.Org.Id,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
- }
- }
- }
- }
-
- }
-
- }
- }
- }
-
- //prescription.Creater = dialysisPrescription.Creater
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- prescription.ID = dialysisPrescription.ID
- }
-
- solution := models.DialysisSolution{
- RegistrarsId: adminUserInfo.AdminUser.Id,
- UserOrgId: adminUserInfo.Org.Id,
- Doctor: prescription_doctor,
- PatientId: id,
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- Dewater: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- TargetKtv: target_ktv,
- }
- service.SavePrescriptionAndCreateSolution(&solution, &prescription)
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": &solution,
- "prescription": &prescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetAcceptsAssessment() {
- patient, _ := c.GetInt64("patient", 0)
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- func (this *DialysisAPIController) PostSignInfo() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetMobileAdminUserInfo()
- err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
-
- if err != nil {
- this.ErrorLog("签名失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "doctor_id": adminInfo.AdminUser.Id,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecord() {
- patientID, _ := this.GetInt64("patient_id")
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecordTody() {
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theAssessmentDateTime := theStartTime.Unix()
-
- patientID, _ := this.GetInt64("patient_id")
- monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
- fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
-
- template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
- if prescription.ID > 0 {
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if template.TemplateId == 6 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- }
- // 只针对方济医院
- if template.TemplateId == 1 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- }
- }
- }
- record.UltrafiltrationRate = ultrafiltration_rate
- record.UltrafiltrationVolume = 0
- 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
- if ultrafiltration_rate > 0 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
- record.UltrafiltrationVolume = value
- }
- }
-
- if template.TemplateId == 6 { //adminInfo.Org.Id == 9538
- if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (this *DialysisAPIController) ModifyStartDialysisOrder() {
- record_id, _ := this.GetInt64("id")
- nurseID, _ := this.GetInt64("nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- if record_id == 0 {
- this.ErrorLog("id:%v", record_id)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
- //
- //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
-
- if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- daySchedule.BedId = bedID
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- err := service.UpdateSchedule(&daySchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- daySchedule.BedId = bedID
- daySchedule.PartitionId = deviceNumber.ZoneID
-
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- err := service.UpdateSchedule(&daySchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- BedID: bedID,
- StartNurse: nurseID,
- StartTime: startDate.Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- SchedualType: schedual_type,
- }
-
- updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
- if updateErr != nil {
- this.ErrorLog("修改上机失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- if tempDialysisRecord.Stage == 2 {
- temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
-
- }
- func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
- record_id, _ := c.GetInt64("id")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
-
- if record_id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
-
- //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- EndTime: endDate.Unix(),
- FinishNurse: nurseID,
- FinishModifier: adminUserInfo.AdminUser.Id,
- }
-
- updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
- if updateErr != nil {
- c.ErrorLog("修改下机失败:%v", updateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
- }
-
- func (c *DialysisAPIController) GetLongAdvice() {
- patient_id, _ := c.GetInt64("id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
-
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
-
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- })
- }
- }
-
- }
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
-
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- timeLayout2 := "2006-01-02"
- loc2, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(2)
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- Remark = remark
- }
-
- var advices []*models.GroupAdvice
- if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
- utils.ErrorLog("advices")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["advices"].([]interface{})
- for _, adviceNameMap := range adviceNames {
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- // advice.SingleDose = singleDose
- //}
-
- if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.SingleDose = adviceNameM["single_dose"].(float64)
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- // advice.PrescribingNumber = prescribingNumber
- //}
-
- if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
- day_count := int64(adviceNameM["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
- week_day, _ := adviceNameM["week_day"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
- children := adviceNameM["child"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.Org.Id
- child.PatientId = patient
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
- child.SingleDose = childMap["single_dose"].(float64)
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
- child.PrescribingNumber = childMap["prescribing_number"].(float64)
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- return
-
- }
-
- func (c *DialysisAPIController) UploadDryWeight() {
- patient_id, _ := c.GetInt64("id")
- dry_weight, _ := c.GetFloat("dry_weight")
- doctor_id, _ := c.GetInt64("doctor_id")
- remark := c.GetString("remark")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
- if err == gorm.ErrRecordNotFound {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- createErr := service.CreatePatientWeightAdjust(dryWeight)
-
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
-
- } else {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- var value float64
- value = dry_weight - weightAdjust.DryWeight
-
- if value < 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
- } else if value == 0 {
- dryWeight.AdjustedValue = "/"
- } else if value > 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
- }
-
- createErr := service.CreatePatientWeightAdjust(dryWeight)
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetSolution() {
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
- prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
- system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- "prescription": prescription,
- "system_prescription": system_prescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetSchedule() {
- schedual_type, _ := c.GetInt64("schedual_type")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02 15:04:05"
-
- date := time.Now().Format("2006-01-02") + " 00:00:00"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
- scheduleTime := theStartTime.Unix()
-
- deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "number": deviceNumber,
- })
-
- }
-
- func (c *DialysisAPIController) GetPatientId() {
- id, _ := c.GetInt64("id")
- patientId, _ := service.GetPatientId(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientId,
- })
- }
|