dialysis_api_controller.go 279KB

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