dialysis_api_controller.go 276KB

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