dialysis_api_controller.go 280KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  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. "github.com/astaxie/beego"
  16. "math"
  17. "net/http"
  18. "net/url"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. scheduals_json_str, _ := redis.Get(key).Result()
  77. redis.Set(key, "", time.Second)
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. if err != nil {
  82. this.ErrorLog("获取排班信息失败:%v", err)
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. } else {
  85. if len(scheduals) > 0 {
  86. devices, _ := service.GetAllDevicetByListSix(orgID)
  87. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  88. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  89. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  90. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  91. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  92. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  93. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  94. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  95. for key, item := range scheduals {
  96. // 获取患者信息
  97. for _, patient := range patients {
  98. if item.PatientId == patient.ID {
  99. scheduals[key].SchedualPatient = patient
  100. break
  101. }
  102. }
  103. // 床位信息
  104. for _, device := range devices {
  105. if item.BedId == device.ID {
  106. scheduals[key].DeviceNumber = device
  107. break
  108. }
  109. }
  110. // 医嘱信息
  111. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  112. for _, advice := range advices {
  113. if item.PatientId == advice.PatientId {
  114. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  115. }
  116. }
  117. // 医嘱信息
  118. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  119. for _, hisAdvice := range hisAdvices {
  120. if item.PatientId == hisAdvice.PatientId {
  121. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  122. }
  123. }
  124. // 医嘱信息
  125. for _, prescription := range prescriptions {
  126. if item.PatientId == prescription.PatientId {
  127. scheduals[key].Prescription = prescription
  128. break
  129. }
  130. }
  131. // 透前评估
  132. for _, assessmentBefore := range assessmentBefores {
  133. if item.PatientId == assessmentBefore.PatientId {
  134. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  135. break
  136. }
  137. }
  138. // 透析上下机
  139. for _, dialysisOrder := range dialysisOrders {
  140. if item.PatientId == dialysisOrder.PatientId {
  141. scheduals[key].DialysisOrder = dialysisOrder
  142. break
  143. }
  144. }
  145. // 治疗小节
  146. for _, afterDislysis := range AssessmentAfterDislysis {
  147. if item.PatientId == afterDislysis.PatientId {
  148. scheduals[key].AssessmentAfterDislysis = afterDislysis
  149. break
  150. }
  151. }
  152. // 透后评估
  153. for _, treatmentSummary := range treatmentSummarys {
  154. if item.PatientId == treatmentSummary.PatientId {
  155. scheduals[key].TreatmentSummary = treatmentSummary
  156. break
  157. }
  158. }
  159. for _, check := range dobulecheck {
  160. if item.PatientId == check.PatientId {
  161. scheduals[key].DoubleCheck = check
  162. break
  163. }
  164. }
  165. }
  166. //缓存数据
  167. scheduals_json, err := json.Marshal(&scheduals)
  168. if err == nil {
  169. redis.Set(key, scheduals_json, time.Second*60)
  170. }
  171. }
  172. //获取今日所有的处方开的耗材
  173. _, configs := service.FindXTHisProjectByOrgId(orgID)
  174. project := make([]*models.HisPrescriptionProjectTwo, 0)
  175. if configs.ID > 0 && configs.IsOpen == 1 {
  176. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  177. }
  178. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  179. this.ServeSuccessJSON(map[string]interface{}{
  180. "scheduals": scheduals,
  181. "project": project,
  182. })
  183. }
  184. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  185. var dat []map[string]interface{}
  186. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  187. } else {
  188. }
  189. //获取今日所有的处方开的耗材
  190. _, configs := service.FindXTHisProjectByOrgId(orgID)
  191. project := make([]*models.HisPrescriptionProjectTwo, 0)
  192. if configs.ID > 0 && configs.IsOpen == 1 {
  193. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  194. }
  195. this.ServeSuccessJSON(map[string]interface{}{
  196. "scheduals": dat,
  197. "redis": "true",
  198. "date": schedualDate,
  199. "project": project,
  200. })
  201. }
  202. }
  203. // /m/api/waiting_scheduals [get]
  204. // @param date:string
  205. func (this *DialysisAPIController) WaitingScheduals() {
  206. schedualDate := this.GetString("date")
  207. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  208. if parseDateErr != nil && len(schedualDate) != 0 {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. adminInfo := this.GetMobileAdminUserInfo()
  213. orgID := adminInfo.Org.Id
  214. redis := service.RedisClient()
  215. defer redis.Close()
  216. // cur_date := time.Now().Format("2006-01-02")
  217. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  218. wait_scheduals, _ := redis.Get(key).Result()
  219. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  220. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  221. if err != nil {
  222. this.ErrorLog("获取排班信息失败:%v", err)
  223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  224. } else {
  225. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  226. for _, s := range scheduals {
  227. returnScheduals = append(returnScheduals, s)
  228. }
  229. if len(returnScheduals) > 0 {
  230. //缓存数据
  231. wait_scheduals_json, err := json.Marshal(scheduals)
  232. if err == nil {
  233. redis.Set(key, wait_scheduals_json, time.Second*30)
  234. }
  235. }
  236. this.ServeSuccessJSON(map[string]interface{}{
  237. "scheduals": scheduals,
  238. })
  239. }
  240. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  241. var dat []map[string]interface{}
  242. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  243. } else {
  244. }
  245. this.ServeSuccessJSON(map[string]interface{}{
  246. "scheduals": dat,
  247. "redis": "true",
  248. "date": schedualDate,
  249. })
  250. }
  251. }
  252. //else{
  253. // fmt.Println("33333333")
  254. //
  255. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  256. // if err != nil {
  257. // this.ErrorLog("获取排班信息失败:%v", err)
  258. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  259. // } else {
  260. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  261. // for _, s := range scheduals {
  262. //
  263. // returnScheduals = append(returnScheduals, s)
  264. // }
  265. //
  266. // this.ServeSuccessJSON(map[string]interface{}{
  267. // "scheduals": returnScheduals,
  268. // })
  269. // }
  270. //
  271. // }
  272. //if err == nil{
  273. //
  274. //
  275. //
  276. //
  277. //
  278. //}else{
  279. //}
  280. // /m/api/dialysis/record [get]
  281. // @param patient_id:int
  282. // @param date:string (yyyy-MM-dd)
  283. func (this *DialysisAPIController) DialysisRecord() {
  284. patientID, _ := this.GetInt64("patient_id")
  285. recordDateStr := this.GetString("date")
  286. if patientID <= 0 {
  287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  288. return
  289. }
  290. if len(recordDateStr) == 0 {
  291. recordDateStr = time.Now().Format("2006-01-02")
  292. }
  293. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  294. if parseDateErr != nil {
  295. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. adminInfo := this.GetMobileAdminUserInfo()
  300. ch := make(chan struct{})
  301. count := 24 // count 表示活动的协程个数
  302. var patient models.Patients
  303. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  304. var predialysisEvaluation *models.PredialysisEvaluation
  305. var lastPredialysisEvaluation *models.PredialysisEvaluation
  306. var doctorAdvices []*models.DoctorAdvice
  307. var dialysisOrder *models.DialysisOrder
  308. var doubleCheck *models.DoubleCheck
  309. var monitorRecords []*models.MonitoringRecord
  310. var lastMonitorRecord *models.MonitoringRecord
  311. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  312. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  313. var treatmentSummary *models.TreatmentSummary
  314. var dialysisPrescribe *models.DialysisPrescription
  315. var dialysisSolution *models.DialysisSolution
  316. var lastDialysisPrescribe *models.DialysisPrescription
  317. var systemDialysisPrescribe *models.SystemPrescription
  318. var is_project_open_config models.XtHisProjectConfig
  319. var projects []*models.HisPrescriptionProject
  320. var stockType []*models.GoodsTypeOne
  321. var prepare []*models.XtDialysisBeforePrepare
  322. var lastAssessment models.XtPatientVascularAccess
  323. var lastDryWeightDislysis *models.SgjPatientDryweight
  324. var gobalConfig models.GobalConfig
  325. var operators []*models.SgjUserAdminRoles
  326. // 先走redis,没有走数据库
  327. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  328. go func() {
  329. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  330. ch <- struct{}{}
  331. }()
  332. go func() {
  333. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  334. ch <- struct{}{}
  335. }()
  336. go func() {
  337. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  338. ch <- struct{}{}
  339. }()
  340. go func() {
  341. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  342. ch <- struct{}{}
  343. }()
  344. go func() {
  345. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  346. ch <- struct{}{}
  347. }()
  348. go func() {
  349. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  350. ch <- struct{}{}
  351. }()
  352. go func() {
  353. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  354. ch <- struct{}{}
  355. }()
  356. go func() {
  357. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  358. ch <- struct{}{}
  359. }()
  360. go func() {
  361. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  362. ch <- struct{}{}
  363. }()
  364. go func() {
  365. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  366. ch <- struct{}{}
  367. }()
  368. go func() {
  369. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  370. ch <- struct{}{}
  371. }()
  372. go func() {
  373. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  374. ch <- struct{}{}
  375. }()
  376. go func() {
  377. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  378. ch <- struct{}{}
  379. }()
  380. go func() {
  381. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  382. ch <- struct{}{}
  383. }()
  384. go func() {
  385. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  386. ch <- struct{}{}
  387. }()
  388. go func() {
  389. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  390. ch <- struct{}{}
  391. }()
  392. go func() {
  393. // 先走redis,没有走数据库
  394. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. // 先走redis,没有走数据库
  399. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. // // 先走redis,没有走数据库
  404. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  405. ch <- struct{}{}
  406. }()
  407. go func() {
  408. // 先走redis,没有走数据库
  409. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  410. ch <- struct{}{}
  411. }()
  412. go func() {
  413. // //获取最后一次血管通路
  414. // 先走redis,没有走数据库
  415. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // 先走redis,没有走数据库
  425. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  431. ch <- struct{}{}
  432. }()
  433. for range ch {
  434. // 每次从ch中接收数据,表明一个活动的协程结束
  435. count--
  436. // 当所有活动的协程都结束时,关闭管道
  437. if count == 0 {
  438. close(ch)
  439. }
  440. }
  441. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  442. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  443. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  444. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  445. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  446. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  447. var team_projects []*models.HisPrescriptionProject
  448. //var index int64 = 0
  449. for _, item := range temp_team_projects {
  450. //组套里面非检验项目的
  451. if item.HisProject.CostClassify != 3 {
  452. projects = append(projects, item)
  453. }
  454. //组套里面检验项目的
  455. if item.HisProject.CostClassify == 3 {
  456. team_projects = append(team_projects, item)
  457. }
  458. }
  459. team_projects = RemoveRepeatedCheckRecod(team_projects)
  460. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  461. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  462. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. var his_advices []*models.HisDoctorAdviceInfo
  464. if is_open_config.IsOpen == 1 {
  465. // 先走redis,没有走数据库
  466. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  467. }
  468. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  469. if is_advice_open.IsAdviceOpen == 1 {
  470. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  471. }
  472. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  473. returnData := map[string]interface{}{
  474. "patient": patient,
  475. "schedual": schedual,
  476. "prescription": dialysisPrescribe,
  477. "solution": dialysisSolution,
  478. "last_prescription": lastDialysisPrescribe,
  479. "receiver_treatment_access": receiverTreatmentAccess,
  480. "predialysis_evaluation": predialysisEvaluation,
  481. "doctor_advices": doctorAdvices,
  482. "double_check": doubleCheck,
  483. "assessment_after_dislysis": assessmentAfterDislysis,
  484. "treatment_summary": treatmentSummary,
  485. "monitor_records": monitorRecords,
  486. "dialysis_order": dialysisOrder,
  487. "operators": operators,
  488. "last_predialysis_evaluation": lastPredialysisEvaluation,
  489. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  490. "last_monitor_record": lastMonitorRecord,
  491. "config": gobalConfig,
  492. "dry_weight": lastDryWeightDislysis,
  493. "system_prescription": systemDialysisPrescribe,
  494. "his_advices": his_advices,
  495. "is_open_config": is_open_config,
  496. "stockType": stockType,
  497. "prepare": prepare,
  498. "lastAssessment": lastAssessment,
  499. "prescribeOne": prescribeOne,
  500. "is_project_open_config": is_project_open_config,
  501. "project": projects,
  502. "team_projects": team_projects,
  503. "is_advice_open": is_advice_open,
  504. "prescription_open": prescriptionConfig.IsOpen,
  505. "lastOrder": lastOrder,
  506. }
  507. this.ServeSuccessJSON(returnData)
  508. }
  509. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  510. adminInfo := c.GetMobileAdminUserInfo()
  511. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  512. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  513. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  514. returnData := map[string]interface{}{
  515. "admin_users": adminUsers,
  516. "devices": devices,
  517. "device_numbers": device_numbers,
  518. }
  519. c.ServeSuccessJSON(returnData)
  520. }
  521. func (c *DialysisAPIController) PostAtreatmentInfo() {
  522. id, _ := c.GetInt64("patient", 0)
  523. recordDateStr := c.GetString("record_date")
  524. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  525. summaryContent := c.GetString("summaryContent")
  526. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  527. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  528. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  529. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  530. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  531. nursingRecord := c.GetString("nursing_record")
  532. fmt.Println("护理记录", nursingRecord)
  533. specialRecord := c.GetString("special_record")
  534. fmt.Println("特殊记录", specialRecord)
  535. adminUserInfo := c.GetMobileAdminUserInfo()
  536. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  537. checkStaffId = adminUserInfo.AdminUser.Id
  538. deboardNurseId = adminUserInfo.AdminUser.Id
  539. treatDoctor = adminUserInfo.AdminUser.Id
  540. if id <= 0 {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  542. return
  543. }
  544. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  545. if patient.ID == 0 {
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  547. return
  548. }
  549. if len(recordDateStr) == 0 {
  550. recordDateStr = time.Now().Format("2006-01-02")
  551. }
  552. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  553. if parseDateErr != nil {
  554. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  556. return
  557. }
  558. summary := models.TreatmentSummary{
  559. UserOrgId: adminUserInfo.Org.Id,
  560. PatientId: id,
  561. AssessmentDate: recordDate.Unix(),
  562. Mission: propagandaAndEducationContent,
  563. DialysisSummary: summaryContent,
  564. SjNurse: changeMedicalNurseId,
  565. ZlNurse: treatNurseId,
  566. HdNurse: checkStaffId,
  567. XjNurse: deboardNurseId,
  568. ZlDoctor: treatDoctor,
  569. CreatedTime: time.Now().Unix(),
  570. Status: 1,
  571. NursingRecord: nursingRecord,
  572. SpecialRecord: specialRecord,
  573. }
  574. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  575. if treatmentSummary.ID == 0 { //新增
  576. summary.Creater = adminUserInfo.AdminUser.Id
  577. service.AddSigleSummaryRecord(&summary)
  578. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  579. redis := service.RedisClient()
  580. //清空key 值
  581. redis.Set(key, "", time.Second)
  582. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  583. redis.Set(keyOne, "", time.Second)
  584. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  585. redis.Set(keyThree, "", time.Second)
  586. defer redis.Close()
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "summary": summary,
  589. })
  590. } else { //修改
  591. summary.Creater = treatmentSummary.Creater
  592. summary.CreatedTime = treatmentSummary.CreatedTime
  593. summary.Modifier = adminUserInfo.AdminUser.Id
  594. summary.ID = treatmentSummary.ID
  595. service.UpdateSummeRecord(&summary)
  596. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  597. redis := service.RedisClient()
  598. //清空key 值
  599. redis.Set(key, "", time.Second)
  600. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  601. redis.Set(keyOne, "", time.Second)
  602. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  603. redis.Set(keyThree, "", time.Second)
  604. defer redis.Close()
  605. c.ServeSuccessJSON(map[string]interface{}{
  606. "summary": summary,
  607. })
  608. }
  609. }
  610. func (c *DialysisAPIController) PostDoubleCheck() {
  611. id, _ := c.GetInt64("patient", 0)
  612. recordDateStr := c.GetString("record_date")
  613. checkTimeStr := c.GetString("check_time")
  614. firstCheckTimeStr := c.GetString("first_check_time")
  615. creater, _ := c.GetInt64("creater", 0)
  616. modifier, _ := c.GetInt64("modifier", 0)
  617. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  618. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  619. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  620. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  621. dialysis_item_desc := c.GetString("dialysis_item_desc")
  622. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  623. vascular_access_desc := c.GetString("vascular_access_desc")
  624. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  625. collator, _ := c.GetInt64("collator", 0)
  626. employee_number := c.GetString("employee_number")
  627. if id <= 0 {
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  629. return
  630. }
  631. adminUserInfo := c.GetMobileAdminUserInfo()
  632. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  633. if patient.ID == 0 {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  635. return
  636. }
  637. if len(recordDateStr) == 0 {
  638. recordDateStr = time.Now().Format("2006-01-02")
  639. }
  640. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  641. if parseDateErr != nil {
  642. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. var checkDate int64
  647. if len(checkTimeStr) == 0 {
  648. checkDate = 0
  649. } else {
  650. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  651. checkDate = checkDateUnix.Unix()
  652. }
  653. var firstCheckDate int64
  654. if len(firstCheckTimeStr) == 0 {
  655. firstCheckDate = 0
  656. } else {
  657. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  658. firstCheckDate = firstCheckDateUnix.Unix()
  659. }
  660. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  661. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  662. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  663. if check.ID == 0 {
  664. if employee_number != list.JobNumber {
  665. c.ServeSuccessJSON(map[string]interface{}{
  666. "doubleCheck": check,
  667. "msg": "2",
  668. })
  669. return
  670. }
  671. }
  672. if check.ID > 0 {
  673. if employee_number != list.JobNumber {
  674. c.ServeSuccessJSON(map[string]interface{}{
  675. "doubleCheck": check,
  676. "msg": "2",
  677. })
  678. return
  679. }
  680. }
  681. }
  682. doubleCheck := models.DoubleCheck{
  683. UserOrgId: adminUserInfo.Org.Id,
  684. PatientId: id,
  685. DialysisItemCheck: dialysis_item_check,
  686. DialysisParameterCheck: dialysis_parameter_check,
  687. VascularAccessVerification: vascular_access_verification,
  688. PipelineConnectionCheck: pipeline_connection_check,
  689. DialysisItemDesc: dialysis_item_desc,
  690. DialysisParameterDesc: dialysis_parameter_desc,
  691. VascularAccessDesc: vascular_access_desc,
  692. PipelineConnectionDesc: pipeline_connection_desc,
  693. Collator: collator,
  694. Status: 1,
  695. CreatedTime: time.Now().Unix(),
  696. CheckDate: recordDate.Unix(),
  697. UpdatedTime: time.Now().Unix(),
  698. EmployeeNumber: employee_number,
  699. }
  700. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  701. if check.ID == 0 { //新增
  702. doubleCheck.FirstCheckTime = firstCheckDate
  703. doubleCheck.CheckTime = checkDate
  704. doubleCheck.Creater = creater
  705. doubleCheck.Modifier = modifier
  706. err := service.AddSigleDoubleCheck(&doubleCheck)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  708. redis := service.RedisClient()
  709. defer redis.Close()
  710. //清空key 值
  711. redis.Set(key, "", time.Second)
  712. if err == nil {
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "doubleCheck": &doubleCheck,
  715. })
  716. }
  717. } else { //修改
  718. doubleCheck.FirstCheckTime = firstCheckDate
  719. doubleCheck.CheckTime = checkDate
  720. doubleCheck.Creater = creater
  721. doubleCheck.Modifier = modifier
  722. doubleCheck.CreatedTime = check.CreatedTime
  723. doubleCheck.ID = check.ID
  724. doubleCheck.EmployeeNumber = employee_number
  725. err := service.UpdateDoubleCheck(&doubleCheck)
  726. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  727. redis := service.RedisClient()
  728. defer redis.Close()
  729. //清空key 值
  730. redis.Set(key, "", time.Second)
  731. if err == nil {
  732. c.ServeSuccessJSON(map[string]interface{}{
  733. "doubleCheck": &doubleCheck,
  734. "msg": "1",
  735. })
  736. }
  737. }
  738. }
  739. func (c *DialysisAPIController) PostAcceptsAssessment() {
  740. id, _ := c.GetInt64("patient", 0)
  741. recordDateStr := c.GetString("record_date")
  742. way, _ := c.GetInt64("way", 0)
  743. consciousness, _ := c.GetInt64("consciousness", 0)
  744. appetite, _ := c.GetInt64("appetite", 0)
  745. condition, _ := c.GetInt64("condition", 0)
  746. posture, _ := c.GetInt64("posture")
  747. sick_condition, _ := c.GetInt64("sick_condition", 0)
  748. danger_level, _ := c.GetInt64("danger_level", 0)
  749. intake, _ := c.GetInt64("intake", 0)
  750. nutrition, _ := c.GetInt64("nutrition", 0)
  751. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  752. psychological_assessment_other := c.GetString("psychological_assessment_other")
  753. score := c.GetString("score")
  754. sick_condition_other := c.GetString("sick_condition_other")
  755. //precaution, _ := c.GetInt64("precaution", 0)
  756. precaution := c.GetString("precaution")
  757. precaution_other := c.GetString("precaution_other")
  758. psychological_other := c.GetString("psychological_other")
  759. admission_number := c.GetString("admission_number")
  760. tumble, _ := c.GetInt64("tumble")
  761. diacrisis := c.GetString("diacrisis")
  762. his_department := c.GetString("his_department")
  763. his_bed := c.GetString("his_bed")
  764. if id <= 0 {
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. adminUserInfo := c.GetMobileAdminUserInfo()
  769. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  770. if patient.ID == 0 {
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  772. return
  773. }
  774. //now := time.Now()
  775. //year, month, day := now.Date()
  776. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  777. //todayTimeStamp := today_time.Unix()
  778. if len(recordDateStr) == 0 {
  779. recordDateStr = time.Now().Format("2006-01-02")
  780. }
  781. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  782. if parseDateErr != nil {
  783. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  785. return
  786. }
  787. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  788. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  789. UserOrgId: adminUserInfo.Org.Id,
  790. PatientId: id,
  791. RecordDate: recordDate.Unix(),
  792. Way: way,
  793. Consciousness: consciousness,
  794. Appetite: appetite,
  795. Condition: condition,
  796. SickCondition: sick_condition,
  797. DangerLevel: danger_level,
  798. Intake: intake,
  799. Nutrition: nutrition,
  800. PsychologicalAssessment: psychological_assessment,
  801. PsychologicalAssessmentOther: psychological_assessment_other,
  802. SickConditionOther: sick_condition_other,
  803. Posture: posture,
  804. CreatedTime: time.Now().Unix(),
  805. UpdateTime: time.Now().Unix(),
  806. Status: 1,
  807. Score: score,
  808. Precaution: precaution,
  809. PrecautionOther: precaution_other,
  810. PsychologicalOther: psychological_other,
  811. AdmissionNumber: admission_number,
  812. Tumble: tumble,
  813. Diacrisis: diacrisis,
  814. HisBed: his_bed,
  815. HisDepartment: his_department,
  816. }
  817. if receiveTreatment.ID == 0 { //新增
  818. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  819. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  820. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  821. redis := service.RedisClient()
  822. defer redis.Close()
  823. //清空key 值
  824. redis.Set(key, "", time.Second)
  825. if err == nil {
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "receiveTreatmentAsses": receiveTreatmentAsses,
  828. })
  829. }
  830. } else { //修改
  831. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  832. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  833. // if getPermissionErr != nil {
  834. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. // return
  836. // } else if headNursePermission == nil {
  837. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  838. // return
  839. // }
  840. //}
  841. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  842. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  843. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  844. receiveTreatmentAsses.ID = receiveTreatment.ID
  845. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  846. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  847. redis := service.RedisClient()
  848. defer redis.Close()
  849. //清空key 值
  850. redis.Set(key, "", time.Second)
  851. if err == nil {
  852. c.ServeSuccessJSON(map[string]interface{}{
  853. "receiveTreatmentAsses": receiveTreatmentAsses,
  854. })
  855. }
  856. }
  857. }
  858. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  859. id, _ := c.GetInt64("patient", 0)
  860. recordDateStr := c.GetString("record_date")
  861. weightAfter, _ := c.GetFloat("weight_after", 0)
  862. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  863. weightReduce, _ := c.GetFloat("weight_loss", 0)
  864. temperature, _ := c.GetFloat("temperature", 0)
  865. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  866. breathing_rate := c.GetString("breathing_rate")
  867. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  868. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  869. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  870. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  871. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  872. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  873. cruor := c.GetString("cruor")
  874. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  875. internalFistula := c.GetString("internal_fistula")
  876. catheter := c.GetString("catheter")
  877. complications := c.GetString("complication")
  878. remark := c.GetString("remark")
  879. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  880. dialysis_intakes := c.GetString("dialysis_intakes")
  881. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  882. fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
  883. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  884. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  885. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  886. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  887. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  888. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  889. patientGose, _ := c.GetInt64("patient_gose", 0)
  890. inpatientDepartment := c.GetString("inpatient_department")
  891. observationContent := c.GetString("observation_content")
  892. observationContentOther := c.GetString("observation_content_other")
  893. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  894. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  895. in_advance_reason := c.GetString("in_advance_reason")
  896. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  897. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  898. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  899. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  900. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  901. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  902. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  903. dialyzer, _ := c.GetInt64("dialyzer", 0)
  904. in_advance_reason_other := c.GetString("in_advance_reason_other")
  905. is_eat, _ := c.GetInt64("is_eat", 0)
  906. cvc_a, _ := c.GetFloat("cvc_a", 0)
  907. cvc_v, _ := c.GetFloat("cvc_v", 0)
  908. channels, _ := c.GetInt64("channel", 0)
  909. return_blood, _ := c.GetInt64("return_blood", 0)
  910. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  911. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  912. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  913. blood_flow, _ := c.GetInt64("blood_flow", 0)
  914. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  915. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  916. sealing_fluid_special := c.GetString("sealing_fluid_special")
  917. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  918. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  919. setting_pressure := c.GetString("setting_pressure")
  920. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  921. diastolic_pressure := c.GetString("diastolic_pressure")
  922. other_complication := c.GetString("other_complication")
  923. ktv := c.GetString("ktv")
  924. urr := c.GetString("urr")
  925. hypertenison, _ := c.GetInt64("hypertenison")
  926. hypopiesia, _ := c.GetInt64("hypopiesia")
  927. leave_office_method, _ := c.GetInt64("leave_office_method")
  928. lapse, _ := c.GetInt64("lapse")
  929. consciousness, _ := c.GetInt64("consciousness")
  930. fallrisk, _ := c.GetInt64("fallrisk")
  931. machine_run := c.GetString("machine_run")
  932. after_urea := c.GetString("after_urea")
  933. pip_coagulation := c.GetString("pip_coagulation")
  934. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  935. if id <= 0 {
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  937. return
  938. }
  939. adminUserInfo := c.GetMobileAdminUserInfo()
  940. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  941. if patient.ID == 0 {
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  943. return
  944. }
  945. if len(recordDateStr) == 0 {
  946. recordDateStr = time.Now().Format("2006-01-02")
  947. }
  948. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  949. if parseDateErr != nil {
  950. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. //now := time.Now()
  955. //year, month, day := now.Date()
  956. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  957. //todayTimeStamp := today_time.Unix()
  958. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  959. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  960. UserOrgId: adminUserInfo.Org.Id,
  961. PatientId: id,
  962. AssessmentDate: recordDate.Unix(),
  963. Temperature: temperature,
  964. PulseFrequency: pulse_frequency,
  965. BreathingRate: breathing_rate,
  966. SystolicBloodPressure: systolic_blood_pressure,
  967. DiastolicBloodPressure: diastolic_blood_pressure,
  968. ActualUltrafiltration: actual_ultrafiltration,
  969. ActualDisplacement: actual_displacement,
  970. ActualTreatmentHour: actualtreatHour,
  971. ActualTreatmentMinute: actualtreatmin,
  972. WeightAfter: weightAfter,
  973. AdditionalWeight: additionalWeight,
  974. WeightLoss: weightReduce,
  975. Cruor: cruor,
  976. SymptomAfterDialysis: symptomsAfterDialysi,
  977. InternalFistula: internalFistula,
  978. Catheter: catheter,
  979. Complication: complications,
  980. DialysisIntakes: dialysateVolume,
  981. CreatedTime: time.Now().Unix(),
  982. UpdatedTime: time.Now().Unix(),
  983. Status: 1,
  984. Remark: remark,
  985. BloodAccessPartId: blood_access_part_id,
  986. BloodAccessPartOperaId: blood_access_part_opera_id,
  987. DialysisIntakesUnit: dialysis_intakes_unit,
  988. PuncturePointOozingBlood: puncturePointOozingBlood,
  989. PuncturePointHaematoma: puncturePointHaematoma,
  990. InternalFistulaTremorAc: internalFistulaTremorAc,
  991. PatientGose: patientGose,
  992. InpatientDepartment: inpatientDepartment,
  993. ObservationContent: observationContent,
  994. ObservationContentOther: observationContentOther,
  995. DialysisProcess: dialysis_process,
  996. InAdvanceMinute: in_advance_minute,
  997. InAdvanceReason: in_advance_reason,
  998. HemostasisMinute: hemostasis_minute,
  999. HemostasisOpera: hemostasis_opera,
  1000. TremorNoise: tremor_noise,
  1001. DisequilibriumSyndrome: disequilibrium_syndrome,
  1002. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1003. ArterialTube: arterial_tube,
  1004. IntravenousTube: intravenous_tube,
  1005. Dialyzer: dialyzer,
  1006. InAdvanceReasonOther: in_advance_reason_other,
  1007. IsEat: is_eat,
  1008. CvcA: cvc_a,
  1009. CvcV: cvc_v,
  1010. Channel: channels,
  1011. ReturnBlood: return_blood,
  1012. RehydrationVolume: rehydration_volume,
  1013. DialysisDuring: dialysis_during,
  1014. StrokeVolume: stroke_volume,
  1015. BloodFlow: blood_flow,
  1016. SealingFluidDispose: sealing_fluid_dispose,
  1017. SealingFluidSpecial: sealing_fluid_special,
  1018. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1019. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1020. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1021. SettingPressure: setting_pressure,
  1022. DiastolicPressure: diastolic_pressure,
  1023. OtherComplication: other_complication,
  1024. Ktv: ktv,
  1025. Urr: urr,
  1026. Hypopiesia: hypopiesia,
  1027. Hypertenison: hypertenison,
  1028. Lapse: lapse,
  1029. LeaveOfficeMethod: leave_office_method,
  1030. Consciousness: consciousness,
  1031. Fallrisk: fallrisk,
  1032. MachineRun: machine_run,
  1033. AfterUrea: after_urea,
  1034. PipCoagulation: pip_coagulation,
  1035. AccumulatedBloodVolume: accumulated_blood_volume,
  1036. }
  1037. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1038. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1039. if assessmentAfter.ID == 0 { //新增
  1040. if appRole.UserType == 2 || appRole.UserType == 1 {
  1041. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1042. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1043. } else {
  1044. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1045. }
  1046. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1047. redis := service.RedisClient()
  1048. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1049. redis.Set(keyTwo, "", time.Second)
  1050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1051. //清空key 值
  1052. redis.Set(key, "", time.Second)
  1053. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1054. redis.Set(keyOne, "", time.Second)
  1055. defer redis.Close()
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "assessmentAfterDislysis": assessmentAfterDislysis,
  1059. })
  1060. }
  1061. } else { //修改
  1062. if appRole.UserType == 2 || appRole.UserType == 1 {
  1063. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1064. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1065. } else {
  1066. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1067. if assessmentAfterDislysis.Creater == 0 {
  1068. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1069. }
  1070. }
  1071. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1072. assessmentAfterDislysis.ID = assessmentAfter.ID
  1073. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1074. redis := service.RedisClient()
  1075. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1076. redis.Set(keyTwo, "", time.Second)
  1077. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1078. //清空key 值
  1079. redis.Set(key, "", time.Second)
  1080. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1081. redis.Set(keyOne, "", time.Second)
  1082. fmt.Println("err233332323232232323", err)
  1083. if err == nil {
  1084. c.ServeSuccessJSON(map[string]interface{}{
  1085. "assessmentAfterDislysis": assessmentAfterDislysis,
  1086. })
  1087. }
  1088. }
  1089. }
  1090. func (c *DialysisAPIController) PostDialysisPrescription() {
  1091. id, _ := c.GetInt64("patient", 0)
  1092. recordDateStr := c.GetString("record_date")
  1093. if id <= 0 {
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. adminUserInfo := c.GetMobileAdminUserInfo()
  1098. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1099. if patient.ID == 0 {
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1101. return
  1102. }
  1103. if len(recordDateStr) == 0 {
  1104. recordDateStr = time.Now().Format("2006-01-02")
  1105. }
  1106. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1107. if parseDateErr != nil {
  1108. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. mode_id, _ := c.GetInt64("mode_id", 0)
  1113. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1114. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1115. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1116. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1117. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1118. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1119. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1120. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1121. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1122. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1123. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1124. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1125. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1126. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1127. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1128. kalium, _ := c.GetFloat("kalium", 0)
  1129. sodium, _ := c.GetFloat("sodium", 0)
  1130. calcium, _ := c.GetFloat("calcium", 0)
  1131. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1132. glucose, _ := c.GetFloat("glucose", 0)
  1133. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1134. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1135. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1136. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1137. conductivity, _ := c.GetFloat("conductivity", 0)
  1138. remark := c.GetString("remark")
  1139. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1140. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1141. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1142. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1143. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1144. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1145. special_medicine_other := c.GetString("special_medicine_other")
  1146. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1147. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1148. blood_access, _ := c.GetInt64("blood_access", 0)
  1149. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1150. body_fluid_other := c.GetString("body_fluid_other")
  1151. niprocart, _ := c.GetInt64("niprocart", 0)
  1152. jms, _ := c.GetInt64("jms", 0)
  1153. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1154. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1155. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1156. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1157. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1158. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1159. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1160. injector, _ := c.GetInt64("injector", 0)
  1161. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1162. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1163. safe_package, _ := c.GetInt64("package", 0)
  1164. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1165. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1166. fmt.Println("预冲量", pre_impulse)
  1167. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1168. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1169. blood := c.GetString("blood")
  1170. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1171. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1172. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1173. displace_speed := c.GetString("displace_speed")
  1174. illness, _ := c.GetInt64("illness")
  1175. amylaceum := c.GetString("amylaceum")
  1176. single_time := c.GetString("single_time")
  1177. single_water := c.GetString("single_water")
  1178. replacement_flow := c.GetString("replacement_flow")
  1179. plasma_separator := c.GetString("plasma_separator")
  1180. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1181. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1182. oxygen_flow := c.GetString("oxygen_flow")
  1183. oxygen_time := c.GetString("oxygen_time")
  1184. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1185. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1186. puncture_needle := c.GetString("puncture_needle")
  1187. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1188. epo := c.GetString("epo")
  1189. epo_count, _ := c.GetFloat("epo_count", 0)
  1190. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1191. admin_user_id, _ := c.GetInt64("admin_user_id")
  1192. is_water := c.GetString("is_water")
  1193. var is_war int64
  1194. if is_water == "是" {
  1195. is_war = 1
  1196. }
  1197. if is_water == "否" {
  1198. is_war = 2
  1199. }
  1200. if is_water == "请选择" {
  1201. is_war = 0
  1202. }
  1203. drhy_water := c.GetString("drhy_water")
  1204. dry_water_hour := c.GetString("dry_water_hour")
  1205. water_machine := c.GetString("water_machine")
  1206. add_amount, _ := c.GetFloat("add_amount")
  1207. reduce_amount, _ := c.GetFloat("reduce_amount")
  1208. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1209. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1210. //
  1211. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1212. // if appRole.UserType == 3 {
  1213. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1214. // if getPermissionErr != nil {
  1215. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1216. // return
  1217. // } else if headNursePermission == nil {
  1218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1219. // return
  1220. // }
  1221. // }
  1222. //}
  1223. //TODO 需要根据角色去判断
  1224. prescription := models.DialysisPrescription{
  1225. UserOrgId: adminUserInfo.Org.Id,
  1226. PatientId: id,
  1227. RecordDate: recordDate.Unix(),
  1228. ModeId: mode_id,
  1229. DialysisDuration: dialysis_duration,
  1230. Dialyzer: dialyzer,
  1231. PerfusionApparatus: perfusion_apparatus,
  1232. BloodFlowVolume: blood_flow_volume,
  1233. DewaterAmount: dewater_amount,
  1234. DisplaceLiqui: displace_liqui,
  1235. ReplacementWay: replacement_way,
  1236. Anticoagulant: anticoagulant,
  1237. AnticoagulantShouji: anticoagulant_shouji,
  1238. AnticoagulantWeichi: anticoagulant_weichi,
  1239. AnticoagulantZongliang: anticoagulant_zongliang,
  1240. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1241. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1242. Kalium: kalium,
  1243. Sodium: sodium,
  1244. Calcium: calcium,
  1245. Bicarbonate: bicarbonate,
  1246. Glucose: glucose,
  1247. // DryWeight: dry_weight,
  1248. DialysateFlow: dialysate_flow,
  1249. DialysateTemperature: dialysate_temperature,
  1250. // PrescriptionDoctor: prescription_doctor,
  1251. ReplacementTotal: replacement_total,
  1252. Conductivity: conductivity,
  1253. Remark: remark,
  1254. Status: 1,
  1255. CreatedTime: time.Now().Unix(),
  1256. UpdatedTime: time.Now().Unix(),
  1257. DialysisDurationMinute: dialysisDurationMinute,
  1258. DialysisDurationHour: dialysisDurationHour,
  1259. TargetUltrafiltration: targetUltrafiltration,
  1260. DialysateFormulation: dialysateFormulation,
  1261. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1262. BodyFluid: body_fluid,
  1263. SpecialMedicine: special_medicine,
  1264. SpecialMedicineOther: special_medicine_other,
  1265. DisplaceLiquiPart: displace_liqui_part,
  1266. DisplaceLiquiValue: displace_liqui_value,
  1267. BloodAccess: blood_access,
  1268. Ultrafiltration: ultrafiltration,
  1269. BodyFluidOther: body_fluid_other,
  1270. Niprocart: niprocart,
  1271. Jms: jms,
  1272. FistulaNeedleSet: fistula_needle_set,
  1273. FistulaNeedleSet16: fistula_needle_set_16,
  1274. Hemoperfusion: hemoperfusion,
  1275. DialyserSterilised: dialyser_sterilised,
  1276. Filtryzer: filtryzer,
  1277. Dialyzers: dialyzers,
  1278. Injector: injector,
  1279. Bloodlines: bloodlines,
  1280. TubingHemodialysis: tubing_hemodialysis,
  1281. Package: safe_package,
  1282. ALiquid: a_liquid,
  1283. TargetKtv: target_ktv,
  1284. PreImpulse: pre_impulse,
  1285. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1286. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1287. Blood: blood,
  1288. DialysisDialyszers: dialysis_dialyszers,
  1289. DialysisIrrigation: dialysis_irrigation,
  1290. AntioxidantCommodityName: antioxidant_commodity_name,
  1291. DisplaceSpeed: displace_speed,
  1292. Illness: illness,
  1293. Amylaceum: amylaceum,
  1294. SingleTime: single_time,
  1295. SingleWater: single_water,
  1296. ReplacementFlow: replacement_flow,
  1297. PlasmaSeparator: plasma_separator,
  1298. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1299. OxygenUptake: oxygen_uptake,
  1300. OxygenFlow: oxygen_flow,
  1301. OxygenTime: oxygen_time,
  1302. HemodialysisPipelines: hemodialysis_pipelines,
  1303. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1304. PunctureNeedle: puncture_needle,
  1305. PunctureNeedleCount: puncture_needle_count,
  1306. Epo: epo,
  1307. EpoCount: epo_count,
  1308. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1309. AdminUserId: admin_user_id,
  1310. IsWater: is_war,
  1311. DrhyWater: drhy_water,
  1312. DryWaterHour: dry_water_hour,
  1313. WaterMachine: water_machine,
  1314. AddAmount: add_amount,
  1315. ReduceAmount: reduce_amount,
  1316. }
  1317. //查询最近透析准备表里是否存在 透析器 灌流器
  1318. //
  1319. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1320. //
  1321. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1322. //
  1323. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1324. //if len(mation)>0{
  1325. // for _, item := range splitStr {
  1326. // for _,it := range mation{
  1327. // if(item == it.SpecificationName){
  1328. //
  1329. // //查询最近一次的透析器
  1330. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1331. //
  1332. // if errcode == gorm.ErrRecordNotFound{
  1333. // //插入数据
  1334. // prepare := models.DialysisBeforePrepare{
  1335. // UserOrgId: adminUserInfo.Org.Id,
  1336. // PatientId: id,
  1337. // RecordDate: recordDate.Unix(),
  1338. // GoodTypeId: it.GoodTypeId,
  1339. // GoodId: it.ID,
  1340. // Count: 1,
  1341. // Ctime: time.Now().Unix(),
  1342. // Creater: adminUserInfo.AdminUser.Id,
  1343. // Status:1,
  1344. //
  1345. // }
  1346. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1347. // fmt.Println("",errcode)
  1348. // }
  1349. // }
  1350. // }
  1351. //
  1352. // }
  1353. //
  1354. // for _, item := range splitIrrigation {
  1355. // for _,it := range mation{
  1356. // if(item == it.SpecificationName){
  1357. // //查询最近一次的透析器
  1358. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1359. // if errcode == gorm.ErrRecordNotFound{
  1360. // //插入数据
  1361. // prepare := models.DialysisBeforePrepare{
  1362. // UserOrgId: adminUserInfo.Org.Id,
  1363. // PatientId: id,
  1364. // RecordDate: recordDate.Unix(),
  1365. // GoodTypeId: it.GoodTypeId,
  1366. // GoodId: it.ID,
  1367. // Count: 1,
  1368. // Ctime: time.Now().Unix(),
  1369. // Creater: adminUserInfo.AdminUser.Id,
  1370. // Status:1,
  1371. //
  1372. // }
  1373. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1374. // fmt.Println(errcode)
  1375. // }
  1376. // }
  1377. // }
  1378. // }
  1379. //}
  1380. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1381. if dialysisPrescription.ID == 0 { //新增
  1382. if appRole.UserType == 2 || appRole.UserType == 1 {
  1383. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1384. }
  1385. prescription.Creater = adminUserInfo.AdminUser.Id
  1386. //针对河间咸得
  1387. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1388. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1389. prescription.DisplaceLiquiPart = 0
  1390. prescription.DisplaceLiquiValue = 0
  1391. }
  1392. }
  1393. err := service.AddSigleRecord(&prescription)
  1394. //获取key,清空redis
  1395. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1396. redis := service.RedisClient()
  1397. //清空key 值
  1398. redis.Set(key, "", time.Second)
  1399. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1400. //清空key 值
  1401. redis.Set(keyOne, "", time.Second)
  1402. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1403. //清空key 值
  1404. redis.Set(keyTwo, "", time.Second)
  1405. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1406. redis.Set(keySix, "", time.Second)
  1407. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1408. redis.Set(keySeven, "", time.Second)
  1409. if err == nil {
  1410. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1411. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1412. //清空key 值
  1413. redis.Set(keyThree, "", time.Second)
  1414. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1415. //清空key 值
  1416. redis.Set(keyFour, "", time.Second)
  1417. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1418. redis.Set(keyFive, "", time.Second)
  1419. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1420. redis.Set(keySix, "", time.Second)
  1421. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1422. redis.Set(keySeven, "", time.Second)
  1423. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1424. //清空key 值
  1425. redis.Set(keyOne, "", time.Second)
  1426. if updateErr != nil {
  1427. utils.ErrorLog("%v", updateErr)
  1428. }
  1429. defer redis.Close()
  1430. c.ServeSuccessJSON(map[string]interface{}{
  1431. "prescription": prescription,
  1432. })
  1433. }
  1434. } else { //修改
  1435. //if mode_id > 0 {
  1436. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1437. //}
  1438. //if template.TemplateId == 1 {
  1439. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1440. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1441. // if getPermissionErr != nil {
  1442. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1443. // return
  1444. // } else if headNursePermission == nil {
  1445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1446. // return
  1447. // }
  1448. // }
  1449. //}
  1450. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1451. prescription.Modifier = adminUserInfo.AdminUser.Id
  1452. if appRole.UserType == 2 || appRole.UserType == 1 {
  1453. prescription_doctor := adminUserInfo.AdminUser.Id
  1454. prescription.PrescriptionDoctor = prescription_doctor
  1455. } else {
  1456. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1457. }
  1458. if dialysisPrescription.Creater == 0 { //体重称
  1459. prescription.Creater = adminUserInfo.AdminUser.Id
  1460. } else {
  1461. prescription.Creater = dialysisPrescription.Creater
  1462. }
  1463. prescription.ID = dialysisPrescription.ID
  1464. err := service.UpDateDialysisPrescription(&prescription)
  1465. //获取key,清空redis
  1466. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1467. redis := service.RedisClient()
  1468. //清空key 值
  1469. redis.Set(key, "", time.Second)
  1470. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1471. //清空key 值
  1472. redis.Set(keyOne, "", time.Second)
  1473. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1474. redis.Set(keySix, "", time.Second)
  1475. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1476. redis.Set(keySeven, "", time.Second)
  1477. if err == nil {
  1478. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1479. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1480. //清空key 值
  1481. redis.Set(keyOne, "", time.Second)
  1482. defer redis.Close()
  1483. if updateErr != nil {
  1484. utils.ErrorLog("%v", updateErr)
  1485. }
  1486. c.ServeSuccessJSON(map[string]interface{}{
  1487. "prescription": prescription,
  1488. })
  1489. }
  1490. }
  1491. }
  1492. func (c *DialysisAPIController) Finish() {
  1493. id, _ := c.GetInt64("patient", 0)
  1494. recordDateStr := c.GetString("record_date")
  1495. nurseID, _ := c.GetInt64("nurse")
  1496. end_time := c.GetString("end_time")
  1497. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1498. internal_fistula := c.GetString("blood_access_internal_fistula")
  1499. catheter := c.GetString("catheter")
  1500. cruor := c.GetString("cruor")
  1501. mission := c.GetString("mission")
  1502. if id <= 0 || nurseID <= 0 {
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1504. return
  1505. }
  1506. adminUserInfo := c.GetMobileAdminUserInfo()
  1507. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1508. if patient.ID == 0 {
  1509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1510. return
  1511. }
  1512. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1513. if getNurseErr != nil {
  1514. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1516. return
  1517. } else if nurse == nil {
  1518. c.ErrorLog("护士不存在")
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1520. return
  1521. }
  1522. if len(recordDateStr) == 0 {
  1523. recordDateStr = time.Now().Format("2006-01-02")
  1524. }
  1525. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1526. if parseDateErr != nil {
  1527. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1529. return
  1530. }
  1531. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1532. if parseEndDateErr != nil {
  1533. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1535. return
  1536. }
  1537. //now := time.Now()
  1538. //year, month, day := now.Date()
  1539. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1540. //todayTimeStamp := today_time.Unix()
  1541. // 获取当天的第一条透析纪录
  1542. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1543. if getMonitorRecordsErr != nil {
  1544. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1546. return
  1547. }
  1548. // 获取当前的最后一条透析纪录
  1549. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1550. if getMonitorRecordsErr != nil {
  1551. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1553. return
  1554. }
  1555. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1556. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1557. if getAADErr != nil {
  1558. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1560. return
  1561. }
  1562. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1563. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1564. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1565. if assessmentAfterDislysis != nil {
  1566. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1567. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1568. } else {
  1569. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1570. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1571. tempassessmentAfterDislysis.Status = 1
  1572. tempassessmentAfterDislysis.PatientId = id
  1573. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1574. }
  1575. //长沙南雅
  1576. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  1577. //获取最后一条透析处方数据
  1578. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1579. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1580. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1581. }
  1582. if dialysisOrder.Stage == 1 {
  1583. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1584. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1585. fmt.Println(value)
  1586. a, b := math.Modf(value)
  1587. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1588. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1589. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1590. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1591. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1592. }
  1593. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1594. //var num1 int64
  1595. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1596. //fmt.Println(num1)
  1597. //sub := float64(num1 / 3600)
  1598. //fmt.Println(sub)
  1599. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1600. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1601. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1602. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1603. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1604. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1605. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1606. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1607. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1608. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1609. }
  1610. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 {
  1611. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1612. if evaluation.SystolicBloodPressure == 0 {
  1613. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  1614. pre := models.PredialysisEvaluation{
  1615. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  1616. }
  1617. fmt.Println("prew", pre)
  1618. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1620. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1621. redis := service.RedisClient()
  1622. redis.Set(key, "", time.Second)
  1623. redis.Set(keyOne, "", time.Second)
  1624. defer redis.Close()
  1625. fmt.Println(getNurseErr)
  1626. }
  1627. if evaluation.DiastolicBloodPressure == 0 {
  1628. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  1629. pres := models.PredialysisEvaluation{
  1630. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  1631. }
  1632. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1633. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1634. redis := service.RedisClient()
  1635. redis.Set(key, "", time.Second)
  1636. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1637. redis.Set(keyOne, "", time.Second)
  1638. defer redis.Close()
  1639. fmt.Println(getNurseErr)
  1640. }
  1641. if evaluation.PulseFrequency == 0 {
  1642. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1643. press := models.PredialysisEvaluation{
  1644. PulseFrequency: evaluation.PulseFrequency,
  1645. }
  1646. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1648. redis := service.RedisClient()
  1649. redis.Set(key, "", time.Second)
  1650. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1651. redis.Set(keyOne, "", time.Second)
  1652. defer redis.Close()
  1653. fmt.Println(getNurseErr)
  1654. }
  1655. if evaluation.Temperature == 0 {
  1656. evaluation.Temperature = fmonitorRecords.Temperature
  1657. press := models.PredialysisEvaluation{
  1658. Temperature: evaluation.Temperature,
  1659. }
  1660. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1661. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1662. redis := service.RedisClient()
  1663. redis.Set(key, "", time.Second)
  1664. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1665. redis.Set(keyOne, "", time.Second)
  1666. defer redis.Close()
  1667. fmt.Println(getNurseErr)
  1668. }
  1669. }
  1670. if adminUserInfo.Org.Id == 9583 {
  1671. //获取透析处方的最后一条数据
  1672. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1673. if diaerr != nil {
  1674. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1676. return
  1677. }
  1678. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1679. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1680. }
  1681. }
  1682. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  1683. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1684. }
  1685. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  1686. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1687. }
  1688. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1689. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1690. }
  1691. if lastAssessmentAfterDislysis != nil {
  1692. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1693. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1694. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1695. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1696. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1697. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1698. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1699. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1700. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1701. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1702. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1703. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1704. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1705. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1706. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1707. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1708. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1709. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1710. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1711. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1712. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1713. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1714. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1715. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1716. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1717. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1718. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1719. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1720. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1721. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1722. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1723. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1724. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1725. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1726. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1727. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1728. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1729. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1730. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1731. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1732. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1733. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1734. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1735. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1736. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1737. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1738. }
  1739. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1740. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1741. redis := service.RedisClient()
  1742. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1743. redis.Set(keyOne, "", time.Second)
  1744. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  1745. redis.Set(keyTwo, "", time.Second)
  1746. defer redis.Close()
  1747. //清空key 值
  1748. redis.Set(key, "", time.Second)
  1749. if err != nil {
  1750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1751. return
  1752. }
  1753. if dialysisOrder == nil {
  1754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1755. return
  1756. }
  1757. if dialysisOrder.Stage == 2 {
  1758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1759. return
  1760. }
  1761. if dialysisOrder.Stage == 1 {
  1762. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1763. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1764. redis := service.RedisClient()
  1765. defer redis.Close()
  1766. //清空key 值
  1767. redis.Set(key, "", time.Second)
  1768. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1769. redis.Set(keyOne, "", time.Second)
  1770. //结束时候透析次数加1
  1771. service.UpdateSolutionByPatientId(id)
  1772. dialysisOrder.Stage = 2
  1773. dialysisOrder.FinishNurse = nurseID
  1774. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1775. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1776. dialysisOrder.EndTime = endDate.Unix()
  1777. go func() {
  1778. ssoDomain := beego.AppConfig.String("call_domain")
  1779. api := ssoDomain + "/index/downpatient"
  1780. values := make(url.Values)
  1781. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1782. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1783. values.Set("patient_id", strconv.FormatInt(id, 10))
  1784. http.PostForm(api, values)
  1785. }()
  1786. if err == nil {
  1787. c.ServeSuccessJSON(map[string]interface{}{
  1788. "dialysisOrder": dialysisOrder,
  1789. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1790. })
  1791. } else {
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1793. }
  1794. }
  1795. }
  1796. func (c *DialysisAPIController) GetAllZone() {
  1797. adminUserInfo := c.GetMobileAdminUserInfo()
  1798. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1799. if err == nil {
  1800. c.ServeSuccessJSON(map[string]interface{}{
  1801. "zone": zone,
  1802. })
  1803. }
  1804. }
  1805. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1806. adminUserInfo := c.GetMobileAdminUserInfo()
  1807. page, _ := c.GetInt64("page", 1)
  1808. limit, _ := c.GetInt64("limit", 10)
  1809. schedulType, _ := c.GetInt64("schedul_type", 0)
  1810. startTime, _ := c.GetInt64("schedul_time", 0)
  1811. partitionType, _ := c.GetInt64("partition_type", 0)
  1812. keywords := c.GetString("keywords")
  1813. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1814. if err == nil {
  1815. c.ServeSuccessJSON(map[string]interface{}{
  1816. "schedule": dialysisSchedule,
  1817. })
  1818. }
  1819. return
  1820. }
  1821. // /m/api/dialysis/start [post]
  1822. // @param patient_id:int
  1823. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1824. // @param nurse:int 上机护士
  1825. // @param bed:int 床位号
  1826. func (this *DialysisAPIController) StartDialysis() {
  1827. patientID, _ := this.GetInt64("patient_id")
  1828. recordDateStr := this.GetString("record_date")
  1829. nurseID, _ := this.GetInt64("nurse")
  1830. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1831. blood_drawing, _ := this.GetInt64("blood_drawing")
  1832. schedual_type, _ := this.GetInt64("schedual_type")
  1833. bedID, _ := this.GetInt64("bed")
  1834. start_time := this.GetString("start_time")
  1835. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1836. change_nurse, _ := this.GetInt64("change_nurse")
  1837. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1838. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1839. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  1840. puncture_needle := this.GetString("puncture_needle")
  1841. puncture_way := this.GetString("puncture_way")
  1842. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1843. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1844. blood_access_id, _ := this.GetInt64("blood_access_id")
  1845. zone_id, _ := this.GetInt64("zone_id")
  1846. elecsign := this.GetString("url")
  1847. nuclein_date_str := this.GetString("nuclein_date_str")
  1848. schedule_remark := this.GetString("schedule_remark")
  1849. order_remark := this.GetString("order_remark")
  1850. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1852. return
  1853. }
  1854. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1855. if parseStartDateErr != nil {
  1856. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1858. return
  1859. }
  1860. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1861. if parseErr != nil {
  1862. this.ErrorLog("时间解析失败:%v", parseErr)
  1863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1864. return
  1865. }
  1866. adminUserInfo := this.GetMobileAdminUserInfo()
  1867. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1868. if getPatientErr != nil {
  1869. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1871. return
  1872. } else if patient == nil {
  1873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1874. return
  1875. }
  1876. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1877. if getNurseErr != nil {
  1878. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1880. return
  1881. } else if nurse == nil {
  1882. this.ErrorLog("护士不存在")
  1883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1884. return
  1885. }
  1886. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1887. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1888. if getDeviceNumberErr != nil {
  1889. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1891. return
  1892. } else if deviceNumber == nil {
  1893. this.ErrorLog("床位号不存在")
  1894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1898. if getRecordErr != nil {
  1899. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1901. return
  1902. } else if dialysisRecord != nil {
  1903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1904. return
  1905. }
  1906. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1907. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1908. timeLayout := "2006-01-02 15:04:05"
  1909. loc, _ := time.LoadLocation("Local")
  1910. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1911. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1912. schedulestartTime := theStartTime.Unix()
  1913. scheduleendTime := theEndTime.Unix()
  1914. var theNucleinDate int64
  1915. timeLayoutOne := "2006-01-02"
  1916. if len(nuclein_date_str) > 0 {
  1917. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  1918. if err != nil {
  1919. utils.ErrorLog(err.Error())
  1920. }
  1921. theNucleinDate = theTime.Unix()
  1922. }
  1923. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1924. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1925. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1926. //查询该床位是否有人用了
  1927. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1928. if err == gorm.ErrRecordNotFound { //空床位
  1929. // 修改了床位逻辑
  1930. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1931. if daySchedule.ID > 0 {
  1932. daySchedule.PartitionId = deviceNumber.ZoneID
  1933. daySchedule.BedId = bedID
  1934. daySchedule.ScheduleType = schedual_type
  1935. daySchedule.UpdatedTime = time.Now().Unix()
  1936. xtSchedule := models.Schedule{
  1937. PartitionId: deviceNumber.ZoneID,
  1938. BedId: bedID,
  1939. ScheduleType: schedual_type,
  1940. UpdatedTime: time.Now().Unix(),
  1941. }
  1942. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1943. if err != nil {
  1944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1945. return
  1946. }
  1947. }
  1948. } else if err == nil {
  1949. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1950. if order_err == nil {
  1951. if order.ID > 0 { //该机位被其他人占用了
  1952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1953. return
  1954. } else {
  1955. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1956. if daySchedule.ID > 0 {
  1957. //daySchedule.PartitionId = deviceNumber.ZoneID
  1958. //daySchedule.BedId = bedID
  1959. //daySchedule.ScheduleType = schedual_type
  1960. //daySchedule.UpdatedTime = time.Now().Unix()
  1961. //err := service.UpdateSchedule(&daySchedule)
  1962. xtSchedule := models.Schedule{
  1963. PartitionId: deviceNumber.ZoneID,
  1964. BedId: bedID,
  1965. ScheduleType: schedual_type,
  1966. UpdatedTime: time.Now().Unix(),
  1967. }
  1968. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1969. if err != nil {
  1970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1971. return
  1972. }
  1973. }
  1974. }
  1975. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1976. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1977. if daySchedule.ID > 0 {
  1978. //daySchedule.PartitionId = deviceNumber.ZoneID
  1979. //daySchedule.BedId = bedID
  1980. //daySchedule.ScheduleType = schedual_type
  1981. //daySchedule.UpdatedTime = time.Now().Unix()
  1982. //err := service.UpdateSchedule(&daySchedule)
  1983. xtSchedule := models.Schedule{
  1984. PartitionId: deviceNumber.ZoneID,
  1985. BedId: bedID,
  1986. ScheduleType: schedual_type,
  1987. UpdatedTime: time.Now().Unix(),
  1988. }
  1989. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1990. if err != nil {
  1991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1992. return
  1993. }
  1994. }
  1995. }
  1996. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1998. return
  1999. }
  2000. } else if err != nil {
  2001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2002. return
  2003. }
  2004. dialysisRecord = &models.DialysisOrder{
  2005. DialysisDate: recordDate.Unix(),
  2006. UserOrgId: adminUserInfo.Org.Id,
  2007. PatientId: patientID,
  2008. Stage: 1,
  2009. BedID: bedID,
  2010. StartNurse: nurseID,
  2011. Status: 1,
  2012. StartTime: startDate.Unix(),
  2013. CreatedTime: time.Now().Unix(),
  2014. UpdatedTime: time.Now().Unix(),
  2015. PunctureNurse: puncture_nurse,
  2016. Creator: adminUserInfo.AdminUser.Id,
  2017. Modifier: adminUserInfo.AdminUser.Id,
  2018. SchedualType: schedual_type,
  2019. WashpipeNurse: washpipe_nurse,
  2020. ChangeNurse: change_nurse,
  2021. DifficultPunctureNurse: difficult_puncture_nurse,
  2022. NewFistulaNurse: new_fistula_nurse,
  2023. ZoneId: zone_id,
  2024. QualityNurseId: quality_nurse_id,
  2025. PunctureNeedle: puncture_needle,
  2026. PunctureWay: puncture_way,
  2027. DialysisIrrigation: dialysis_irrigation,
  2028. DialysisDialyszers: dialysis_dialyszers,
  2029. BloodAccessId: blood_access_id,
  2030. Url: elecsign,
  2031. NucleinDate: theNucleinDate,
  2032. ScheduleRemark: schedule_remark,
  2033. OrderRemark: order_remark,
  2034. }
  2035. //查询该床位是否有人用了
  2036. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2037. if errorscode == gorm.ErrRecordNotFound {
  2038. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2039. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2040. redis := service.RedisClient()
  2041. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2042. redis.Set(key, "", time.Second)
  2043. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2044. //清空key 值
  2045. redis.Set(keyOne, "", time.Second)
  2046. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2047. //清空key 值
  2048. redis.Set(keyTwo, "", time.Second)
  2049. if createErr != nil {
  2050. this.ErrorLog("上机失败:%v", createErr)
  2051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2052. return
  2053. }
  2054. }
  2055. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2056. var tempdispose string
  2057. // 只针对中能建
  2058. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2059. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2060. }
  2061. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2062. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2063. }
  2064. var ultrafiltration_rate float64
  2065. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2066. //后期预增脱水量
  2067. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2068. if prescription.ID > 0 {
  2069. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2070. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2071. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2072. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2073. }
  2074. //针对医师汇
  2075. if adminUserInfo.Org.Id == 10121 {
  2076. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2077. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2078. }
  2079. //针对通道
  2080. if adminUserInfo.Org.Id == 10234 {
  2081. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2082. }
  2083. //针对监利大垸医院
  2084. if template.TemplateId == 41 {
  2085. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2086. }
  2087. //针对肇庆三鹤血液透析中心
  2088. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
  2089. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2090. }
  2091. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2092. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2093. }
  2094. // 只针对方济医院
  2095. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2096. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2097. ultrafiltration_rate = value
  2098. }
  2099. }
  2100. }
  2101. record := models.MonitoringRecord{
  2102. UserOrgId: adminUserInfo.Org.Id,
  2103. PatientId: patientID,
  2104. DialysisOrderId: dialysisRecord.ID,
  2105. MonitoringDate: schedulestartTime,
  2106. OperateTime: startDate.Unix(),
  2107. // MonitoringTime: recordTime,
  2108. MonitoringNurse: nurseID,
  2109. Dispose: tempdispose,
  2110. UltrafiltrationRate: ultrafiltration_rate,
  2111. UltrafiltrationVolume: 0,
  2112. Status: 1,
  2113. CreatedTime: time.Now().Unix(),
  2114. UpdatedTime: time.Now().Unix(),
  2115. }
  2116. //只针对广慈医院
  2117. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 {
  2118. // 查询病人是否有透前评估数据
  2119. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2120. //如果有数据就插入
  2121. if errcode == nil {
  2122. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2123. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2124. record.BreathingRate = befor.BreathingRate
  2125. record.PulseFrequency = befor.PulseFrequency
  2126. record.Temperature = befor.Temperature
  2127. }
  2128. }
  2129. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2130. if newdialysisRecord.ID > 0 {
  2131. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 {
  2132. record.Temperature = 36.5
  2133. record.ArterialPressure = -100
  2134. record.DialysateTemperature = 36.5
  2135. record.Conductivity = 14
  2136. record.BreathingRate = "20"
  2137. record.VenousPressure = 80
  2138. record.TransmembranePressure = 60
  2139. }
  2140. //针对兰溪人民医院的需求
  2141. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2142. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2143. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2144. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2145. record.Temperature = befor.Temperature
  2146. record.PulseFrequency = befor.PulseFrequency
  2147. record.BreathingRate = befor.BreathingRate
  2148. }
  2149. err := service.CreateMonitor(&record)
  2150. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2151. redis := service.RedisClient()
  2152. //清空key 值
  2153. redis.Set(key, "", time.Second)
  2154. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2155. redis.Set(keyOne, "", time.Second)
  2156. defer redis.Close()
  2157. if err != nil {
  2158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2159. return
  2160. }
  2161. }
  2162. go func() {
  2163. ssoDomain := beego.AppConfig.String("call_domain")
  2164. api := ssoDomain + "/index/uppatient"
  2165. values := make(url.Values)
  2166. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2167. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2168. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2169. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2170. http.PostForm(api, values)
  2171. }()
  2172. this.ServeSuccessJSON(map[string]interface{}{
  2173. "dialysis_order": newdialysisRecord,
  2174. "monitor": record,
  2175. })
  2176. return
  2177. }
  2178. func (c *DialysisAPIController) PostSolution() {
  2179. id, _ := c.GetInt64("patient", 0)
  2180. recordDateStr := c.GetString("record_date")
  2181. if id <= 0 {
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2183. return
  2184. }
  2185. adminUserInfo := c.GetMobileAdminUserInfo()
  2186. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2187. if patient.ID == 0 {
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2189. return
  2190. }
  2191. if len(recordDateStr) == 0 {
  2192. recordDateStr = time.Now().Format("2006-01-02")
  2193. }
  2194. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2195. if parseDateErr != nil {
  2196. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2198. return
  2199. }
  2200. mode_id, _ := c.GetInt64("mode_id", 0)
  2201. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2202. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2203. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2204. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2205. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2206. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2207. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2208. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  2209. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  2210. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  2211. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  2212. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  2213. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  2214. kalium, _ := c.GetFloat("kalium", 0)
  2215. sodium, _ := c.GetFloat("sodium", 0)
  2216. calcium, _ := c.GetFloat("calcium", 0)
  2217. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  2218. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  2219. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  2220. glucose, _ := c.GetFloat("glucose", 0)
  2221. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  2222. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2223. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2224. conductivity, _ := c.GetFloat("conductivity", 0)
  2225. remark := c.GetString("remark")
  2226. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  2227. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  2228. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  2229. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  2230. body_fluid, _ := c.GetInt64("body_fluid", 0)
  2231. special_medicine, _ := c.GetInt64("special_medicine", 0)
  2232. special_medicine_other := c.GetString("special_medicine_other")
  2233. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  2234. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  2235. blood_access, _ := c.GetInt64("blood_access", 0)
  2236. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  2237. body_fluid_other := c.GetString("body_fluid_other")
  2238. replacement_total, _ := c.GetFloat("replacement_total", 0)
  2239. niprocart, _ := c.GetInt64("niprocart", 0)
  2240. jms, _ := c.GetInt64("jms", 0)
  2241. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  2242. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  2243. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  2244. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  2245. filtryzer, _ := c.GetInt64("filtryzer", 0)
  2246. target_ktv, _ := c.GetFloat("target_ktv", 0)
  2247. dialyzers, _ := c.GetInt64("dialyzers", 0)
  2248. injector, _ := c.GetInt64("injector", 0)
  2249. bloodlines, _ := c.GetInt64("bloodlines", 0)
  2250. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  2251. safe_package, _ := c.GetInt64("package", 0)
  2252. a_liquid, _ := c.GetInt64("a_liquid", 0)
  2253. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  2254. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  2255. blood := c.GetString("blood")
  2256. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  2257. dialysis_irrigation := c.GetString("dialysis_irrigation")
  2258. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  2259. displace_speed := c.GetString("displace_speed")
  2260. illness, _ := c.GetInt64("illness")
  2261. amylaceum := c.GetString("amylaceum")
  2262. single_time := c.GetString("single_time")
  2263. single_water := c.GetString("single_water")
  2264. replacement_flow := c.GetString("replacement_flow")
  2265. plasma_separator := c.GetString("plasma_separator")
  2266. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  2267. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  2268. oxygen_flow := c.GetString("oxygen_flow")
  2269. oxygen_time := c.GetString("oxygen_time")
  2270. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  2271. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  2272. puncture_needle := c.GetString("puncture_needle")
  2273. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  2274. epo := c.GetString("epo")
  2275. epo_count, _ := c.GetFloat("epo_count", 0)
  2276. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  2277. pre_impulse := c.GetString("pre_impulse")
  2278. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  2279. admin_user_id, _ := c.GetInt64("admin_user_id")
  2280. is_water := c.GetString("is_water")
  2281. add_amount, _ := c.GetFloat("add_amount")
  2282. reduce_amount, _ := c.GetFloat("reduce_amount")
  2283. var is_war int64
  2284. if is_water == "是" {
  2285. is_war = 1
  2286. }
  2287. if is_water == "否" {
  2288. is_war = 2
  2289. }
  2290. if is_water == "请选择" {
  2291. is_war = 0
  2292. }
  2293. drhy_water := c.GetString("drhy_water")
  2294. dry_water_hour := c.GetString("dry_water_hour")
  2295. water_machine := c.GetString("water_machine")
  2296. if mode_id > 0 {
  2297. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2298. }
  2299. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2300. //
  2301. //if template.TemplateId == 2 || template.TemplateId == 6 {
  2302. // if appRole.UserType == 3 {
  2303. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2304. // if getPermissionErr != nil {
  2305. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2306. // return
  2307. // } else if headNursePermission == nil {
  2308. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2309. // return
  2310. // }
  2311. // }
  2312. //}
  2313. prescription := models.DialysisPrescription{
  2314. UserOrgId: adminUserInfo.Org.Id,
  2315. PatientId: id,
  2316. RecordDate: recordDate.Unix(),
  2317. ModeId: mode_id,
  2318. DialysisDuration: dialysis_duration,
  2319. Dialyzer: dialyzer,
  2320. PerfusionApparatus: perfusion_apparatus,
  2321. BloodFlowVolume: blood_flow_volume,
  2322. DewaterAmount: dewater_amount,
  2323. DisplaceLiqui: displace_liqui,
  2324. ReplacementWay: replacement_way,
  2325. Anticoagulant: anticoagulant,
  2326. AnticoagulantShouji: anticoagulant_shouji,
  2327. AnticoagulantWeichi: anticoagulant_weichi,
  2328. AnticoagulantZongliang: anticoagulant_zongliang,
  2329. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2330. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2331. Kalium: kalium,
  2332. Sodium: sodium,
  2333. Calcium: calcium,
  2334. Bicarbonate: bicarbonate,
  2335. Glucose: glucose,
  2336. // DryWeight: dry_weight,
  2337. DialysateFlow: dialysate_flow,
  2338. DialysateTemperature: dialysate_temperature,
  2339. Conductivity: conductivity,
  2340. Remark: remark,
  2341. Status: 1,
  2342. CreatedTime: time.Now().Unix(),
  2343. UpdatedTime: time.Now().Unix(),
  2344. DialysisDurationMinute: dialysisDurationMinute,
  2345. DialysisDurationHour: dialysisDurationHour,
  2346. TargetUltrafiltration: targetUltrafiltration,
  2347. DialysateFormulation: dialysateFormulation,
  2348. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2349. BodyFluid: body_fluid,
  2350. SpecialMedicine: special_medicine,
  2351. SpecialMedicineOther: special_medicine_other,
  2352. DisplaceLiquiPart: displace_liqui_part,
  2353. DisplaceLiquiValue: displace_liqui_value,
  2354. BloodAccess: blood_access,
  2355. Ultrafiltration: ultrafiltration,
  2356. BodyFluidOther: body_fluid_other,
  2357. ReplacementTotal: replacement_total,
  2358. Niprocart: niprocart,
  2359. Jms: jms,
  2360. FistulaNeedleSet: fistula_needle_set,
  2361. FistulaNeedleSet16: fistula_needle_set_16,
  2362. Hemoperfusion: hemoperfusion,
  2363. DialyserSterilised: dialyser_sterilised,
  2364. Filtryzer: filtryzer,
  2365. TargetKtv: target_ktv,
  2366. Dialyzers: dialyzers,
  2367. Injector: injector,
  2368. Bloodlines: bloodlines,
  2369. TubingHemodialysis: tubing_hemodialysis,
  2370. Package: safe_package,
  2371. ALiquid: a_liquid,
  2372. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  2373. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  2374. Blood: blood,
  2375. DialysisDialyszers: dialysis_dialyszers,
  2376. DialysisIrrigation: dialysis_irrigation,
  2377. AntioxidantCommodityName: antioxidant_commodity_name,
  2378. DisplaceSpeed: displace_speed,
  2379. Illness: illness,
  2380. Amylaceum: amylaceum,
  2381. SingleWater: single_water,
  2382. SingleTime: single_time,
  2383. ReplacementFlow: replacement_flow,
  2384. PlasmaSeparator: plasma_separator,
  2385. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  2386. OxygenUptake: oxygen_uptake,
  2387. OxygenTime: oxygen_time,
  2388. OxygenFlow: oxygen_flow,
  2389. HemodialysisPipelines: hemodialysis_pipelines,
  2390. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2391. PunctureNeedle: puncture_needle,
  2392. PunctureNeedleCount: puncture_needle_count,
  2393. Epo: epo,
  2394. EpoCount: epo_count,
  2395. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2396. PreImpulse: impulse,
  2397. AdminUserId: admin_user_id,
  2398. IsWater: is_war,
  2399. DrhyWater: drhy_water,
  2400. DryWaterHour: dry_water_hour,
  2401. WaterMachine: water_machine,
  2402. AddAmount: add_amount,
  2403. ReduceAmount: reduce_amount,
  2404. }
  2405. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2406. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2407. //
  2408. if appRole.UserType == 2 || appRole.UserType == 1 {
  2409. prescription_doctor = adminUserInfo.AdminUser.Id
  2410. prescription.PrescriptionDoctor = prescription_doctor
  2411. }
  2412. if dialysisPrescription.ID == 0 { //新增
  2413. prescription.Creater = adminUserInfo.AdminUser.Id
  2414. } else { //修改
  2415. if dialysisPrescription.Creater == 0 {
  2416. prescription.Creater = adminUserInfo.AdminUser.Id
  2417. } else {
  2418. prescription.Creater = dialysisPrescription.Creater
  2419. }
  2420. //if/**/
  2421. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2422. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  2423. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2424. // if getPermissionErr != nil {
  2425. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2426. // return
  2427. // } else if headNursePermission == nil {
  2428. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2429. // return
  2430. // }
  2431. //}
  2432. //prescription.Creater = dialysisPrescription.Creater
  2433. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2434. prescription.Modifier = adminUserInfo.AdminUser.Id
  2435. prescription.ID = dialysisPrescription.ID
  2436. }
  2437. solution := models.DialysisSolution{
  2438. RegistrarsId: adminUserInfo.AdminUser.Id,
  2439. UserOrgId: adminUserInfo.Org.Id,
  2440. Doctor: prescription_doctor,
  2441. PatientId: id,
  2442. ModeId: mode_id,
  2443. DialysisDuration: dialysis_duration,
  2444. PerfusionApparatus: perfusion_apparatus,
  2445. BloodFlowVolume: blood_flow_volume,
  2446. Dewater: dewater_amount,
  2447. DisplaceLiqui: displace_liqui,
  2448. ReplacementWay: replacement_way,
  2449. Anticoagulant: anticoagulant,
  2450. AnticoagulantShouji: anticoagulant_shouji,
  2451. AnticoagulantWeichi: anticoagulant_weichi,
  2452. AnticoagulantZongliang: anticoagulant_zongliang,
  2453. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2454. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2455. Kalium: kalium,
  2456. Sodium: sodium,
  2457. Calcium: calcium,
  2458. Bicarbonate: bicarbonate,
  2459. Glucose: glucose,
  2460. // DryWeight: dry_weight,
  2461. DialysateFlow: dialysate_flow,
  2462. DialysateTemperature: dialysate_temperature,
  2463. Conductivity: conductivity,
  2464. Remark: remark,
  2465. Status: 1,
  2466. CreatedTime: time.Now().Unix(),
  2467. UpdatedTime: time.Now().Unix(),
  2468. DialysisDurationMinute: dialysisDurationMinute,
  2469. DialysisDurationHour: dialysisDurationHour,
  2470. TargetUltrafiltration: targetUltrafiltration,
  2471. DialysateFormulation: dialysateFormulation,
  2472. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2473. BodyFluid: body_fluid,
  2474. SpecialMedicine: special_medicine,
  2475. SpecialMedicineOther: special_medicine_other,
  2476. DisplaceLiquiPart: displace_liqui_part,
  2477. DisplaceLiquiValue: displace_liqui_value,
  2478. BloodAccess: blood_access,
  2479. Ultrafiltration: ultrafiltration,
  2480. BodyFluidOther: body_fluid_other,
  2481. ReplacementTotal: replacement_total,
  2482. TargetKtv: target_ktv,
  2483. DialysisDialyszers: dialysis_dialyszers,
  2484. DialysisIrrigation: dialysis_irrigation,
  2485. HemodialysisPipelines: hemodialysis_pipelines,
  2486. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2487. PunctureNeedle: puncture_needle,
  2488. PunctureNeedleCount: puncture_needle_count,
  2489. Epo: epo,
  2490. EpoCount: epo_count,
  2491. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2492. PreImpulse: impulse,
  2493. SolutionStatus: 1,
  2494. }
  2495. //针对河间咸的
  2496. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  2497. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  2498. solution.DisplaceLiquiPart = 0
  2499. solution.DisplaceLiquiValue = 0
  2500. }
  2501. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2502. prescription.DisplaceLiquiPart = 0
  2503. prescription.DisplaceLiquiValue = 0
  2504. }
  2505. }
  2506. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2507. //获取最新1条
  2508. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  2509. //更新状态
  2510. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  2511. //获取key,清空redis
  2512. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2513. redis := service.RedisClient()
  2514. defer redis.Close()
  2515. //清空key 值
  2516. redis.Set(key, "", time.Second)
  2517. //清空长期医嘱的key
  2518. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2519. redis.Set(soulution_key, "", time.Second)
  2520. //查询最近透析准备表里是否存在 透析器 灌流器
  2521. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2522. redis.Set(keyOne, "", time.Second)
  2523. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2524. redis.Set(keyTwo, "", time.Second)
  2525. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2526. redis.Set(keyThree, "", time.Second)
  2527. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2528. redis.Set(keyFour, "", time.Second)
  2529. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2530. //
  2531. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2532. //
  2533. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2534. //if len(mation)>0{
  2535. // for _, item := range splitStr {
  2536. // for _,it := range mation{
  2537. // if(item == it.SpecificationName){
  2538. //
  2539. // //查询最近一次的透析器
  2540. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2541. //
  2542. // if errcode == gorm.ErrRecordNotFound{
  2543. // //插入数据
  2544. // prepare := models.DialysisBeforePrepare{
  2545. // UserOrgId: adminUserInfo.Org.Id,
  2546. // PatientId: id,
  2547. // RecordDate: recordDate.Unix(),
  2548. // GoodTypeId: it.GoodTypeId,
  2549. // GoodId: it.ID,
  2550. // Count: 1,
  2551. // Ctime: time.Now().Unix(),
  2552. // Creater: adminUserInfo.AdminUser.Id,
  2553. // Status:1,
  2554. //
  2555. // }
  2556. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2557. // fmt.Println("",errcode)
  2558. // }
  2559. // }
  2560. // }
  2561. //
  2562. // }
  2563. //
  2564. // for _, item := range splitIrrigation {
  2565. // for _,it := range mation{
  2566. // if(item == it.SpecificationName){
  2567. // //查询最近一次的透析器
  2568. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2569. // if errcode == gorm.ErrRecordNotFound{
  2570. // //插入数据
  2571. // prepare := models.DialysisBeforePrepare{
  2572. // UserOrgId: adminUserInfo.Org.Id,
  2573. // PatientId: id,
  2574. // RecordDate: recordDate.Unix(),
  2575. // GoodTypeId: it.GoodTypeId,
  2576. // GoodId: it.ID,
  2577. // Count: 1,
  2578. // Ctime: time.Now().Unix(),
  2579. // Creater: adminUserInfo.AdminUser.Id,
  2580. // Status:1,
  2581. //
  2582. // }
  2583. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2584. // fmt.Println(errcode)
  2585. // }
  2586. // }
  2587. // }
  2588. // }
  2589. //}
  2590. c.ServeSuccessJSON(map[string]interface{}{
  2591. "solution": &solution,
  2592. "prescription": &prescription,
  2593. })
  2594. }
  2595. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2596. patient, _ := c.GetInt64("patient", 0)
  2597. adminUserInfo := c.GetMobileAdminUserInfo()
  2598. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2599. c.ServeSuccessJSON(map[string]interface{}{
  2600. "receiveTreatmentAsses": receiveTreatmentAsses,
  2601. })
  2602. }
  2603. func (this *DialysisAPIController) PostSignInfo() {
  2604. patientID, _ := this.GetInt64("patient_id")
  2605. recordDateStr := this.GetString("date")
  2606. if patientID <= 0 {
  2607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. if len(recordDateStr) == 0 {
  2611. recordDateStr = time.Now().Format("2006-01-02")
  2612. }
  2613. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2614. if parseDateErr != nil {
  2615. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2617. return
  2618. }
  2619. adminInfo := this.GetMobileAdminUserInfo()
  2620. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2621. if err != nil {
  2622. this.ErrorLog("签名失败:%v", err)
  2623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2624. return
  2625. }
  2626. this.ServeSuccessJSON(map[string]interface{}{
  2627. "doctor_id": adminInfo.AdminUser.Id,
  2628. })
  2629. }
  2630. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2631. patientID, _ := this.GetInt64("patient_id")
  2632. adminInfo := this.GetMobileAdminUserInfo()
  2633. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2634. this.ServeSuccessJSON(map[string]interface{}{
  2635. "monitor": record,
  2636. })
  2637. }
  2638. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2639. thisTime := time.Now()
  2640. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2641. timeLayout := "2006-01-02 15:04:05"
  2642. loc, _ := time.LoadLocation("Local")
  2643. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2644. theAssessmentDateTime := theStartTime.Unix()
  2645. patientID, _ := this.GetInt64("patient_id")
  2646. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2647. adminInfo := this.GetMobileAdminUserInfo()
  2648. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2649. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2650. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2651. var ultrafiltration_rate float64
  2652. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2653. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2654. fmt.Println(evaluation)
  2655. if prescription.ID > 0 {
  2656. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2657. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2658. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  2659. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2660. record.UltrafiltrationRate = ultrafiltration_rate
  2661. }
  2662. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2663. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2664. record.UltrafiltrationRate = ultrafiltration_rate
  2665. }
  2666. if template.TemplateId == 20 || template.TemplateId == 22 {
  2667. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2668. record.UltrafiltrationRate = ultrafiltration_rate
  2669. }
  2670. // 只针对方济医院
  2671. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2672. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2673. ultrafiltration_rate = value
  2674. record.UltrafiltrationRate = ultrafiltration_rate
  2675. }
  2676. if template.TemplateId == 41 || template.TemplateId == 47 {
  2677. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2678. record.UltrafiltrationRate = ultrafiltration_rate
  2679. }
  2680. if template.TemplateId == 43 {
  2681. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2682. record.UltrafiltrationRate = ultrafiltration_rate
  2683. }
  2684. if template.TemplateId == 46 || template.TemplateId == 54 {
  2685. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2686. record.UltrafiltrationRate = ultrafiltration_rate
  2687. }
  2688. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 {
  2689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  2690. record.UltrafiltrationRate = ultrafiltration_rate
  2691. }
  2692. //if template.TemplateId == 47 {
  2693. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2694. // record.UltrafiltrationRate = ultrafiltration_rate
  2695. //}
  2696. }
  2697. }
  2698. // record.UltrafiltrationRate = ultrafiltration_rate
  2699. record.UltrafiltrationVolume = 0
  2700. 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
  2701. if ultrafiltration_rate > 0 {
  2702. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2703. record.UltrafiltrationVolume = value
  2704. }
  2705. }
  2706. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 { //adminInfo.Org.Id == 9538
  2707. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2708. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2709. record.UltrafiltrationVolume = ultrafiltration_volume
  2710. }
  2711. }
  2712. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 {
  2713. if ultrafiltration_rate > 0 {
  2714. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2715. record.UltrafiltrationVolume = ultrafiltration_volume
  2716. }
  2717. }
  2718. if template.TemplateId == 47 || template.TemplateId == 54 {
  2719. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  2720. }
  2721. this.ServeSuccessJSON(map[string]interface{}{
  2722. "monitor": record,
  2723. })
  2724. }
  2725. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2726. record_id, _ := this.GetInt64("id")
  2727. nurseID, _ := this.GetInt64("nurse")
  2728. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2729. bedID, _ := this.GetInt64("bed")
  2730. start_time := this.GetString("start_time")
  2731. schedual_type, _ := this.GetInt64("schedual_type")
  2732. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2733. change_nurse, _ := this.GetInt64("change_nurse")
  2734. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2735. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2736. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2737. patient_id, _ := this.GetInt64("patient_id")
  2738. record_date, _ := this.GetInt64("record_date")
  2739. puncture_needle := this.GetString("puncture_needle")
  2740. puncture_way := this.GetString("puncture_way")
  2741. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2742. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2743. blood_access_id, _ := this.GetInt64("blood_access_id")
  2744. nuclein_date_str := this.GetString("nuclein_date_str")
  2745. order_remark := this.GetString("order_remark")
  2746. schedule_remark := this.GetString("schedule_remark")
  2747. if record_id == 0 {
  2748. this.ErrorLog("id:%v", record_id)
  2749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2750. return
  2751. }
  2752. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2753. if parseStartDateErr != nil {
  2754. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2756. return
  2757. }
  2758. adminUserInfo := this.GetMobileAdminUserInfo()
  2759. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2760. if getNurseErr != nil {
  2761. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2763. return
  2764. } else if nurse == nil {
  2765. this.ErrorLog("护士不存在")
  2766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2767. return
  2768. }
  2769. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2770. //if getNurseErr != nil {
  2771. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2772. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2773. // return
  2774. //} else if nurse == nil {
  2775. // this.ErrorLog("护士不存在")
  2776. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2777. // return
  2778. //}
  2779. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2780. if getDeviceNumberErr != nil {
  2781. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2783. return
  2784. } else if deviceNumber == nil {
  2785. this.ErrorLog("床位号不存在")
  2786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2790. //
  2791. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2792. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2793. // if getPermissionErr != nil {
  2794. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2795. // return
  2796. // } else if headNursePermission == nil {
  2797. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2798. // return
  2799. // }
  2800. //}
  2801. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2802. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2803. timeLayout := "2006-01-02 15:04:05"
  2804. loc, _ := time.LoadLocation("Local")
  2805. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2806. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2807. schedulestartTime := theStartTime.Unix()
  2808. scheduleendTime := theEndTime.Unix()
  2809. var theNucleinDate int64
  2810. timeLayoutOne := "2006-01-02"
  2811. if len(nuclein_date_str) > 0 {
  2812. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2813. if err != nil {
  2814. utils.ErrorLog(err.Error())
  2815. }
  2816. theNucleinDate = theTime.Unix()
  2817. }
  2818. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2819. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2820. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2821. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2822. if err == gorm.ErrRecordNotFound { //空床位
  2823. // 修改了床位逻辑
  2824. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2825. if daySchedule.ID > 0 {
  2826. //daySchedule.BedId = bedID
  2827. //daySchedule.PartitionId = deviceNumber.ZoneID
  2828. //daySchedule.ScheduleType = schedual_type
  2829. //daySchedule.UpdatedTime = time.Now().Unix()
  2830. //err := service.UpdateSchedule(&daySchedule)
  2831. xtSchedule := models.Schedule{
  2832. PartitionId: deviceNumber.ZoneID,
  2833. BedId: bedID,
  2834. ScheduleType: schedual_type,
  2835. UpdatedTime: time.Now().Unix(),
  2836. }
  2837. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2838. if err != nil {
  2839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2840. return
  2841. }
  2842. }
  2843. } else if err == nil {
  2844. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2845. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2846. if daySchedule.ID > 0 {
  2847. //daySchedule.BedId = bedID
  2848. //daySchedule.PartitionId = deviceNumber.ZoneID
  2849. //
  2850. //daySchedule.ScheduleType = schedual_type
  2851. //daySchedule.UpdatedTime = time.Now().Unix()
  2852. //err := service.UpdateSchedule(&daySchedule)
  2853. xtSchedule := models.Schedule{
  2854. PartitionId: deviceNumber.ZoneID,
  2855. BedId: bedID,
  2856. ScheduleType: schedual_type,
  2857. UpdatedTime: time.Now().Unix(),
  2858. }
  2859. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2860. if err != nil {
  2861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2862. return
  2863. }
  2864. }
  2865. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2867. return
  2868. }
  2869. } else if err != nil {
  2870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2871. return
  2872. }
  2873. }
  2874. dialysisRecord := &models.DialysisOrder{
  2875. ID: record_id,
  2876. UserOrgId: adminUserInfo.Org.Id,
  2877. BedID: bedID,
  2878. StartNurse: nurseID,
  2879. StartTime: startDate.Unix(),
  2880. PunctureNurse: puncture_nurse,
  2881. Creator: adminUserInfo.AdminUser.Id,
  2882. Modifier: adminUserInfo.AdminUser.Id,
  2883. WashpipeNurse: washpipe_nurse,
  2884. SchedualType: schedual_type,
  2885. ChangeNurse: change_nurse,
  2886. DifficultPunctureNurse: difficult_puncture_nurse,
  2887. NewFistulaNurse: new_fistula_nurse,
  2888. QualityNurseId: quality_nurse_id,
  2889. PunctureNeedle: puncture_needle,
  2890. PunctureWay: puncture_way,
  2891. DialysisDialyszers: dialysis_dialyszers,
  2892. DialysisIrrigation: dialysis_irrigation,
  2893. BloodAccessId: blood_access_id,
  2894. NucleinDate: theNucleinDate,
  2895. OrderRemark: order_remark,
  2896. ScheduleRemark: schedule_remark,
  2897. }
  2898. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2899. order, _ := service.GetLastPatientOrder(record_id)
  2900. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  2901. redis := service.RedisClient()
  2902. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  2903. redis.Set(key, "", time.Second)
  2904. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2905. //清空key 值
  2906. redis.Set(keyOne, "", time.Second)
  2907. scheduleDateStartOne := startDate.Format("2006-01-02")
  2908. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2909. redis.Set(keyTwo, "", time.Second)
  2910. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  2911. redis.Set(keyThree, "", time.Second)
  2912. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2913. redis.Set(keyFour, "", time.Second)
  2914. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  2915. redis.Set(keyFive, "", time.Second)
  2916. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  2917. redis.Set(keySix, "", time.Second)
  2918. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  2919. redis.Set(keySeven, "", time.Second)
  2920. if updateErr != nil {
  2921. this.ErrorLog("修改上机失败:%v", updateErr)
  2922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2923. return
  2924. }
  2925. if updateErr == nil {
  2926. if tempDialysisRecord.Stage == 2 {
  2927. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2928. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2929. fmt.Println(value)
  2930. a, b := math.Modf(value)
  2931. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2932. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2933. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2934. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2935. redis := service.RedisClient()
  2936. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  2937. redis.Set(key, "", time.Second)
  2938. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  2939. redis.Set(keyOne, "", time.Second)
  2940. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2941. //清空key 值
  2942. redis.Set(keySix, "", time.Second)
  2943. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2944. redis.Set(keySeven, "", time.Second)
  2945. redis.Close()
  2946. if updateAssessmentErr != nil {
  2947. utils.ErrorLog("%v", updateAssessmentErr)
  2948. }
  2949. }
  2950. }
  2951. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2952. this.ServeSuccessJSON(map[string]interface{}{
  2953. "dialysis_order": dialysisRecords,
  2954. })
  2955. }
  2956. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2957. record_id, _ := c.GetInt64("id")
  2958. nurseID, _ := c.GetInt64("nurse")
  2959. end_time := c.GetString("end_time")
  2960. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2961. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2962. catheter := c.GetString("catheter")
  2963. cruor := c.GetString("cruor")
  2964. mission := c.GetString("mission")
  2965. if record_id <= 0 || nurseID <= 0 {
  2966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2967. return
  2968. }
  2969. adminUserInfo := c.GetMobileAdminUserInfo()
  2970. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2971. if getNurseErr != nil {
  2972. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2974. return
  2975. } else if nurse == nil {
  2976. c.ErrorLog("护士不存在")
  2977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2978. return
  2979. }
  2980. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2981. if parseEndDateErr != nil {
  2982. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2984. return
  2985. }
  2986. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2987. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2988. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2989. // if getPermissionErr != nil {
  2990. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2991. // return
  2992. // } else if headNursePermission == nil {
  2993. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2994. // return
  2995. // }
  2996. //}
  2997. dialysisRecord := &models.DialysisOrder{
  2998. ID: record_id,
  2999. UserOrgId: adminUserInfo.Org.Id,
  3000. EndTime: endDate.Unix(),
  3001. FinishNurse: nurseID,
  3002. FinishModifier: adminUserInfo.AdminUser.Id,
  3003. PuncturePointHaematoma: puncture_point_haematoma,
  3004. BloodAccessInternalFistula: blood_access_internal_fistula,
  3005. Catheter: catheter,
  3006. Cruor: cruor,
  3007. Mission: mission,
  3008. }
  3009. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  3010. redis := service.RedisClient()
  3011. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  3012. //清空key 值
  3013. redis.Set(key, "", time.Second)
  3014. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3015. //清空key 值
  3016. redis.Set(keyOne, "", time.Second)
  3017. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3018. redis.Set(keySeven, "", time.Second)
  3019. redis.Close()
  3020. if updateErr != nil {
  3021. c.ErrorLog("修改下机失败:%v", updateErr)
  3022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3023. return
  3024. }
  3025. if updateErr == nil {
  3026. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  3027. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3028. a, b := math.Modf(value)
  3029. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3030. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3031. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3032. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  3033. redis := service.RedisClient()
  3034. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  3035. redis.Set(keyTen, "", time.Second)
  3036. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  3037. redis.Set(keyTwo, "", time.Second)
  3038. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  3039. redis.Set(key, "", time.Second)
  3040. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3041. redis.Set(keyThree, "", time.Second)
  3042. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3043. redis.Set(keySeven, "", time.Second)
  3044. defer redis.Close()
  3045. if updateAssessmentErr != nil {
  3046. utils.ErrorLog("%v", updateAssessmentErr)
  3047. }
  3048. }
  3049. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3050. c.ServeSuccessJSON(map[string]interface{}{
  3051. "dialysis_order": dialysisRecords,
  3052. })
  3053. }
  3054. func (c *DialysisAPIController) GetLongAdvice() {
  3055. patient_id, _ := c.GetInt64("id")
  3056. adminUserInfo := c.GetMobileAdminUserInfo()
  3057. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3058. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3059. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3060. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3061. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3062. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3063. c.ServeSuccessJSON(map[string]interface{}{
  3064. "status": "1",
  3065. })
  3066. return
  3067. } else { //开启推送提醒
  3068. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3069. var advice_three []*models.DoctorAdvice
  3070. recordDateStr := time.Now().Format("2006-01-02")
  3071. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3072. nowtime := recordDate.Unix()
  3073. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  3074. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  3075. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  3076. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  3077. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  3078. for _, advice := range advices {
  3079. if advice.FrequencyType == 3 {
  3080. t := time.Now()
  3081. week := int(t.Weekday())
  3082. fmt.Println(t.Weekday())
  3083. fmt.Println(week)
  3084. switch week {
  3085. case 1:
  3086. if strings.Index(advice.WeekDay, "周一") == -1 {
  3087. advice_three = append(advice_three, advice)
  3088. }
  3089. break
  3090. case 2:
  3091. if strings.Index(advice.WeekDay, "周二") == -1 {
  3092. advice_three = append(advice_three, advice)
  3093. }
  3094. break
  3095. case 3:
  3096. if strings.Index(advice.WeekDay, "周三") == -1 {
  3097. advice_three = append(advice_three, advice)
  3098. }
  3099. break
  3100. case 4:
  3101. if strings.Index(advice.WeekDay, "周四") == -1 {
  3102. advice_three = append(advice_three, advice)
  3103. }
  3104. break
  3105. case 5:
  3106. if strings.Index(advice.WeekDay, "周五") == -1 {
  3107. advice_three = append(advice_three, advice)
  3108. }
  3109. break
  3110. case 6:
  3111. if strings.Index(advice.WeekDay, "周六") == -1 {
  3112. advice_three = append(advice_three, advice)
  3113. }
  3114. break
  3115. case 0:
  3116. if strings.Index(advice.WeekDay, "周日") == -1 {
  3117. advice_three = append(advice_three, advice)
  3118. }
  3119. break
  3120. }
  3121. }
  3122. }
  3123. for _, advice := range advices_two {
  3124. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3125. now := p.Unix()
  3126. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3127. dayStr2 := "-" + dayStr
  3128. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3129. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3130. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3131. for _, ad := range advices {
  3132. advice_three = append(advice_three, ad)
  3133. }
  3134. }
  3135. if err == nil {
  3136. c.ServeSuccessJSON(map[string]interface{}{
  3137. "status": "2",
  3138. "advices": advices,
  3139. "advices_two": RemoveRepeatedElement(advice_three),
  3140. "is_open_remind": config.IsOpenRemind,
  3141. "his_config_open": hisConfig.IsOpen,
  3142. "is_advice_open": is_advice_open.IsAdviceOpen,
  3143. "prescription_open": prescription_open.IsOpen,
  3144. })
  3145. }
  3146. }
  3147. }
  3148. func (c *DialysisAPIController) GetLongAdviceOne() {
  3149. patient_id, _ := c.GetInt64("id")
  3150. startTime := c.GetString("schedule_date")
  3151. timeLayout := "2006-01-02"
  3152. loc, _ := time.LoadLocation("Local")
  3153. var theStartTime int64
  3154. if len(startTime) > 0 {
  3155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3156. if err != nil {
  3157. utils.ErrorLog(err.Error())
  3158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3159. return
  3160. }
  3161. theStartTime = theTime.Unix()
  3162. }
  3163. adminUserInfo := c.GetMobileAdminUserInfo()
  3164. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3165. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3166. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3167. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3168. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3169. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3170. c.ServeSuccessJSON(map[string]interface{}{
  3171. "status": "1",
  3172. })
  3173. return
  3174. } else { //开启推送提醒
  3175. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3176. var advice_three []*models.DoctorAdvice
  3177. fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
  3178. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  3179. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  3180. for _, advice := range advices {
  3181. if advice.FrequencyType == 3 {
  3182. t := time.Now()
  3183. week := int(t.Weekday())
  3184. fmt.Println(t.Weekday())
  3185. fmt.Println(week)
  3186. switch week {
  3187. case 1:
  3188. if strings.Index(advice.WeekDay, "周一") == -1 {
  3189. advice_three = append(advice_three, advice)
  3190. }
  3191. break
  3192. case 2:
  3193. if strings.Index(advice.WeekDay, "周二") == -1 {
  3194. advice_three = append(advice_three, advice)
  3195. }
  3196. break
  3197. case 3:
  3198. if strings.Index(advice.WeekDay, "周三") == -1 {
  3199. advice_three = append(advice_three, advice)
  3200. }
  3201. break
  3202. case 4:
  3203. if strings.Index(advice.WeekDay, "周四") == -1 {
  3204. advice_three = append(advice_three, advice)
  3205. }
  3206. break
  3207. case 5:
  3208. if strings.Index(advice.WeekDay, "周五") == -1 {
  3209. advice_three = append(advice_three, advice)
  3210. }
  3211. break
  3212. case 6:
  3213. if strings.Index(advice.WeekDay, "周六") == -1 {
  3214. advice_three = append(advice_three, advice)
  3215. }
  3216. break
  3217. case 0:
  3218. if strings.Index(advice.WeekDay, "周日") == -1 {
  3219. advice_three = append(advice_three, advice)
  3220. }
  3221. break
  3222. }
  3223. }
  3224. }
  3225. for _, advice := range advices_two {
  3226. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3227. now := p.Unix()
  3228. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3229. dayStr2 := "-" + dayStr
  3230. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3231. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3232. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3233. for _, ad := range advices {
  3234. advice_three = append(advice_three, ad)
  3235. }
  3236. }
  3237. if err == nil {
  3238. c.ServeSuccessJSON(map[string]interface{}{
  3239. "status": "2",
  3240. "advices": advices,
  3241. "advices_two": RemoveRepeatedElement(advice_three),
  3242. "is_open_remind": config.IsOpenRemind,
  3243. "his_config_open": hisConfig.IsOpen,
  3244. "is_advice_open": is_advice_open.IsAdviceOpen,
  3245. "prescription_open": prescription_open.IsOpen,
  3246. })
  3247. }
  3248. }
  3249. }
  3250. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3251. newArr = make([]*models.DoctorAdvice, 0)
  3252. for i := 0; i < len(arr); i++ {
  3253. repeat := false
  3254. for j := i + 1; j < len(arr); j++ {
  3255. if arr[i].ID == arr[j].ID {
  3256. repeat = true
  3257. break
  3258. }
  3259. }
  3260. if !repeat {
  3261. newArr = append(newArr, arr[i])
  3262. }
  3263. }
  3264. return
  3265. }
  3266. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  3267. patient, _ := c.GetInt64("id", 0)
  3268. groupNo, _ := c.GetInt64("groupno", 0)
  3269. if patient <= 0 {
  3270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3271. return
  3272. }
  3273. adminUserInfo := c.GetMobileAdminUserInfo()
  3274. dataBody := make(map[string]interface{}, 0)
  3275. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3276. if err != nil {
  3277. utils.ErrorLog(err.Error())
  3278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3279. return
  3280. }
  3281. utils.ErrorLog("%v", dataBody)
  3282. timeLayout := "2006-01-02 15:04"
  3283. loc, _ := time.LoadLocation("Local")
  3284. timeLayout2 := "2006-01-02"
  3285. loc2, _ := time.LoadLocation("Local")
  3286. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3287. utils.ErrorLog("advice_type")
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3289. return
  3290. }
  3291. adviceType := int64(2)
  3292. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3293. utils.ErrorLog("advice_date")
  3294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3295. return
  3296. }
  3297. adviceDate, _ := dataBody["advice_date"].(string)
  3298. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3299. AdviceDate := theTime.Unix()
  3300. RecordDate := theTime.Unix()
  3301. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3302. utils.ErrorLog("start_time")
  3303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3304. return
  3305. }
  3306. startTime, _ := dataBody["start_time"].(string)
  3307. if len(startTime) == 0 {
  3308. utils.ErrorLog("len(start_time) == 0")
  3309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3310. return
  3311. }
  3312. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  3313. if err != nil {
  3314. utils.ErrorLog(err.Error())
  3315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3316. return
  3317. }
  3318. StartTime := theTime.Unix()
  3319. Remark := ""
  3320. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3321. remark, _ := dataBody["remark"].(string)
  3322. Remark = remark
  3323. }
  3324. var advices []*models.GroupAdvice
  3325. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3326. utils.ErrorLog("advices")
  3327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3328. return
  3329. }
  3330. adviceNames := dataBody["advices"].([]interface{})
  3331. for _, adviceNameMap := range adviceNames {
  3332. adviceNameM := adviceNameMap.(map[string]interface{})
  3333. var advice models.GroupAdvice
  3334. advice.Remark = Remark
  3335. advice.AdviceType = adviceType
  3336. advice.StartTime = StartTime
  3337. advice.AdviceDate = AdviceDate
  3338. advice.RecordDate = RecordDate
  3339. advice.Status = 1
  3340. advice.CreatedTime = time.Now().Unix()
  3341. advice.UpdatedTime = time.Now().Unix()
  3342. advice.StopState = 2
  3343. advice.ExecutionState = 2
  3344. advice.UserOrgId = adminUserInfo.Org.Id
  3345. advice.PatientId = patient
  3346. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3347. advice.IsSettle = 2
  3348. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3349. utils.ErrorLog("advice_name")
  3350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3351. return
  3352. }
  3353. adviceName, _ := adviceNameM["advice_name"].(string)
  3354. if len(adviceName) == 0 {
  3355. utils.ErrorLog("len(advice_name) == 0")
  3356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3357. return
  3358. }
  3359. advice.AdviceName = adviceName
  3360. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3361. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3362. advice.DrugSpec = drugSpec
  3363. }
  3364. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3365. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3366. advice.AdviceDesc = adviceDesc
  3367. }
  3368. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3369. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3370. advice.DrugSpecUnit = drugSpecUnit
  3371. }
  3372. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3373. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3374. // advice.SingleDose = singleDose
  3375. //}
  3376. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3377. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3378. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3379. }
  3380. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3381. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3382. advice.SingleDoseUnit = singleDoseUnit
  3383. }
  3384. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3385. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3386. // advice.PrescribingNumber = prescribingNumber
  3387. //}
  3388. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3389. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3390. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3391. }
  3392. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3393. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3394. advice.PrescribingNumberUnit = prescribingNumberUnit
  3395. }
  3396. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3397. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3398. advice.DeliveryWay = deliveryWay
  3399. }
  3400. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3401. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3402. advice.ExecutionFrequency = executionFrequency
  3403. }
  3404. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3405. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3406. advice.FrequencyType = frequency_type
  3407. }
  3408. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3409. day_count := int64(adviceNameM["day_count"].(float64))
  3410. advice.DayCount = day_count
  3411. }
  3412. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3413. week_day, _ := adviceNameM["week_day"].(string)
  3414. advice.WeekDay = week_day
  3415. }
  3416. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3417. way := int64(adviceNameM["way"].(float64))
  3418. advice.Way = way
  3419. }
  3420. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3421. drug_id := int64(adviceNameM["drug_id"].(float64))
  3422. advice.DrugId = drug_id
  3423. }
  3424. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3425. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3426. advice.DrugNameId = drug_name_id
  3427. }
  3428. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3429. template_id, _ := adviceNameM["template_id"].(string)
  3430. advice.TemplateId = template_id
  3431. }
  3432. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  3433. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3434. advice.ExecutionFrequency = executionFrequency
  3435. }
  3436. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3437. children := adviceNameM["child"].([]interface{})
  3438. if len(children) > 0 {
  3439. for _, childrenMap := range children {
  3440. childMap := childrenMap.(map[string]interface{})
  3441. var child models.GroupAdvice
  3442. child.Remark = Remark
  3443. child.AdviceType = adviceType
  3444. child.StartTime = StartTime
  3445. child.AdviceDate = AdviceDate
  3446. child.RecordDate = RecordDate
  3447. child.Status = 1
  3448. child.CreatedTime = time.Now().Unix()
  3449. child.UpdatedTime = time.Now().Unix()
  3450. child.StopState = 2
  3451. child.ExecutionState = 2
  3452. child.UserOrgId = adminUserInfo.Org.Id
  3453. child.PatientId = patient
  3454. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3455. child.IsSettle = 1
  3456. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3457. utils.ErrorLog("child advice_name")
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3459. return
  3460. }
  3461. childAdviceName, _ := childMap["advice_name"].(string)
  3462. if len(childAdviceName) == 0 {
  3463. utils.ErrorLog("len(child advice_name) == 0")
  3464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3465. return
  3466. }
  3467. child.AdviceName = childAdviceName
  3468. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3469. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3470. child.AdviceDesc = childAdviceDesc
  3471. }
  3472. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3473. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3474. child.DrugSpec = childDrugSpec
  3475. }
  3476. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3477. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3478. child.DrugSpecUnit = childDrugSpecUnit
  3479. }
  3480. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3481. child.SingleDose = childMap["single_dose"].(float64)
  3482. }
  3483. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3484. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3485. child.SingleDoseUnit = childSingleDoseUnit
  3486. }
  3487. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3488. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3489. }
  3490. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3491. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3492. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3493. }
  3494. child.DeliveryWay = advice.DeliveryWay
  3495. child.ExecutionFrequency = advice.ExecutionFrequency
  3496. advice.Children = append(advice.Children, &child)
  3497. }
  3498. }
  3499. }
  3500. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  3501. if temp_advice.ID == 0 {
  3502. advices = append(advices, &advice)
  3503. }
  3504. }
  3505. if len(advices) > 0 {
  3506. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  3507. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  3508. redis := service.RedisClient()
  3509. //清空key 值
  3510. redis.Set(key, "", time.Second)
  3511. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3512. redis.Set(keyOne, "", time.Second)
  3513. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3514. defer redis.Close()
  3515. redis.Set(keyThree, "", time.Second)
  3516. if err != nil {
  3517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3518. return
  3519. }
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "msg": "ok",
  3522. "advices": list,
  3523. })
  3524. } else {
  3525. c.ServeSuccessJSON(map[string]interface{}{
  3526. "msg": "ok",
  3527. })
  3528. }
  3529. return
  3530. }
  3531. func (c *DialysisAPIController) UploadDryWeight() {
  3532. patient_id, _ := c.GetInt64("id")
  3533. dry_weight, _ := c.GetFloat("dry_weight")
  3534. doctor_id, _ := c.GetInt64("doctor_id")
  3535. remark := c.GetString("remark")
  3536. adminUserInfo := c.GetMobileAdminUserInfo()
  3537. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  3538. if err == gorm.ErrRecordNotFound {
  3539. dryWeight := &models.SgjPatientDryweight{
  3540. PatientId: patient_id,
  3541. DryWeight: dry_weight,
  3542. Remakes: remark,
  3543. Ctime: time.Now().Unix(),
  3544. Mtime: time.Now().Unix(),
  3545. Creator: doctor_id,
  3546. Status: 1,
  3547. UserOrgId: adminUserInfo.Org.Id,
  3548. AdjustedValue: "/",
  3549. UserId: adminUserInfo.AdminUser.Id,
  3550. }
  3551. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3552. redis := service.RedisClient()
  3553. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  3554. redis.Set(keyOne, "", time.Second)
  3555. loc, _ := time.LoadLocation("Local")
  3556. nowTime := time.Now()
  3557. nowDay := nowTime.Format("2006-01-02")
  3558. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3559. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3560. redis.Set(key, "", time.Second)
  3561. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3562. redis.Set(keyTwo, "", time.Second)
  3563. redis.Close()
  3564. if createErr == nil {
  3565. c.ServeSuccessJSON(map[string]interface{}{
  3566. "msg": "提交成功",
  3567. "weight": dryWeight,
  3568. })
  3569. }
  3570. } else {
  3571. dryWeight := &models.SgjPatientDryweight{
  3572. PatientId: patient_id,
  3573. DryWeight: dry_weight,
  3574. Remakes: remark,
  3575. Ctime: time.Now().Unix(),
  3576. Mtime: time.Now().Unix(),
  3577. Creator: doctor_id,
  3578. Status: 1,
  3579. UserOrgId: adminUserInfo.Org.Id,
  3580. AdjustedValue: "/",
  3581. UserId: adminUserInfo.AdminUser.Id,
  3582. }
  3583. var value float64
  3584. value = dry_weight - weightAdjust.DryWeight
  3585. if value < 0 {
  3586. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3587. } else if value == 0 {
  3588. dryWeight.AdjustedValue = "/"
  3589. } else if value > 0 {
  3590. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3591. }
  3592. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3593. redis := service.RedisClient()
  3594. loc, _ := time.LoadLocation("Local")
  3595. nowTime := time.Now()
  3596. nowDay := nowTime.Format("2006-01-02")
  3597. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3598. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3599. redis.Set(keyOne, "", time.Second)
  3600. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3601. redis.Set(key, "", time.Second)
  3602. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3603. redis.Set(keyTwo, "", time.Second)
  3604. redis.Close()
  3605. if createErr == nil {
  3606. c.ServeSuccessJSON(map[string]interface{}{
  3607. "msg": "提交成功",
  3608. "weight": dryWeight,
  3609. })
  3610. }
  3611. }
  3612. }
  3613. func (c *DialysisAPIController) GetSolution() {
  3614. patient_id, _ := c.GetInt64("patient_id")
  3615. mode_id, _ := c.GetInt64("mode_id")
  3616. adminUserInfo := c.GetMobileAdminUserInfo()
  3617. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3618. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3619. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  3620. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  3621. if err != nil {
  3622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3623. return
  3624. }
  3625. c.ServeSuccessJSON(map[string]interface{}{
  3626. "solution": solution,
  3627. "prescription": prescription,
  3628. "system_prescription": system_prescription,
  3629. "dialysisPrescription": dialysisPrescription,
  3630. })
  3631. }
  3632. func (c *DialysisAPIController) GetSchedule() {
  3633. schedual_type, _ := c.GetInt64("schedual_type")
  3634. adminUserInfo := c.GetMobileAdminUserInfo()
  3635. scheduleTime, _ := c.GetInt64("record_date")
  3636. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  3637. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  3638. c.ServeSuccessJSON(map[string]interface{}{
  3639. "number": deviceNumber,
  3640. "list": list,
  3641. })
  3642. }
  3643. func (c *DialysisAPIController) GetPatientId() {
  3644. id, _ := c.GetInt64("id")
  3645. //orgid := c.GetMobileAdminUserInfo().Org.Id
  3646. patientId, _ := service.GetPatientId(id)
  3647. //获取该患者的所有传染病
  3648. list, _ := service.GetPatientInfectious(id)
  3649. c.ServeSuccessJSON(map[string]interface{}{
  3650. "patient": patientId,
  3651. "infectioulist": list,
  3652. })
  3653. }
  3654. func (this *DialysisAPIController) GetDialysisSchedule() {
  3655. schedualDate := this.GetString("date")
  3656. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3657. if parseDateErr != nil {
  3658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3659. return
  3660. }
  3661. adminInfo := this.GetMobileAdminUserInfo()
  3662. orgID := adminInfo.Org.Id
  3663. redis := service.RedisClient()
  3664. defer redis.Close()
  3665. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  3666. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  3667. if len(scheduals) > 0 {
  3668. //缓存数据
  3669. scheduals_json, err := json.Marshal(scheduals)
  3670. if err == nil {
  3671. redis.Set(key, scheduals_json, time.Second*30)
  3672. }
  3673. }
  3674. this.ServeSuccessJSON(map[string]interface{}{
  3675. "scheduals": scheduals,
  3676. })
  3677. }
  3678. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  3679. change_type, _ := this.GetInt64("type", 0)
  3680. record_date := this.GetString("record_time")
  3681. patient_id, _ := this.GetInt64("patient_id", 0)
  3682. timeLayout := "2006-01-02"
  3683. loc, _ := time.LoadLocation("Local")
  3684. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3685. record_time := theAdviceRecordTime.Unix()
  3686. adminUserInfo := this.GetMobileAdminUserInfo()
  3687. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  3688. if err == nil {
  3689. if len(advices) == 0 {
  3690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3691. return
  3692. } else {
  3693. this.ServeSuccessJSON(map[string]interface{}{
  3694. "advices": advices,
  3695. "schedule": sch,
  3696. })
  3697. return
  3698. }
  3699. } else {
  3700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3701. return
  3702. }
  3703. }
  3704. func (c *DialysisAPIController) CreateConsumables() {
  3705. record_date := c.GetString("record_time")
  3706. patient_id, _ := c.GetInt64("patient_id", 0)
  3707. active, _ := c.GetInt64("active")
  3708. adminUser := c.GetMobileAdminUserInfo()
  3709. timeLayout := "2006-01-02"
  3710. loc, _ := time.LoadLocation("Local")
  3711. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3712. record_time := theRecordTime.Unix()
  3713. dataBody := make(map[string]interface{}, 0)
  3714. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3715. if err != nil {
  3716. utils.ErrorLog(err.Error())
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3718. return
  3719. }
  3720. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3721. var beforePrepares []*models.DialysisBeforePrepareGoods
  3722. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  3723. var dialysisBefor []*models.DialysisBeforePrepare
  3724. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3725. goods, _ := dataBody["goods"].([]interface{})
  3726. if len(goods) > 0 {
  3727. for _, item := range goods {
  3728. items := item.(map[string]interface{})
  3729. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3730. utils.ErrorLog("good_id")
  3731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3732. return
  3733. }
  3734. good_id := int64(items["good_id"].(float64))
  3735. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3736. utils.ErrorLog("good_type_id")
  3737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3738. return
  3739. }
  3740. good_type_id := int64(items["good_type_id"].(float64))
  3741. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3742. utils.ErrorLog("count")
  3743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3744. return
  3745. }
  3746. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3747. commdity_code := items["commdity_code"].(string)
  3748. fmt.Println("commdity", commdity_code)
  3749. prepareGoods := &models.DialysisBeforePrepareGoods{
  3750. GoodTypeId: good_type_id,
  3751. GoodId: good_id,
  3752. Count: count,
  3753. StorehouseId: houseConfig.StorehouseOutInfo,
  3754. }
  3755. beforePrepares = append(beforePrepares, prepareGoods)
  3756. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  3757. GoodTypeId: good_type_id,
  3758. GoodId: good_id,
  3759. Count: count,
  3760. StorehouseId: houseConfig.StorehouseOutInfo,
  3761. }
  3762. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  3763. prepare := &models.DialysisBeforePrepare{
  3764. GoodTypeId: good_type_id,
  3765. GoodId: good_id,
  3766. Count: count,
  3767. PatientId: patient_id,
  3768. RecordDate: record_time,
  3769. UserOrgId: adminUser.Org.Id,
  3770. Status: 1,
  3771. Ctime: time.Now().Unix(),
  3772. Creater: adminUser.AdminUser.Id,
  3773. CommdityCode: commdity_code,
  3774. StorehouseId: houseConfig.StorehouseOutInfo,
  3775. }
  3776. dialysisBefor = append(dialysisBefor, prepare)
  3777. }
  3778. }
  3779. //查询是否有库存
  3780. for _, item := range dialysisBefor {
  3781. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  3782. if err == gorm.ErrRecordNotFound {
  3783. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3784. c.ServeSuccessJSON(map[string]interface{}{
  3785. "message": "1",
  3786. "good_name": goodObj.GoodName,
  3787. "specification_name": goodObj.SpecificationName,
  3788. })
  3789. return
  3790. }
  3791. if err != nil {
  3792. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3793. c.ServeSuccessJSON(map[string]interface{}{
  3794. "message": "1",
  3795. "good_name": goodObj.GoodName,
  3796. "specification_name": goodObj.SpecificationName,
  3797. })
  3798. return
  3799. }
  3800. }
  3801. //新增
  3802. if active == 1 && len(goods) > 0 {
  3803. for _, item := range dialysisBefor {
  3804. dialyPrepareOne := models.DialysisBeforePrepare{
  3805. GoodTypeId: item.GoodTypeId,
  3806. GoodId: item.GoodId,
  3807. PatientId: item.PatientId,
  3808. RecordDate: item.RecordDate,
  3809. UserOrgId: item.UserOrgId,
  3810. Count: item.Count,
  3811. Ctime: time.Now().Unix(),
  3812. Creater: item.Creater,
  3813. CommdityCode: item.CommdityCode,
  3814. Status: 1,
  3815. StorehouseId: houseConfig.StorehouseOutInfo,
  3816. }
  3817. //先清除再插入
  3818. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3819. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  3820. //查询默认仓库
  3821. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3822. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3823. var total_count int64
  3824. for _, it := range stockList {
  3825. total_count += it.StockCount
  3826. }
  3827. //基础库插入数据
  3828. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3829. //更新库存
  3830. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3831. var flush_count int64
  3832. for _, it := range goodList {
  3833. flush_count += it.StockCount
  3834. }
  3835. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3836. }
  3837. if err == nil {
  3838. c.ServeSuccessJSON(map[string]interface{}{
  3839. "msg": "保存成功",
  3840. "message": "2",
  3841. })
  3842. return
  3843. } else {
  3844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3845. return
  3846. }
  3847. }
  3848. if len(beforePrepares) > 0 && active == 2 {
  3849. for _, item := range beforePrepares {
  3850. //1.查看该患者该耗材型号最后一次出库数量
  3851. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  3852. //判断当前出库数量和最后一次出库数量的大小
  3853. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  3854. if item.Count <= goodInfo.Count {
  3855. //退库
  3856. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  3857. //查询今日出库数据
  3858. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3859. for _, it := range list {
  3860. prepare := models.DialysisBeforePrepare{
  3861. UserOrgId: it.OrgId,
  3862. PatientId: patient_id,
  3863. RecordDate: it.RecordTime,
  3864. GoodId: it.GoodId,
  3865. GoodTypeId: it.GoodTypeId,
  3866. Count: it.Count,
  3867. Ctime: time.Now().Unix(),
  3868. Creater: adminUser.AdminUser.Id,
  3869. Status: 1,
  3870. StorehouseId: houseConfig.StorehouseOutInfo,
  3871. }
  3872. //删除准备表数据
  3873. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3874. service.CreateDialysisBeforePrepareOne(&prepare)
  3875. }
  3876. }
  3877. var last_total int64
  3878. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  3879. if item.Count >= goodInfo.Count {
  3880. //查询当前批次当前耗材最后一条出库数据
  3881. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3882. //计算当前出库和最后一次出库数据相差数据
  3883. last_total = item.Count - lastOutInfo.Count
  3884. //查询该批次剩余库存
  3885. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  3886. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  3887. if lastInfo.StockCount >= last_total {
  3888. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3889. //查询今日出库数据
  3890. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3891. for _, it := range list {
  3892. prepare := models.DialysisBeforePrepare{
  3893. UserOrgId: it.OrgId,
  3894. PatientId: patient_id,
  3895. RecordDate: it.RecordTime,
  3896. GoodId: it.GoodId,
  3897. GoodTypeId: it.GoodTypeId,
  3898. Count: it.Count,
  3899. Ctime: time.Now().Unix(),
  3900. Creater: adminUser.AdminUser.Id,
  3901. Status: 1,
  3902. StorehouseId: houseConfig.StorehouseOutInfo,
  3903. }
  3904. //删除准备表数据
  3905. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3906. service.CreateDialysisBeforePrepareOne(&prepare)
  3907. //查询默认仓库
  3908. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3909. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3910. var total_count int64
  3911. for _, it := range stockList {
  3912. total_count += it.StockCount
  3913. }
  3914. //基础库插入数据
  3915. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3916. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3917. var flush_count int64
  3918. for _, it := range goodList {
  3919. flush_count += it.StockCount
  3920. }
  3921. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3922. }
  3923. }
  3924. //如果库存不够,则出库到下一个批次
  3925. if lastInfo.StockCount < last_total {
  3926. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3927. //查询今日出库数据
  3928. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3929. for _, it := range list {
  3930. prepare := models.DialysisBeforePrepare{
  3931. UserOrgId: it.OrgId,
  3932. PatientId: patient_id,
  3933. RecordDate: it.RecordTime,
  3934. GoodId: it.GoodId,
  3935. GoodTypeId: it.GoodTypeId,
  3936. Count: it.Count,
  3937. Ctime: time.Now().Unix(),
  3938. Creater: adminUser.AdminUser.Id,
  3939. Status: 1,
  3940. StorehouseId: houseConfig.StorehouseOutInfo,
  3941. }
  3942. //删除准备表数据
  3943. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3944. service.CreateDialysisBeforePrepareOne(&prepare)
  3945. //查询默认仓库
  3946. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3947. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3948. var total_count int64
  3949. for _, it := range stockList {
  3950. total_count += it.StockCount
  3951. }
  3952. //基础库插入数据
  3953. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3954. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3955. var flush_count int64
  3956. for _, it := range goodList {
  3957. flush_count += it.StockCount
  3958. }
  3959. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3960. }
  3961. if err != nil {
  3962. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3963. c.ServeSuccessJSON(map[string]interface{}{
  3964. "message": "1",
  3965. "good_name": goodObj.GoodName,
  3966. "specification_name": goodObj.SpecificationName,
  3967. })
  3968. return
  3969. }
  3970. }
  3971. }
  3972. if err != nil {
  3973. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3974. c.ServeSuccessJSON(map[string]interface{}{
  3975. "message": "1",
  3976. "good_name": goodObj.GoodName,
  3977. "specification_name": goodObj.SpecificationName,
  3978. })
  3979. return
  3980. }
  3981. }
  3982. }
  3983. }
  3984. var errs error
  3985. if errs == nil {
  3986. c.ServeSuccessJSON(map[string]interface{}{
  3987. "msg": "提交成功",
  3988. "message": "2",
  3989. "good_name": "",
  3990. "specification_name": "",
  3991. })
  3992. return
  3993. } else {
  3994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3995. return
  3996. }
  3997. }
  3998. func (c *DialysisAPIController) CreateStockOutInfo() {
  3999. patient_id, _ := c.GetInt64("patient_id", 0)
  4000. record_date := c.GetString("record_time")
  4001. if patient_id <= 0 {
  4002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4003. return
  4004. }
  4005. adminInfo := c.GetMobileAdminUserInfo()
  4006. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  4007. timeLayout := "2006-01-02"
  4008. loc, _ := time.LoadLocation("Local")
  4009. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4010. record_time := theRecordTime.Unix()
  4011. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  4012. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4013. //去重
  4014. consumables = RemoveRepeatedGood(consumables)
  4015. if record.IsOpen == 1 {
  4016. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4017. //查询是否有库存
  4018. for _, item := range consumables {
  4019. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4020. if item.Count > warehouse.Count {
  4021. goodErrcode := models.XtGoodErrcode{
  4022. UserOrgId: item.UserOrgId,
  4023. Errcode: "自动出库库存不足",
  4024. GoodId: item.GoodId,
  4025. Status: 1,
  4026. Ctime: time.Now().Unix(),
  4027. Mtime: 0,
  4028. Count: 0,
  4029. StockCount: 0,
  4030. Creater: creator,
  4031. BatchNumberId: warehouse.ID,
  4032. WarehouseOutId: 0,
  4033. }
  4034. service.CreateGoodErrcode(goodErrcode)
  4035. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4036. c.ServeSuccessJSON(map[string]interface{}{
  4037. "message": "1",
  4038. "good_name": goodObj.GoodName,
  4039. "specification_name": goodObj.SpecificationName,
  4040. })
  4041. return
  4042. }
  4043. }
  4044. //查询是否有出库单
  4045. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4046. if err == gorm.ErrRecordNotFound {
  4047. //没有记录,则创建出库单
  4048. timeStr := time.Now().Format("2006-01-02")
  4049. timeArr := strings.Split(timeStr, "-")
  4050. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4051. total = total + 1
  4052. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4053. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4054. number = number + total
  4055. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4056. creater := adminInfo.AdminUser.Id
  4057. warehouseOut := models.WarehouseOut{
  4058. WarehouseOutOrderNumber: warehousing_out_order,
  4059. OperationTime: time.Now().Unix(),
  4060. OrgId: adminInfo.Org.Id,
  4061. Creater: creater,
  4062. Ctime: time.Now().Unix(),
  4063. Status: 1,
  4064. WarehouseOutTime: record_time,
  4065. Dealer: 0,
  4066. Manufacturer: 0,
  4067. Type: 1,
  4068. IsSys: 1,
  4069. StorehouseId: houseConfig.StorehouseOutInfo,
  4070. IsCheck: 1,
  4071. }
  4072. err := service.AddSigleWarehouseOut(&warehouseOut)
  4073. if err != nil {
  4074. goodErrcode := models.XtGoodErrcode{
  4075. UserOrgId: adminInfo.Org.Id,
  4076. Errcode: "创建出库单失败",
  4077. GoodId: 0,
  4078. Status: 1,
  4079. Ctime: time.Now().Unix(),
  4080. Mtime: 0,
  4081. Count: 0,
  4082. StockCount: 0,
  4083. Creater: creator,
  4084. BatchNumberId: 0,
  4085. WarehouseOutId: 0,
  4086. }
  4087. service.CreateGoodErrcode(goodErrcode)
  4088. utils.TraceLog("创建出库单失败 err = %v", err)
  4089. } else {
  4090. for _, item := range consumables {
  4091. //出库
  4092. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  4093. if err == nil {
  4094. goodErrcode := models.XtGoodErrcode{
  4095. UserOrgId: adminInfo.Org.Id,
  4096. Errcode: "自动出库接口报错",
  4097. GoodId: 0,
  4098. Status: 1,
  4099. Ctime: time.Now().Unix(),
  4100. Mtime: 0,
  4101. Count: 0,
  4102. StockCount: 0,
  4103. Creater: creator,
  4104. BatchNumberId: 0,
  4105. WarehouseOutId: 0,
  4106. }
  4107. service.CreateGoodErrcode(goodErrcode)
  4108. utils.TraceLog("创建出库单失败 err = %v", err)
  4109. }
  4110. //查询
  4111. //出库数量相加
  4112. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4113. if errs != nil {
  4114. goodErrcode := models.XtGoodErrcode{
  4115. UserOrgId: item.UserOrgId,
  4116. Errcode: "创建剩余库存字段报错",
  4117. GoodId: item.GoodId,
  4118. Status: 1,
  4119. Ctime: time.Now().Unix(),
  4120. Mtime: 0,
  4121. Count: 0,
  4122. StockCount: 0,
  4123. Creater: creater,
  4124. BatchNumberId: 0,
  4125. WarehouseOutId: 0,
  4126. }
  4127. service.CreateGoodErrcode(goodErrcode)
  4128. }
  4129. }
  4130. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4131. if len(list) == 0 {
  4132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4133. return
  4134. }
  4135. for _, item := range list {
  4136. prepare := models.DialysisBeforePrepare{
  4137. UserOrgId: adminInfo.Org.Id,
  4138. PatientId: patient_id,
  4139. RecordDate: record_time,
  4140. GoodId: item.GoodId,
  4141. GoodTypeId: item.GoodTypeId,
  4142. Count: item.Count,
  4143. Creater: adminInfo.AdminUser.Id,
  4144. Status: 1,
  4145. Ctime: time.Now().Unix(),
  4146. StorehouseId: houseConfig.StorehouseOutInfo,
  4147. }
  4148. //清空准备表数据
  4149. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4150. if err != nil {
  4151. goodErrcode := models.XtGoodErrcode{
  4152. UserOrgId: item.OrgId,
  4153. Errcode: "自动出库清空准备表数据报错",
  4154. GoodId: item.GoodId,
  4155. Status: 1,
  4156. Ctime: time.Now().Unix(),
  4157. Mtime: 0,
  4158. Count: 0,
  4159. StockCount: 0,
  4160. Creater: creater,
  4161. BatchNumberId: 0,
  4162. WarehouseOutId: 0,
  4163. }
  4164. service.CreateGoodErrcode(goodErrcode)
  4165. }
  4166. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  4167. if errs != nil {
  4168. goodErrcode := models.XtGoodErrcode{
  4169. UserOrgId: item.OrgId,
  4170. Errcode: "自动出库创建准备表数据报错",
  4171. GoodId: item.GoodId,
  4172. Status: 1,
  4173. Ctime: time.Now().Unix(),
  4174. Mtime: 0,
  4175. Count: 0,
  4176. StockCount: 0,
  4177. Creater: creater,
  4178. BatchNumberId: 0,
  4179. WarehouseOutId: 0,
  4180. }
  4181. service.CreateGoodErrcode(goodErrcode)
  4182. }
  4183. //查询默认仓库
  4184. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4185. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4186. var total_count int64
  4187. for _, it := range stockList {
  4188. total_count += it.StockCount
  4189. }
  4190. //基础库插入数据
  4191. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4192. if errcodes != nil {
  4193. goodErrcode := models.XtGoodErrcode{
  4194. UserOrgId: item.OrgId,
  4195. Errcode: "自动出库基础库插入数据",
  4196. GoodId: item.GoodId,
  4197. Status: 1,
  4198. Ctime: time.Now().Unix(),
  4199. Mtime: 0,
  4200. Count: 0,
  4201. StockCount: 0,
  4202. Creater: creater,
  4203. BatchNumberId: 0,
  4204. WarehouseOutId: 0,
  4205. }
  4206. service.CreateGoodErrcode(goodErrcode)
  4207. }
  4208. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4209. var flush_count int64
  4210. for _, it := range goodList {
  4211. flush_count += it.StockCount
  4212. }
  4213. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4214. if errsss != nil {
  4215. goodErrcode := models.XtGoodErrcode{
  4216. UserOrgId: item.OrgId,
  4217. Errcode: "自动出库剩余库存更新数据",
  4218. GoodId: item.GoodId,
  4219. Status: 1,
  4220. Ctime: time.Now().Unix(),
  4221. Mtime: 0,
  4222. Count: 0,
  4223. StockCount: 0,
  4224. Creater: creater,
  4225. BatchNumberId: 0,
  4226. WarehouseOutId: 0,
  4227. }
  4228. service.CreateGoodErrcode(goodErrcode)
  4229. }
  4230. }
  4231. }
  4232. //
  4233. } else if err == nil {
  4234. for _, item := range consumables {
  4235. //出库
  4236. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  4237. if err != nil {
  4238. goodErrcode := models.XtGoodErrcode{
  4239. UserOrgId: adminInfo.Org.Id,
  4240. Errcode: "自动出库接口报错",
  4241. GoodId: 0,
  4242. Status: 1,
  4243. Ctime: time.Now().Unix(),
  4244. Mtime: 0,
  4245. Count: 0,
  4246. StockCount: 0,
  4247. Creater: creator,
  4248. BatchNumberId: 0,
  4249. WarehouseOutId: 0,
  4250. }
  4251. service.CreateGoodErrcode(goodErrcode)
  4252. }
  4253. //出库数量相加
  4254. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4255. if errss != nil {
  4256. goodErrcode := models.XtGoodErrcode{
  4257. UserOrgId: item.UserOrgId,
  4258. Errcode: "创建剩余库存字段报错",
  4259. GoodId: item.GoodId,
  4260. Status: 1,
  4261. Ctime: time.Now().Unix(),
  4262. Mtime: time.Now().Unix(),
  4263. Count: 0,
  4264. StockCount: 0,
  4265. Creater: item.Creater,
  4266. BatchNumberId: 0,
  4267. WarehouseOutId: 0,
  4268. }
  4269. service.CreateGoodErrcode(goodErrcode)
  4270. }
  4271. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4272. if len(list) == 0 {
  4273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4274. return
  4275. }
  4276. for _, item := range list {
  4277. prepare := models.DialysisBeforePrepare{
  4278. UserOrgId: adminInfo.Org.Id,
  4279. PatientId: patient_id,
  4280. RecordDate: record_time,
  4281. GoodId: item.GoodId,
  4282. GoodTypeId: item.GoodTypeId,
  4283. Count: item.Count,
  4284. Creater: adminInfo.AdminUser.Id,
  4285. Status: 1,
  4286. Ctime: time.Now().Unix(),
  4287. StorehouseId: houseConfig.StorehouseOutInfo,
  4288. }
  4289. //清空准备表数据
  4290. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4291. if errs != nil {
  4292. goodErrcode := models.XtGoodErrcode{
  4293. UserOrgId: adminInfo.Org.Id,
  4294. Errcode: "自动出库清空准备表数据报错",
  4295. GoodId: 0,
  4296. Status: 1,
  4297. Ctime: time.Now().Unix(),
  4298. Mtime: 0,
  4299. Count: 0,
  4300. StockCount: 0,
  4301. Creater: creator,
  4302. BatchNumberId: 0,
  4303. WarehouseOutId: 0,
  4304. }
  4305. service.CreateGoodErrcode(goodErrcode)
  4306. }
  4307. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  4308. if errcodes != nil {
  4309. goodErrcode := models.XtGoodErrcode{
  4310. UserOrgId: adminInfo.Org.Id,
  4311. Errcode: "自动出库创建准备表数据报错",
  4312. GoodId: 0,
  4313. Status: 1,
  4314. Ctime: time.Now().Unix(),
  4315. Mtime: 0,
  4316. Count: 0,
  4317. StockCount: 0,
  4318. Creater: creator,
  4319. BatchNumberId: 0,
  4320. WarehouseOutId: 0,
  4321. }
  4322. service.CreateGoodErrcode(goodErrcode)
  4323. }
  4324. //查询默认仓库
  4325. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4326. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4327. var total_count int64
  4328. for _, it := range stockList {
  4329. total_count += it.StockCount
  4330. }
  4331. //基础库插入数据
  4332. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4333. if errcodes != nil {
  4334. goodErrcode := models.XtGoodErrcode{
  4335. UserOrgId: adminInfo.Org.Id,
  4336. Errcode: "自动出库基础库插入数据报错",
  4337. GoodId: 0,
  4338. Status: 1,
  4339. Ctime: time.Now().Unix(),
  4340. Mtime: 0,
  4341. Count: 0,
  4342. StockCount: 0,
  4343. Creater: creator,
  4344. BatchNumberId: 0,
  4345. WarehouseOutId: 0,
  4346. }
  4347. service.CreateGoodErrcode(goodErrcode)
  4348. }
  4349. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4350. var flush_count int64
  4351. for _, it := range goodList {
  4352. flush_count += it.StockCount
  4353. }
  4354. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4355. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  4356. if errss != nil {
  4357. goodErrcode := models.XtGoodErrcode{
  4358. UserOrgId: item.OrgId,
  4359. Errcode: "自动出库剩余库存更新数据",
  4360. GoodId: item.GoodId,
  4361. Status: 1,
  4362. Ctime: time.Now().Unix(),
  4363. Mtime: 0,
  4364. Count: 0,
  4365. StockCount: 0,
  4366. Creater: creater,
  4367. BatchNumberId: 0,
  4368. WarehouseOutId: 0,
  4369. }
  4370. service.CreateGoodErrcode(goodErrcode)
  4371. }
  4372. }
  4373. }
  4374. }
  4375. c.ServeSuccessJSON(map[string]interface{}{
  4376. "msg": "提交成功",
  4377. "message": "2",
  4378. "good_name": "",
  4379. "specification_name": "",
  4380. })
  4381. return
  4382. } else {
  4383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4384. return
  4385. }
  4386. }
  4387. func (c *DialysisAPIController) EditConsumables() {
  4388. patient_id, _ := c.GetInt64("patient_id", 0)
  4389. record_date := c.GetString("record_time")
  4390. if patient_id <= 0 {
  4391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4392. return
  4393. }
  4394. adminInfo := c.GetMobileAdminUserInfo()
  4395. timeLayout := "2006-01-02"
  4396. loc, _ := time.LoadLocation("Local")
  4397. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4398. record_time := theRecordTime.Unix()
  4399. dataBody := make(map[string]interface{}, 0)
  4400. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4401. if err != nil {
  4402. utils.ErrorLog(err.Error())
  4403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4404. return
  4405. }
  4406. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4407. var beforePrepares []*models.DialysisBeforePrepareGoods
  4408. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4409. var cancelbefor []*models.DialysisBeforePrepareGoods
  4410. var outbefor []*models.DialysisBeforePrepareGoods
  4411. //判断是否开启自动出库
  4412. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4413. if record.IsOpen == 1 {
  4414. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4415. goods, _ := dataBody["goods"].([]interface{})
  4416. if len(goods) > 0 {
  4417. for _, item := range goods {
  4418. items := item.(map[string]interface{})
  4419. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4420. utils.ErrorLog("good_id")
  4421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4422. return
  4423. }
  4424. good_id := int64(items["good_id"].(float64))
  4425. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4426. utils.ErrorLog("good_type_id")
  4427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4428. return
  4429. }
  4430. good_type_id := int64(items["good_type_id"].(float64))
  4431. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4432. utils.ErrorLog("count")
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4434. return
  4435. }
  4436. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4437. commdity_code := items["commdity_code"].(string)
  4438. fmt.Println(commdity_code)
  4439. prepareGoods := &models.DialysisBeforePrepareGoods{
  4440. GoodTypeId: good_type_id,
  4441. GoodId: good_id,
  4442. Count: count,
  4443. StorehouseId: houseConfig.StorehouseOutInfo,
  4444. }
  4445. beforePrepares = append(beforePrepares, prepareGoods)
  4446. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4447. GoodTypeId: good_type_id,
  4448. GoodId: good_id,
  4449. Count: count,
  4450. StorehouseId: houseConfig.StorehouseOutInfo,
  4451. }
  4452. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4453. }
  4454. for _, item := range beforePrepares {
  4455. //1.查看该患者该耗材型号最后一次出库数量
  4456. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4457. //判断当前出库数量和最后一次出库数量的大小
  4458. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  4459. if item.Count < goodInfo.Count {
  4460. cancelbefor = append(cancelbefor, item)
  4461. }
  4462. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4463. if item.Count > goodInfo.Count {
  4464. outbefor = append(outbefor, item)
  4465. }
  4466. //处理编辑耗材新增不了的问题
  4467. if goodInfo.Count == item.Count {
  4468. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  4469. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  4470. }
  4471. }
  4472. fmt.Println("退库长度", len(cancelbefor))
  4473. fmt.Println("出库长度", len(outbefor))
  4474. //退库
  4475. for _, item := range cancelbefor {
  4476. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4477. creater := adminInfo.AdminUser.Id
  4478. //退库
  4479. //err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
  4480. //查询该患者当天已经出库的耗材信息
  4481. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  4482. var delete_count int64 = 0
  4483. delete_count = warehouseOutInfos.Count - item.Count
  4484. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4485. // 在出库记录表里记录退库详情
  4486. warehouseOutInfo := &models.WarehouseOutInfo{
  4487. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4488. WarehouseOutId: warehouseOut.ID,
  4489. Status: 1,
  4490. Ctime: time.Now().Unix(),
  4491. OrgId: adminInfo.Org.Id,
  4492. Type: 1,
  4493. IsSys: 1,
  4494. SysRecordTime: record_time,
  4495. GoodTypeId: item.GoodTypeId,
  4496. GoodId: item.GoodId,
  4497. PatientId: patient_id,
  4498. ConsumableType: 2,
  4499. StorehouseId: houseConfig.StorehouseOutInfo,
  4500. IsCheck: 1,
  4501. }
  4502. warehouseOutInfo.Count = item.Count
  4503. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  4504. warehouseOutInfo.Price = stockInInfo.Price
  4505. warehouseOutInfo.Dealer = stockInInfo.Dealer
  4506. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  4507. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  4508. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  4509. warehouseOutInfo.Number = warehouseOutInfos.Number
  4510. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  4511. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  4512. //查找当天是否存在出库记录
  4513. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  4514. if errcod == gorm.ErrRecordNotFound {
  4515. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4516. //插入详情明细表
  4517. stockFlow := models.VmStockFlow{
  4518. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4519. WarehouseOutId: warehouseOut.ID,
  4520. GoodId: item.GoodId,
  4521. Number: warehouseOutInfos.Number,
  4522. ProductDate: stockInInfo.ProductDate,
  4523. ExpireDate: stockInInfo.ExpiryDate,
  4524. Count: item.Count,
  4525. Price: stockInInfo.Price,
  4526. Status: 1,
  4527. Ctime: time.Now().Unix(),
  4528. UserOrgId: adminInfo.Org.Id,
  4529. Manufacturer: stockInInfo.Manufacturer,
  4530. Dealer: stockInInfo.Dealer,
  4531. LicenseNumber: stockInInfo.LicenseNumber,
  4532. IsEdit: 2,
  4533. Creator: creater,
  4534. SystemTime: record_time,
  4535. ConsumableType: 3,
  4536. WarehousingDetailId: 0,
  4537. IsSys: 1,
  4538. UpdateCreator: creater,
  4539. PatientId: patient_id,
  4540. StorehouseId: houseConfig.StorehouseOutInfo,
  4541. }
  4542. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4543. if errflow == gorm.ErrRecordNotFound {
  4544. //创建流水表
  4545. err := service.CreateStockFlowOne(stockFlow)
  4546. fmt.Println("err", err)
  4547. } else if errflow == nil {
  4548. //插入详情明细表
  4549. stockFlow := models.VmStockFlow{
  4550. ID: exsit.ID,
  4551. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4552. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4553. WarehouseOutId: warehouseOut.ID,
  4554. GoodId: item.GoodId,
  4555. Number: warehouseOutInfos.Number,
  4556. ProductDate: stockInInfo.ProductDate,
  4557. ExpireDate: stockInInfo.ExpiryDate,
  4558. Count: exsit.Count - delete_count,
  4559. Price: stockInInfo.Price,
  4560. Status: 1,
  4561. Ctime: time.Now().Unix(),
  4562. UserOrgId: adminInfo.Org.Id,
  4563. Manufacturer: stockInInfo.Manufacturer,
  4564. Dealer: stockInInfo.Dealer,
  4565. LicenseNumber: stockInInfo.LicenseNumber,
  4566. IsEdit: 2,
  4567. Creator: creater,
  4568. SystemTime: record_time,
  4569. ConsumableType: 3,
  4570. WarehousingDetailId: 0,
  4571. IsSys: 1,
  4572. UpdateCreator: creater,
  4573. PatientId: patient_id,
  4574. StorehouseId: houseConfig.StorehouseOutInfo,
  4575. }
  4576. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4577. }
  4578. } else if errcod == nil {
  4579. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  4580. //插入详情明细表
  4581. stockFlow := models.VmStockFlow{
  4582. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4583. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4584. WarehouseOutId: warehouseOut.ID,
  4585. GoodId: item.GoodId,
  4586. Number: warehouseOutInfos.Number,
  4587. ProductDate: stockInInfo.ProductDate,
  4588. ExpireDate: stockInInfo.ExpiryDate,
  4589. Count: item.Count,
  4590. Price: stockInInfo.Price,
  4591. Status: 1,
  4592. Ctime: time.Now().Unix(),
  4593. UserOrgId: adminInfo.Org.Id,
  4594. Manufacturer: stockInInfo.Manufacturer,
  4595. Dealer: stockInInfo.Dealer,
  4596. LicenseNumber: stockInInfo.LicenseNumber,
  4597. IsEdit: 2,
  4598. Creator: creater,
  4599. SystemTime: record_time,
  4600. ConsumableType: 3,
  4601. WarehousingDetailId: 0,
  4602. IsSys: 1,
  4603. UpdateCreator: creater,
  4604. PatientId: patient_id,
  4605. ReturnCount: delete_count,
  4606. StorehouseId: houseConfig.StorehouseOutInfo,
  4607. }
  4608. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4609. if errflows == gorm.ErrRecordNotFound {
  4610. //创建流水表
  4611. service.CreateStockFlowOne(stockFlow)
  4612. } else if errflows == nil {
  4613. stockFlow := models.VmStockFlow{
  4614. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4615. ID: exsit.ID,
  4616. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4617. WarehouseOutId: warehouseOut.ID,
  4618. GoodId: item.GoodId,
  4619. Number: warehouseOutInfos.Number,
  4620. ProductDate: stockInInfo.ProductDate,
  4621. ExpireDate: stockInInfo.ExpiryDate,
  4622. Count: exsit.Count - delete_count,
  4623. Price: stockInInfo.Price,
  4624. Status: 1,
  4625. Ctime: time.Now().Unix(),
  4626. UserOrgId: adminInfo.Org.Id,
  4627. Manufacturer: stockInInfo.Manufacturer,
  4628. Dealer: stockInInfo.Dealer,
  4629. LicenseNumber: stockInInfo.LicenseNumber,
  4630. IsEdit: 2,
  4631. Creator: creater,
  4632. SystemTime: record_time,
  4633. ConsumableType: 3,
  4634. WarehousingDetailId: 0,
  4635. IsSys: 1,
  4636. UpdateCreator: creater,
  4637. PatientId: patient_id,
  4638. ReturnCount: delete_count,
  4639. StorehouseId: houseConfig.StorehouseOutInfo,
  4640. }
  4641. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4642. }
  4643. }
  4644. //更改自动出库的表格
  4645. details := models.BloodAutomaticReduceDetail{
  4646. WarehouseOutId: warehouseOutInfo.ID,
  4647. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4648. PatientId: patient_id,
  4649. Ctime: time.Now().Unix(),
  4650. Mtime: time.Now().Unix(),
  4651. Status: 1,
  4652. RecordTime: record_time,
  4653. OrgId: adminInfo.Org.Id,
  4654. GoodId: item.GoodId,
  4655. GoodTypeId: item.GoodTypeId,
  4656. Count: item.Count,
  4657. StorehouseId: houseConfig.StorehouseOutInfo,
  4658. }
  4659. //查询当天耗材是否已经存在数据
  4660. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4661. if errcode == gorm.ErrRecordNotFound {
  4662. service.CreateAutoReduceRecord(&details)
  4663. } else if errcode == nil {
  4664. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4665. service.CreateAutoReduceRecord(&details)
  4666. }
  4667. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  4668. //增加出库库存数量
  4669. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  4670. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
  4671. fmt.Println("errOne", errOne)
  4672. // 删除出库完成后,要增加对应批次的库存数量
  4673. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  4674. //查询默认仓库
  4675. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4676. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4677. var total_count int64
  4678. for _, it := range stockList {
  4679. total_count += it.StockCount
  4680. }
  4681. //基础库插入数据
  4682. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4683. //更新剩余库存
  4684. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4685. var flush_count int64
  4686. for _, it := range goodList {
  4687. flush_count += it.StockCount
  4688. }
  4689. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4690. }
  4691. //出库
  4692. for _, item := range outbefor {
  4693. fmt.Println("出库ID", item.GoodId)
  4694. var last_total int64
  4695. //1.查看该患者该耗材型号最后一次出库数量
  4696. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4697. //计算当前出库和最后一次出库数据相差数据
  4698. last_total = item.Count - goodInfoOne.Count
  4699. //查询该批次剩余库存
  4700. lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
  4701. if lastInfo.StockCount == 0 {
  4702. //查询该耗材的总库存
  4703. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4704. if wareinfo.StockCount == 0 {
  4705. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4706. c.ServeSuccessJSON(map[string]interface{}{
  4707. "message": "1",
  4708. "good_name": goodObj.GoodName,
  4709. "specification_name": goodObj.SpecificationName,
  4710. })
  4711. return
  4712. }
  4713. }
  4714. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  4715. //查询该耗材的总库存
  4716. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4717. // 如果库存差大于剩余库存则提示库存不足
  4718. if last_total > wareinfo.StockCount {
  4719. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4720. c.ServeSuccessJSON(map[string]interface{}{
  4721. "message": "1",
  4722. "good_name": goodObj.GoodName,
  4723. "specification_name": goodObj.SpecificationName,
  4724. })
  4725. return
  4726. } else {
  4727. fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
  4728. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4729. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4730. if err == gorm.ErrRecordNotFound {
  4731. //没有记录,则创建出库单
  4732. timeStr := time.Now().Format("2006-01-02")
  4733. timeArr := strings.Split(timeStr, "-")
  4734. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4735. total = total + 1
  4736. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4737. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4738. number = number + total
  4739. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4740. warehouseOut := models.WarehouseOut{
  4741. WarehouseOutOrderNumber: warehousing_out_order,
  4742. OperationTime: time.Now().Unix(),
  4743. OrgId: adminInfo.Org.Id,
  4744. Creater: adminInfo.AdminUser.Id,
  4745. Ctime: time.Now().Unix(),
  4746. Status: 1,
  4747. WarehouseOutTime: record_time,
  4748. Dealer: 0,
  4749. Manufacturer: 0,
  4750. Type: 1,
  4751. IsSys: 1,
  4752. StorehouseId: houseConfig.StorehouseOutInfo,
  4753. IsCheck: 1,
  4754. }
  4755. service.AddSigleWarehouseOut(&warehouseOut)
  4756. }
  4757. //出库
  4758. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  4759. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4760. //1.查看该患者该耗材型号最后一次出库数量
  4761. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4762. fmt.Println("count2323323222323wi", item.Count)
  4763. prepare := models.DialysisBeforePrepare{
  4764. UserOrgId: adminInfo.Org.Id,
  4765. PatientId: patient_id,
  4766. RecordDate: record_time,
  4767. GoodId: item.GoodId,
  4768. GoodTypeId: item.GoodTypeId,
  4769. Count: item.Count - goodInfoTwo.Count,
  4770. Ctime: time.Now().Unix(),
  4771. Mtime: 0,
  4772. Creater: adminInfo.AdminUser.Id,
  4773. Modifier: adminInfo.AdminUser.Id,
  4774. Status: 1,
  4775. CommdityCode: "",
  4776. NewCount: 0,
  4777. ProjectId: 0,
  4778. StorehouseId: houseConfig.StorehouseOutInfo,
  4779. }
  4780. fmt.Println("prepare", prepare.Count)
  4781. fmt.Println("count", item.Count)
  4782. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  4783. //增加出库数量
  4784. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  4785. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4786. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4787. var total_count int64
  4788. for _, it := range stockList {
  4789. total_count += it.StockCount
  4790. }
  4791. //基础库插入数据
  4792. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4793. //剩余库存
  4794. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4795. var flush_count int64
  4796. for _, it := range goodList {
  4797. flush_count += it.StockCount
  4798. }
  4799. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4800. }
  4801. }
  4802. //查询今日出库数据
  4803. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4804. for _, it := range list {
  4805. prepare := models.DialysisBeforePrepare{
  4806. UserOrgId: it.OrgId,
  4807. PatientId: patient_id,
  4808. RecordDate: it.RecordTime,
  4809. GoodId: it.GoodId,
  4810. GoodTypeId: it.GoodTypeId,
  4811. Count: it.Count,
  4812. Ctime: time.Now().Unix(),
  4813. Creater: adminInfo.AdminUser.Id,
  4814. Status: 1,
  4815. StorehouseId: houseConfig.StorehouseOutInfo,
  4816. }
  4817. //删除准备表数据
  4818. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  4819. service.CreateDialysisBeforePrepareOne(&prepare)
  4820. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4821. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4822. var total_count int64
  4823. for _, it := range stockList {
  4824. total_count += it.StockCount
  4825. }
  4826. //基础库插入数据
  4827. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  4828. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  4829. var flush_count int64
  4830. for _, it := range goodList {
  4831. flush_count += it.StockCount
  4832. }
  4833. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  4834. //if err != nil {
  4835. // goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
  4836. // c.ServeSuccessJSON(map[string]interface{}{
  4837. // "message": "2",
  4838. // "good_name": goodObj.GoodName,
  4839. // "specification_name": goodObj.SpecificationName,
  4840. // })
  4841. // return
  4842. //}
  4843. }
  4844. }
  4845. }
  4846. //更新自动出库的地方
  4847. var errs error
  4848. if errs == nil {
  4849. c.ServeSuccessJSON(map[string]interface{}{
  4850. "msg": "修改成功",
  4851. "message": "2",
  4852. "good_name": "",
  4853. "specification_name": "",
  4854. })
  4855. return
  4856. } else {
  4857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4858. return
  4859. }
  4860. }
  4861. }
  4862. func (c *DialysisAPIController) GetDialysisGoods() {
  4863. schedualDate := c.GetString("schedule_date")
  4864. schedule_type, _ := c.GetInt64("schedule_type")
  4865. partition_id, _ := c.GetInt64("partition_id")
  4866. page, _ := c.GetInt("page")
  4867. patient_id, _ := c.GetInt64("patient_id")
  4868. schedualEndDate := int64(0)
  4869. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4870. if parseDateErr != nil && len(schedualDate) != 0 {
  4871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4872. return
  4873. }
  4874. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4875. if parseDateErr != nil && len(schedualDate) != 0 {
  4876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4877. return
  4878. }
  4879. schedualEndDate = endDate.Unix()
  4880. adminUser := c.GetMobileAdminUserInfo()
  4881. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  4882. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  4883. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  4884. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  4885. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  4886. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  4887. //获取当天该病人的透析处方
  4888. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  4889. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  4890. if err == gorm.ErrRecordNotFound {
  4891. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4892. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  4893. if patient_id != 0 {
  4894. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4895. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4896. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4897. //获取患者总的出库数据
  4898. item.LastAutomaticReduceDetail = goodUser
  4899. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4900. item.Project = project
  4901. }
  4902. }
  4903. c.ServeSuccessJSON(map[string]interface{}{
  4904. "dialysis_goods": dialysisGoods,
  4905. "good_type": goodTypes,
  4906. "total": total,
  4907. "prescribe": prescribe,
  4908. "good_info": good_info,
  4909. "warehouseOutList": warehouseOutList,
  4910. "config": config,
  4911. "outConfig": outConfig,
  4912. "settleConfig": settleConfig,
  4913. })
  4914. return
  4915. } else if err == nil {
  4916. //获取当天排班的每个患者的库存使用情况
  4917. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4918. //获取患者总的出库数据
  4919. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  4920. if patient_id != 0 {
  4921. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4922. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4923. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4924. item.Project = project
  4925. item.LastAutomaticReduceDetail = goodUser
  4926. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4927. }
  4928. }
  4929. if err == nil {
  4930. c.ServeSuccessJSON(map[string]interface{}{
  4931. "dialysis_goods": dialysisGoods,
  4932. "good_type": goodTypes,
  4933. "total": total,
  4934. "prescribe": prescribe,
  4935. "good_info": good_info,
  4936. "project": project,
  4937. "warehouseOutList": warehouseOutList,
  4938. "config": config,
  4939. "outConfig": outConfig,
  4940. "settleConfig": settleConfig,
  4941. })
  4942. return
  4943. } else {
  4944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4945. return
  4946. }
  4947. } else if err != nil {
  4948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4949. return
  4950. }
  4951. }
  4952. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  4953. start_time := c.GetString("start_time")
  4954. end_time := c.GetString("end_time")
  4955. timeLayout := "2006-01-02"
  4956. loc, _ := time.LoadLocation("Local")
  4957. var theStartTime int64
  4958. if len(start_time) > 0 {
  4959. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4960. if err != nil {
  4961. utils.ErrorLog(err.Error())
  4962. }
  4963. theStartTime = theTime.Unix()
  4964. }
  4965. var theEndtTime int64
  4966. if len(end_time) > 0 {
  4967. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4968. if err != nil {
  4969. utils.ErrorLog(err.Error())
  4970. }
  4971. theEndtTime = theTime.Unix()
  4972. }
  4973. adminUser := c.GetMobileAdminUserInfo()
  4974. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  4975. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  4976. if err == nil {
  4977. c.ServeSuccessJSON(map[string]interface{}{
  4978. "stock_out": outInfo,
  4979. "stockCount": stockCount,
  4980. })
  4981. return
  4982. } else {
  4983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4984. return
  4985. }
  4986. }
  4987. func (c *DialysisAPIController) GetStockInGoodInfo() {
  4988. patient_id, _ := c.GetInt64("patient_id", 0)
  4989. record_time := c.GetString("record_time")
  4990. adminUser := c.GetMobileAdminUserInfo()
  4991. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  4992. if parseDateErr != nil && len(record_time) != 0 {
  4993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4994. return
  4995. }
  4996. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  4997. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  4998. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  4999. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  5000. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5001. //获取今日患者的透析处方参数
  5002. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5003. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  5004. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5005. c.ServeSuccessJSON(map[string]interface{}{
  5006. "good_type": goodTypes,
  5007. "good_user": goodUser,
  5008. "good_info": good_info,
  5009. "last_good_user": lastGoodUserDetial,
  5010. "project": project,
  5011. "prescription": prescribe,
  5012. "outInfo": outInfo,
  5013. "configs": configs,
  5014. })
  5015. return
  5016. }
  5017. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  5018. patient_id, _ := c.GetInt64("patient_id", 0)
  5019. record_date := c.GetString("record_time")
  5020. timeLayout := "2006-01-02"
  5021. loc, _ := time.LoadLocation("Local")
  5022. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5023. record_time := theRecordTime.Unix()
  5024. adminInfo := c.GetMobileAdminUserInfo()
  5025. dataBody := make(map[string]interface{}, 0)
  5026. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5027. if err != nil {
  5028. utils.ErrorLog(err.Error())
  5029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5030. return
  5031. }
  5032. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5033. var beforePrepares []*models.DialysisBeforePrepareGoods
  5034. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5035. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5036. goods, _ := dataBody["goods"].([]interface{})
  5037. if len(goods) > 0 {
  5038. for _, item := range goods {
  5039. items := item.(map[string]interface{})
  5040. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5041. utils.ErrorLog("good_id")
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5043. return
  5044. }
  5045. good_id := int64(items["good_id"].(float64))
  5046. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5047. utils.ErrorLog("good_type_id")
  5048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5049. return
  5050. }
  5051. good_type_id := int64(items["good_type_id"].(float64))
  5052. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5053. utils.ErrorLog("count")
  5054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5055. return
  5056. }
  5057. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5058. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5059. utils.ErrorLog("project_id")
  5060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5061. return
  5062. }
  5063. project_id := int64(items["project_id"].(float64))
  5064. prepare := &models.DialysisBeforePrepareGoods{
  5065. GoodId: good_id,
  5066. GoodTypeId: good_type_id,
  5067. Count: count,
  5068. ProjectId: project_id,
  5069. StorehouseId: houseConfig.StorehouseOutInfo,
  5070. }
  5071. beforePrepares = append(beforePrepares, prepare)
  5072. newPrepare := &models.NewDialysisBeforePrepareGoods{
  5073. GoodId: good_id,
  5074. GoodTypeId: good_type_id,
  5075. Count: count,
  5076. ProjectId: project_id,
  5077. StorehouseId: houseConfig.StorehouseOutInfo,
  5078. }
  5079. newBeforePrepares = append(newBeforePrepares, newPrepare)
  5080. }
  5081. }
  5082. }
  5083. //查询是否有库存
  5084. for _, item := range beforePrepares {
  5085. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5086. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  5087. if item.Count > warehouse.Count {
  5088. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5089. c.ServeSuccessJSON(map[string]interface{}{
  5090. "message": "1",
  5091. "good_name": goodObj.GoodName,
  5092. "specification_name": goodObj.SpecificationName,
  5093. })
  5094. return
  5095. }
  5096. }
  5097. //出库逻辑
  5098. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  5099. if err != nil {
  5100. utils.ErrorLog(err.Error())
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5102. return
  5103. }
  5104. //查询当天出库的数据
  5105. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5106. for _, item := range list {
  5107. prepare := models.DialysisBeforePrepare{
  5108. UserOrgId: item.OrgId,
  5109. PatientId: item.PatientId,
  5110. RecordDate: item.RecordTime,
  5111. GoodId: item.GoodId,
  5112. GoodTypeId: item.GoodTypeId,
  5113. Count: item.Count,
  5114. Creater: adminInfo.AdminUser.Id,
  5115. Status: 1,
  5116. Ctime: time.Now().Unix(),
  5117. ProjectId: item.ProjectId,
  5118. StorehouseId: houseConfig.StorehouseOutInfo,
  5119. }
  5120. //清空准备表的数据
  5121. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5122. //插入准备表数据
  5123. service.CreateDialysisBeforePrepareOne(&prepare)
  5124. //查询默认仓库
  5125. //查询默认仓库
  5126. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5127. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5128. var total_count int64
  5129. for _, it := range stockList {
  5130. total_count += it.StockCount
  5131. }
  5132. //基础库插入数据
  5133. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5134. ////更新剩余库存
  5135. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5136. var flush_count int64
  5137. for _, it := range goodList {
  5138. flush_count += it.StockCount
  5139. }
  5140. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5141. if errs != nil {
  5142. goodErrcode := models.XtGoodErrcode{
  5143. UserOrgId: item.OrgId,
  5144. Errcode: "手动出库更新剩余出库失败",
  5145. GoodId: item.GoodId,
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Count: 0,
  5150. StockCount: 0,
  5151. Creater: adminInfo.AdminUser.Id,
  5152. BatchNumberId: 0,
  5153. WarehouseOutId: 0,
  5154. }
  5155. service.CreateGoodErrcode(goodErrcode)
  5156. }
  5157. }
  5158. //更新自动出库的地方
  5159. var errs error
  5160. if errs == nil {
  5161. c.ServeSuccessJSON(map[string]interface{}{
  5162. "msg": "修改成功",
  5163. "message": "2",
  5164. "good_name": "",
  5165. "specification_name": "",
  5166. })
  5167. return
  5168. } else {
  5169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5170. return
  5171. }
  5172. }
  5173. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5174. newArr = make([]*models.DialysisBeforePrepare, 0)
  5175. for i := 0; i < len(arr); i++ {
  5176. repeat := false
  5177. for j := i + 1; j < len(arr); j++ {
  5178. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  5179. repeat = true
  5180. break
  5181. }
  5182. }
  5183. if !repeat {
  5184. newArr = append(newArr, arr[i])
  5185. }
  5186. }
  5187. return
  5188. }
  5189. func (c *DialysisAPIController) GetAllDrug() {
  5190. patient_id, _ := c.GetInt64("patient_id", 0)
  5191. adminInfo := c.GetMobileAdminUserInfo()
  5192. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5193. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  5194. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  5195. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  5196. c.ServeSuccessJSON(map[string]interface{}{
  5197. "base_drug_config": drugStockConfig,
  5198. "private_drug_config": privateDrugConfig,
  5199. "base_drug_list": drugList,
  5200. "private_drug_list": privateDrugList,
  5201. })
  5202. }
  5203. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5204. newArr = make([]*models.DialysisBeforePrepare, 0)
  5205. for i := 0; i < len(arr); i++ {
  5206. repeat := false
  5207. for j := i + 1; j < len(arr); j++ {
  5208. if arr[i].GoodId == arr[j].GoodId {
  5209. repeat = true
  5210. break
  5211. }
  5212. }
  5213. if !repeat {
  5214. newArr = append(newArr, arr[i])
  5215. }
  5216. }
  5217. return
  5218. }
  5219. func (c *DialysisAPIController) GetDepartment() {
  5220. adminInfo := c.GetMobileAdminUserInfo()
  5221. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  5222. if err == nil {
  5223. c.ServeSuccessJSON(map[string]interface{}{
  5224. "departments": departments,
  5225. })
  5226. } else {
  5227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5228. return
  5229. }
  5230. }
  5231. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  5232. types, _ := c.GetInt("type", 0)
  5233. start_time := c.GetString("start_time")
  5234. end_time := c.GetString("end_time")
  5235. orgId := c.GetMobileAdminUserInfo().Org.Id
  5236. timeLayout := "2006-01-02"
  5237. loc, _ := time.LoadLocation("Local")
  5238. var startTime int64
  5239. if len(start_time) > 0 {
  5240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5241. if err != nil {
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5243. return
  5244. }
  5245. startTime = theTime.Unix()
  5246. }
  5247. var endTime int64
  5248. if len(end_time) > 0 {
  5249. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5250. if err != nil {
  5251. utils.ErrorLog(err.Error())
  5252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5253. return
  5254. }
  5255. endTime = theTime.Unix()
  5256. }
  5257. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  5258. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  5259. if err != nil {
  5260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5261. } else {
  5262. c.ServeSuccessJSON(map[string]interface{}{
  5263. "list": list,
  5264. "type": types,
  5265. "stockTotal": stockTotal,
  5266. })
  5267. }
  5268. }
  5269. func (c *DialysisAPIController) BatchDeleteMonitor() {
  5270. ids := c.GetString("ids")
  5271. //patient_id, _ := c.GetInt64("patient_id")
  5272. //monitoring_date, _ := c.GetInt64("monitoring_date")
  5273. idArray := strings.Split(ids, ",")
  5274. err := service.BatchDeleteMonitor(idArray)
  5275. fmt.Print("err", err)
  5276. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5277. //redis := service.RedisClient()
  5278. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  5279. //redis.Set(key, "", time.Second)
  5280. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  5281. //redis.Set(keyOne, "", time.Second)
  5282. //fmt.Println("keyo呢32332322332332232332",keyOne)
  5283. //redis.Close()
  5284. c.ServeSuccessJSON(map[string]interface{}{
  5285. "msg": "批量删除成功",
  5286. })
  5287. return
  5288. }
  5289. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  5290. id, _ := c.GetInt64("id")
  5291. timeLayout := "2006-01-02"
  5292. loc, _ := time.LoadLocation("Local")
  5293. start_time := time.Now().Format("2006-01-02")
  5294. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5295. nowTime := time.Now()
  5296. endTime := nowTime.AddDate(-2, 0, 0)
  5297. endTimes := endTime.Format("2006-01-02")
  5298. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  5299. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  5300. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  5301. c.ServeSuccessJSON(map[string]interface{}{
  5302. "list": list,
  5303. })
  5304. return
  5305. }
  5306. func (c *DialysisAPIController) BathDeleteAdviceList() {
  5307. dataBody := make(map[string]interface{}, 0)
  5308. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5309. ids := c.GetString("ids")
  5310. idArray := strings.Split(ids, ",")
  5311. origin, _ := c.GetInt64("origin")
  5312. if origin == 1 {
  5313. err = service.BatchDeleteAdvice(idArray)
  5314. fmt.Print("err", err)
  5315. c.ServeSuccessJSON(map[string]interface{}{
  5316. "msg": "批量删除成功",
  5317. })
  5318. return
  5319. }
  5320. if origin == 2 {
  5321. service.BatchDeleteHisAdvice(idArray)
  5322. }
  5323. }
  5324. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  5325. good_id, _ := c.GetInt64("good_id")
  5326. count, _ := c.GetInt64("count")
  5327. record_time, _ := c.GetInt64("record_time")
  5328. patient_id, _ := c.GetInt64("patient_id")
  5329. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  5330. c.ServeSuccessJSON(map[string]interface{}{
  5331. "detail": detail,
  5332. })
  5333. return
  5334. }
  5335. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  5336. good_id, _ := c.GetInt64("good_id")
  5337. record_time, _ := c.GetInt64("record_time")
  5338. patient_id, _ := c.GetInt64("patient_id")
  5339. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  5340. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  5341. fmt.Print("err", err)
  5342. c.ServeSuccessJSON(map[string]interface{}{
  5343. "msg": "批量删除成功",
  5344. })
  5345. return
  5346. }
  5347. func (c *DialysisAPIController) BatchAdviceCheck() {
  5348. ids := c.GetString("ids")
  5349. idArray := strings.Split(ids, ",")
  5350. creator, _ := c.GetInt64("creator")
  5351. origin, _ := c.GetInt64("origin")
  5352. if origin == 1 {
  5353. err := service.BatchAdviceCheck(idArray, creator)
  5354. fmt.Println(err)
  5355. list, _ := service.GetAdviceExecutionById(idArray)
  5356. c.ServeSuccessJSON(map[string]interface{}{
  5357. "list": list,
  5358. })
  5359. return
  5360. }
  5361. if origin == 2 {
  5362. service.BatchHisAdviceCheck(idArray, creator)
  5363. list, _ := service.GetHisAdviceExecutionById(idArray)
  5364. c.ServeSuccessJSON(map[string]interface{}{
  5365. "list": list,
  5366. })
  5367. return
  5368. }
  5369. }
  5370. func (c *DialysisAPIController) BatchAdviceExecution() {
  5371. ids := c.GetString("ids")
  5372. idArray := strings.Split(ids, ",")
  5373. executionTime := c.GetString("execution_time")
  5374. creator, _ := c.GetInt64("creator")
  5375. timeLayout := "2006-01-02 15:04:05"
  5376. loc, _ := time.LoadLocation("Local")
  5377. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  5378. orgin, _ := c.GetInt64("origin")
  5379. if orgin == 1 {
  5380. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  5381. list, _ := service.GetAdviceExecutionById(idArray)
  5382. fmt.Println(err)
  5383. c.ServeSuccessJSON(map[string]interface{}{
  5384. "list": list,
  5385. })
  5386. return
  5387. }
  5388. if orgin == 2 {
  5389. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  5390. list, _ := service.GetHisAdviceExecutionById(idArray)
  5391. fmt.Println(err)
  5392. c.ServeSuccessJSON(map[string]interface{}{
  5393. "list": list,
  5394. })
  5395. return
  5396. }
  5397. }
  5398. func (c *DialysisAPIController) UpdateStockGoods() {
  5399. good_id, _ := c.GetInt64("good_id")
  5400. record_time, _ := c.GetInt64("record_time")
  5401. patient_id, _ := c.GetInt64("patient_id")
  5402. count, _ := c.GetInt64("count")
  5403. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  5404. fmt.Print("err", err)
  5405. c.ServeSuccessJSON(map[string]interface{}{
  5406. "msg": "更新成功",
  5407. })
  5408. return
  5409. }
  5410. //当前数据比上一次出库数据少
  5411. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  5412. //查询该患者当天已经出库的耗材信息
  5413. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5414. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5415. for i := len(goods_yc) - 1; i >= 0; i-- {
  5416. goods_yc_temp := goods_yc[i]
  5417. for j := len(goods) - 1; j >= 0; j-- {
  5418. goods_temp := goods[j]
  5419. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5420. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5421. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5422. if goods_yc_temp.Count == goods_temp.Count {
  5423. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5424. goods = append(goods[:j], goods[j+1:]...)
  5425. break
  5426. }
  5427. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5428. if goods_yc_temp.Count > goods_temp.Count {
  5429. temp_count := goods_yc_temp.Count - goods_temp.Count
  5430. goods_yc[i].Count = temp_count
  5431. goods = append(goods[:j], goods[j+1:]...)
  5432. break
  5433. }
  5434. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5435. if goods_yc_temp.Count < goods_temp.Count {
  5436. temp_count := goods_temp.Count - goods_yc_temp.Count
  5437. goods[j].Count = temp_count
  5438. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5439. break
  5440. }
  5441. }
  5442. }
  5443. }
  5444. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5445. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5446. //退库
  5447. if len(goods_yc) > 0 {
  5448. for _, good_yc := range goods_yc {
  5449. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5450. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  5451. }
  5452. }
  5453. return nil
  5454. }
  5455. //耗材出库删除
  5456. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5457. // 先根据相关信息查询当天该耗材的出库信息
  5458. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5459. if err != nil {
  5460. return err
  5461. }
  5462. var delete_count int64 = 0
  5463. delete_count = warehouseOutInfos.Count - count
  5464. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5465. // 在出库记录表里记录退库详情
  5466. warehouseOutInfo := &models.WarehouseOutInfo{
  5467. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5468. WarehouseOutId: warehouseOut.ID,
  5469. Status: 1,
  5470. Ctime: time.Now().Unix(),
  5471. OrgId: orgID,
  5472. Type: 1,
  5473. IsSys: 1,
  5474. SysRecordTime: record_time,
  5475. GoodTypeId: good_yc.GoodTypeId,
  5476. GoodId: good_yc.GoodId,
  5477. PatientId: good_yc.PatientId,
  5478. ConsumableType: 2,
  5479. StorehouseId: houseConfig.StorehouseOutInfo,
  5480. IsCheck: 1,
  5481. }
  5482. warehouseOutInfo.Count = count
  5483. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5484. warehouseOutInfo.Price = stockInInfo.Price
  5485. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5486. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5487. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5488. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5489. warehouseOutInfo.Number = warehouseOutInfos.Number
  5490. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5491. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5492. //查找当天是否存在出库记录
  5493. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5494. if errcod == gorm.ErrRecordNotFound {
  5495. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5496. //插入详情明细表
  5497. stockFlow := models.VmStockFlow{
  5498. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5499. WarehouseOutId: warehouseOut.ID,
  5500. GoodId: good_yc.GoodId,
  5501. Number: warehouseOutInfos.Number,
  5502. ProductDate: stockInInfo.ProductDate,
  5503. ExpireDate: stockInInfo.ExpiryDate,
  5504. Count: count,
  5505. Price: stockInInfo.Price,
  5506. Status: 1,
  5507. Ctime: time.Now().Unix(),
  5508. UserOrgId: good_yc.OrgId,
  5509. Manufacturer: stockInInfo.Manufacturer,
  5510. Dealer: stockInInfo.Dealer,
  5511. LicenseNumber: stockInInfo.LicenseNumber,
  5512. IsEdit: 2,
  5513. Creator: creater,
  5514. SystemTime: record_time,
  5515. ConsumableType: 3,
  5516. WarehousingDetailId: 0,
  5517. IsSys: 1,
  5518. UpdateCreator: creater,
  5519. PatientId: patient_id,
  5520. StorehouseId: houseConfig.StorehouseOutInfo,
  5521. }
  5522. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5523. if errflow == gorm.ErrRecordNotFound {
  5524. //创建流水表
  5525. err := service.CreateStockFlowOne(stockFlow)
  5526. fmt.Println("err", err)
  5527. } else if errflow == nil {
  5528. //插入详情明细表
  5529. stockFlow := models.VmStockFlow{
  5530. ID: exsit.ID,
  5531. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5532. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5533. WarehouseOutId: warehouseOut.ID,
  5534. GoodId: good_yc.GoodId,
  5535. Number: warehouseOutInfos.Number,
  5536. ProductDate: stockInInfo.ProductDate,
  5537. ExpireDate: stockInInfo.ExpiryDate,
  5538. Count: exsit.Count - delete_count,
  5539. Price: stockInInfo.Price,
  5540. Status: 1,
  5541. Ctime: time.Now().Unix(),
  5542. UserOrgId: good_yc.OrgId,
  5543. Manufacturer: stockInInfo.Manufacturer,
  5544. Dealer: stockInInfo.Dealer,
  5545. LicenseNumber: stockInInfo.LicenseNumber,
  5546. IsEdit: 2,
  5547. Creator: creater,
  5548. SystemTime: record_time,
  5549. ConsumableType: 3,
  5550. WarehousingDetailId: 0,
  5551. IsSys: 1,
  5552. UpdateCreator: creater,
  5553. PatientId: patient_id,
  5554. StorehouseId: houseConfig.StorehouseOutInfo,
  5555. }
  5556. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5557. }
  5558. if errOne != nil {
  5559. return errOne
  5560. }
  5561. } else if errcod == nil {
  5562. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5563. //插入详情明细表
  5564. stockFlow := models.VmStockFlow{
  5565. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5566. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5567. WarehouseOutId: warehouseOut.ID,
  5568. GoodId: good_yc.GoodId,
  5569. Number: warehouseOutInfos.Number,
  5570. ProductDate: stockInInfo.ProductDate,
  5571. ExpireDate: stockInInfo.ExpiryDate,
  5572. Count: count,
  5573. Price: stockInInfo.Price,
  5574. Status: 1,
  5575. Ctime: time.Now().Unix(),
  5576. UserOrgId: good_yc.OrgId,
  5577. Manufacturer: stockInInfo.Manufacturer,
  5578. Dealer: stockInInfo.Dealer,
  5579. LicenseNumber: stockInInfo.LicenseNumber,
  5580. IsEdit: 2,
  5581. Creator: creater,
  5582. SystemTime: record_time,
  5583. ConsumableType: 3,
  5584. WarehousingDetailId: 0,
  5585. IsSys: 1,
  5586. UpdateCreator: creater,
  5587. PatientId: patient_id,
  5588. ReturnCount: delete_count,
  5589. StorehouseId: houseConfig.StorehouseOutInfo,
  5590. }
  5591. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5592. if errflows == gorm.ErrRecordNotFound {
  5593. //创建流水表
  5594. service.CreateStockFlowOne(stockFlow)
  5595. } else if errflows == nil {
  5596. stockFlow := models.VmStockFlow{
  5597. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5598. ID: exsit.ID,
  5599. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5600. WarehouseOutId: warehouseOut.ID,
  5601. GoodId: good_yc.GoodId,
  5602. Number: warehouseOutInfos.Number,
  5603. ProductDate: stockInInfo.ProductDate,
  5604. ExpireDate: stockInInfo.ExpiryDate,
  5605. Count: exsit.Count - delete_count,
  5606. Price: stockInInfo.Price,
  5607. Status: 1,
  5608. Ctime: time.Now().Unix(),
  5609. UserOrgId: good_yc.OrgId,
  5610. Manufacturer: stockInInfo.Manufacturer,
  5611. Dealer: stockInInfo.Dealer,
  5612. LicenseNumber: stockInInfo.LicenseNumber,
  5613. IsEdit: 2,
  5614. Creator: creater,
  5615. SystemTime: record_time,
  5616. ConsumableType: 3,
  5617. WarehousingDetailId: 0,
  5618. IsSys: 1,
  5619. UpdateCreator: creater,
  5620. PatientId: patient_id,
  5621. ReturnCount: delete_count,
  5622. StorehouseId: houseConfig.StorehouseOutInfo,
  5623. }
  5624. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5625. }
  5626. }
  5627. //更改自动出库的表格
  5628. details := models.BloodAutomaticReduceDetail{
  5629. WarehouseOutId: warehouseOutInfo.ID,
  5630. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5631. PatientId: patient_id,
  5632. Ctime: time.Now().Unix(),
  5633. Mtime: time.Now().Unix(),
  5634. Status: 1,
  5635. RecordTime: record_time,
  5636. OrgId: orgID,
  5637. GoodId: good_yc.GoodId,
  5638. GoodTypeId: good_yc.GoodTypeId,
  5639. Count: count,
  5640. StorehouseId: houseConfig.StorehouseOutInfo,
  5641. }
  5642. //查询当天耗材是否已经存在数据
  5643. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5644. if errcode == gorm.ErrRecordNotFound {
  5645. errTwo := service.CreateAutoReduceRecord(&details)
  5646. if errTwo != nil {
  5647. return errTwo
  5648. }
  5649. } else if errcode == nil {
  5650. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5651. service.CreateAutoReduceRecord(&details)
  5652. }
  5653. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5654. //增加出库库存数量
  5655. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  5656. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5657. fmt.Println("errOne", errOne)
  5658. // 删除出库完成后,要增加对应批次的库存数量
  5659. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  5660. if errThree != nil {
  5661. return errThree
  5662. }
  5663. if good_yc.Count == 0 {
  5664. return nil
  5665. } else {
  5666. return errors.New("退库和出库数据不匹配")
  5667. }
  5668. }
  5669. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  5670. //查询该患者当天已经出库的耗材信息
  5671. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5672. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5673. for i := len(goods_yc) - 1; i >= 0; i-- {
  5674. goods_yc_temp := goods_yc[i]
  5675. for j := len(goods) - 1; j >= 0; j-- {
  5676. goods_temp := goods[j]
  5677. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5678. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5679. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5680. if goods_yc_temp.Count == goods_temp.Count {
  5681. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5682. goods = append(goods[:j], goods[j+1:]...)
  5683. break
  5684. }
  5685. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5686. if goods_yc_temp.Count > goods_temp.Count {
  5687. temp_count := goods_yc_temp.Count - goods_temp.Count
  5688. goods_yc[i].Count = temp_count
  5689. goods = append(goods[:j], goods[j+1:]...)
  5690. break
  5691. }
  5692. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5693. if goods_yc_temp.Count < goods_temp.Count {
  5694. temp_count := goods_temp.Count - goods_yc_temp.Count
  5695. goods[j].Count = temp_count
  5696. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5697. break
  5698. }
  5699. }
  5700. }
  5701. }
  5702. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5703. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5704. fmt.Println("剩余需要出库的", len(goods))
  5705. if len(goods) > 0 {
  5706. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  5707. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5708. if err == gorm.ErrRecordNotFound {
  5709. //没有记录,则创建出库单
  5710. timeStr := time.Now().Format("2006-01-02")
  5711. timeArr := strings.Split(timeStr, "-")
  5712. total, _ := service.FindAllWarehouseOut(orgID)
  5713. total = total + 1
  5714. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5715. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5716. number = number + total
  5717. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5718. warehouseOut := models.WarehouseOut{
  5719. WarehouseOutOrderNumber: warehousing_out_order,
  5720. OperationTime: time.Now().Unix(),
  5721. OrgId: orgID,
  5722. Creater: creater,
  5723. Ctime: time.Now().Unix(),
  5724. Status: 1,
  5725. WarehouseOutTime: record_time,
  5726. Dealer: 0,
  5727. Manufacturer: 0,
  5728. Type: 1,
  5729. IsSys: 1,
  5730. StorehouseId: houseConfig.StorehouseOutInfo,
  5731. IsCheck: 1,
  5732. }
  5733. err := service.AddSigleWarehouseOut(&warehouseOut)
  5734. if err != nil {
  5735. utils.TraceLog("创建出库单失败 err = %v", err)
  5736. return err
  5737. } else {
  5738. out = warehouseOut
  5739. }
  5740. }
  5741. for _, item := range goods {
  5742. var newCount int64 = 0
  5743. for _, it := range goodOne {
  5744. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  5745. newCount = it.Count
  5746. }
  5747. }
  5748. prepare := models.DialysisBeforePrepare{
  5749. GoodTypeId: item.GoodTypeId,
  5750. GoodId: item.GoodId,
  5751. Count: item.Count,
  5752. StorehouseId: houseConfig.StorehouseOutInfo,
  5753. }
  5754. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  5755. //增加出库数量
  5756. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  5757. }
  5758. }
  5759. if len(goods_yc) > 0 {
  5760. for _, good_yc := range goods_yc {
  5761. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5762. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  5763. }
  5764. }
  5765. return nil
  5766. }
  5767. //耗材出库删除
  5768. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  5769. // 先根据相关信息查询当天该耗材的出库信息
  5770. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  5771. if err != nil {
  5772. return err
  5773. }
  5774. var delete_count int64 = 0
  5775. for _, ware := range warehouseOutInfos {
  5776. // 判断当前出库的数据和删除出库数量
  5777. if good_yc.Count <= ware.Count {
  5778. delete_count = good_yc.Count
  5779. } else {
  5780. delete_count = ware.Count
  5781. }
  5782. warehouseOutInfo := &models.WarehouseOutInfo{
  5783. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5784. WarehouseOutId: warehouseOut.ID,
  5785. Status: 1,
  5786. Ctime: time.Now().Unix(),
  5787. Remark: "",
  5788. OrgId: orgID,
  5789. Type: 1,
  5790. Manufacturer: 0,
  5791. Dealer: 0,
  5792. IsSys: 0,
  5793. SysRecordTime: record_time,
  5794. GoodTypeId: good_yc.GoodTypeId,
  5795. GoodId: good_yc.GoodId,
  5796. StorehouseId: warehouseOut.StorehouseId,
  5797. IsCheck: 1,
  5798. }
  5799. warehouseOutInfo.Count = delete_count
  5800. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5801. warehouseOutInfo.Price = stockInInfo.Price
  5802. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5803. if errOne != nil {
  5804. return errOne
  5805. }
  5806. // 删除出库完成后,要改变流水库存(有疑问)
  5807. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5808. fmt.Println("errOne", errOne)
  5809. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  5810. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5811. //扣减出库数量
  5812. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  5813. if errThree != nil {
  5814. return errThree
  5815. }
  5816. }
  5817. if good_yc.Count == 0 {
  5818. return nil
  5819. } else {
  5820. return errors.New("退库和出库数据不匹配")
  5821. }
  5822. }
  5823. func (this *DialysisAPIController) GetMobileScheduleList() {
  5824. limit, _ := this.GetInt64("limit")
  5825. page, _ := this.GetInt64("page")
  5826. type_options_visible, _ := this.GetInt64("type_options_visible")
  5827. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  5828. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  5829. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  5830. }
  5831. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  5832. newArr = make([]*models.HisPrescriptionProject, 0)
  5833. for i := 0; i < len(arr); i++ {
  5834. repeat := false
  5835. for j := i + 1; j < len(arr); j++ {
  5836. if arr[i].TeamId == arr[j].TeamId {
  5837. repeat = true
  5838. break
  5839. }
  5840. }
  5841. if !repeat {
  5842. newArr = append(newArr, arr[i])
  5843. }
  5844. }
  5845. return
  5846. }
  5847. func (this *DialysisAPIController) GetRoleList() {
  5848. admin_user_id, _ := this.GetInt64("admin_user_id")
  5849. orgid := this.GetMobileAdminUserInfo().Org.Id
  5850. list, err := service.GetRoleList(orgid, admin_user_id)
  5851. fmt.Println(err)
  5852. this.ServeSuccessJSON(map[string]interface{}{
  5853. "list": list,
  5854. })
  5855. return
  5856. }
  5857. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5858. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  5859. // 先根据相关信息查询当天该耗材的出库信息
  5860. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5861. if err != nil {
  5862. return err
  5863. }
  5864. var delete_count int64 = 0
  5865. delete_count = warehouseOutInfos.Count - count
  5866. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5867. // 删除出库完成后,要增加对应批次的库存数量
  5868. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  5869. if errThree != nil {
  5870. return errThree
  5871. }
  5872. //增加退库数量
  5873. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  5874. //扣减出库数量
  5875. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  5876. //查询剩余库存
  5877. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID)
  5878. var sum_count int64
  5879. for _, item := range goodList {
  5880. sum_count += item.StockCount
  5881. }
  5882. // 在出库记录表里记录退库详情
  5883. warehouseOutInfo := &models.WarehouseOutInfo{
  5884. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5885. WarehouseOutId: warehouseOut.ID,
  5886. Status: 1,
  5887. Ctime: time.Now().Unix(),
  5888. OrgId: orgID,
  5889. Type: 1,
  5890. IsSys: 1,
  5891. SysRecordTime: record_time,
  5892. GoodTypeId: good_yc.GoodTypeId,
  5893. GoodId: good_yc.GoodId,
  5894. PatientId: good_yc.PatientId,
  5895. ConsumableType: 2,
  5896. StorehouseId: houseConfig.StorehouseOutInfo,
  5897. IsCheck: 1,
  5898. OverCount: sum_count,
  5899. }
  5900. warehouseOutInfo.Count = count
  5901. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5902. warehouseOutInfo.Price = stockInInfo.Price
  5903. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5904. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5905. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5906. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5907. warehouseOutInfo.Number = warehouseOutInfos.Number
  5908. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5909. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5910. //查找当天是否存在出库记录
  5911. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5912. if errcod == gorm.ErrRecordNotFound {
  5913. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5914. //插入详情明细表
  5915. if errOne != nil {
  5916. return errOne
  5917. }
  5918. //插入详情明细表
  5919. stockFlow := models.VmStockFlow{
  5920. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5921. WarehouseOutId: warehouseOut.ID,
  5922. GoodId: good_yc.GoodId,
  5923. Number: warehouseOutInfos.Number,
  5924. ProductDate: stockInInfo.ProductDate,
  5925. ExpireDate: stockInInfo.ExpiryDate,
  5926. Count: count,
  5927. Price: stockInInfo.Price,
  5928. Status: 1,
  5929. Ctime: time.Now().Unix(),
  5930. UserOrgId: good_yc.OrgId,
  5931. Manufacturer: stockInInfo.Manufacturer,
  5932. Dealer: stockInInfo.Dealer,
  5933. LicenseNumber: stockInInfo.LicenseNumber,
  5934. IsEdit: 2,
  5935. Creator: creater,
  5936. SystemTime: record_time,
  5937. ConsumableType: 3,
  5938. WarehousingDetailId: 0,
  5939. IsSys: 1,
  5940. UpdateCreator: creater,
  5941. PatientId: patient_id,
  5942. StorehouseId: houseConfig.StorehouseOutInfo,
  5943. OverCount: sum_count,
  5944. ProjectId: good_yc.ProjectId,
  5945. }
  5946. err := service.CreateStockFlowOne(stockFlow)
  5947. fmt.Println("err", err)
  5948. } else if errcod == nil {
  5949. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5950. }
  5951. //创建退库单
  5952. operation_time := time.Now().Unix()
  5953. //创建退库单
  5954. timeStr := time.Now().Format("2006-01-02")
  5955. timeArr := strings.Split(timeStr, "-")
  5956. total, _ := service.FindAllCancelStockTotal(orgID)
  5957. total = total + 1
  5958. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5959. cancelStock := models.CancelStock{
  5960. OrderNumber: orderNumber,
  5961. OperaTime: operation_time,
  5962. OrgId: orgID,
  5963. Creater: warehouseOut.Creater,
  5964. Ctime: time.Now().Unix(),
  5965. Status: 1,
  5966. ReturnTime: record_time,
  5967. Type: 1,
  5968. StorehouseId: stockInInfo.StorehouseId,
  5969. IsCheck: 1,
  5970. }
  5971. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  5972. if msgerrkonde == gorm.ErrRecordNotFound {
  5973. service.AddSigleCancelStock(&cancelStock)
  5974. }
  5975. cancel, _ := service.GetLastCancelStockById(orgID)
  5976. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  5977. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  5978. cancelStockInfo := models.CancelStockInfo{
  5979. GoodId: stockInInfo.GoodId,
  5980. CancelStockId: cancel.ID,
  5981. GoodTypeId: stockInInfo.GoodTypeId,
  5982. Count: delete_count,
  5983. Price: stockInInfo.PackingPrice,
  5984. Total: 0,
  5985. ProductDate: stockInInfo.ProductDate,
  5986. ExpiryDate: stockInInfo.ExpiryDate,
  5987. Ctime: time.Now().Unix(),
  5988. Status: 1,
  5989. OrgId: orgID,
  5990. OrderNumber: cancel.OrderNumber,
  5991. Type: 0,
  5992. Dealer: deaerler.DealerName,
  5993. Manufacturer: manufacturer.ManufacturerName,
  5994. Number: stockInInfo.Number,
  5995. RegisterAccount: "",
  5996. Remark: "",
  5997. WarehouseInfoId: stockInInfo.ID,
  5998. PatientId: patient_id,
  5999. RecordDate: record_time,
  6000. StorehouseId: stockInInfo.StorehouseId,
  6001. IsCheck: 1,
  6002. }
  6003. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6004. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  6005. flow := models.VmStockFlow{
  6006. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  6007. GoodId: good_yc.GoodId,
  6008. Number: warehouseOutInfos.Number,
  6009. LicenseNumber: stockInInfo.LicenseNumber,
  6010. Count: delete_count,
  6011. UserOrgId: orgID,
  6012. PatientId: patient_id,
  6013. SystemTime: record_time,
  6014. ConsumableType: 7,
  6015. IsSys: 0,
  6016. WarehousingOrder: "",
  6017. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  6018. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6019. IsEdit: 0,
  6020. CancelStockId: cancel.ID,
  6021. CancelOrderNumber: cancel.OrderNumber,
  6022. Manufacturer: manufacturer.ID,
  6023. Dealer: 0,
  6024. Creator: warehouseOut.Creater,
  6025. UpdateCreator: 0,
  6026. Status: 1,
  6027. Ctime: time.Now().Unix(),
  6028. Mtime: 0,
  6029. Price: stockInInfo.Price,
  6030. WarehousingDetailId: stockInInfo.ID,
  6031. WarehouseOutDetailId: warehouseOutInfos.ID,
  6032. CancelOutDetailId: cancelInfo.ID,
  6033. ProductDate: stockInInfo.ProductDate,
  6034. ExpireDate: stockInInfo.ExpiryDate,
  6035. StorehouseId: houseConfig.StorehouseOutInfo,
  6036. OverCount: sum_count,
  6037. }
  6038. service.CreateStockFlowOne(flow)
  6039. //更改自动出库的表格
  6040. details := models.BloodAutomaticReduceDetail{
  6041. WarehouseOutId: warehouseOutInfo.ID,
  6042. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6043. PatientId: patient_id,
  6044. Ctime: time.Now().Unix(),
  6045. Mtime: time.Now().Unix(),
  6046. Status: 1,
  6047. RecordTime: record_time,
  6048. OrgId: orgID,
  6049. GoodId: good_yc.GoodId,
  6050. GoodTypeId: good_yc.GoodTypeId,
  6051. Count: count,
  6052. StorehouseId: houseConfig.StorehouseOutInfo,
  6053. }
  6054. //查询当天耗材是否已经存在数据
  6055. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6056. if errcode == gorm.ErrRecordNotFound {
  6057. errTwo := service.CreateAutoReduceRecord(&details)
  6058. if errTwo != nil {
  6059. return errTwo
  6060. }
  6061. } else if errcode == nil {
  6062. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6063. service.CreateAutoReduceRecord(&details)
  6064. }
  6065. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6066. //增加出库库存数量
  6067. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  6068. if good_yc.Count == 0 {
  6069. return nil
  6070. } else {
  6071. return errors.New("退库和出库数据不匹配")
  6072. }
  6073. }
  6074. func (this *DialysisAPIController) SavePatientSign() {
  6075. adminUserInfo := this.GetMobileAdminUserInfo()
  6076. patient_id, _ := this.GetInt64("patient_id")
  6077. dialysis_date, _ := this.GetInt64("dialysis_date")
  6078. orgid := adminUserInfo.Org.Id
  6079. var esdata models.DialysisOrder
  6080. var err error
  6081. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  6082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6083. return
  6084. }
  6085. esdata.Hash = esdata.Hash
  6086. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  6087. order := models.DialysisOrder{
  6088. Hash: esdata.Hash,
  6089. Url: esdata.Url,
  6090. }
  6091. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  6092. redis := service.RedisClient()
  6093. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6094. redis.Set(key, "", time.Second)
  6095. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6096. //清空key 值
  6097. redis.Set(keyOne, "", time.Second)
  6098. //scheduleDateStartOne := startDate.Format("2006-01-02")
  6099. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6100. //redis.Set(keyTwo, "", time.Second)
  6101. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6102. redis.Set(keyThree, "", time.Second)
  6103. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6104. redis.Set(keyFour, "", time.Second)
  6105. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6106. redis.Set(keyFive, "", time.Second)
  6107. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6108. redis.Set(keySix, "", time.Second)
  6109. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  6110. redis.Set(keySeven, "", time.Second)
  6111. if err != nil {
  6112. fmt.Println(err)
  6113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6114. return
  6115. }
  6116. this.ServeSuccessJSON(map[string]interface{}{
  6117. "electronic_signature": esdata,
  6118. })
  6119. }
  6120. func (this *DialysisAPIController) GetPatientSign() {
  6121. patient_id, _ := this.GetInt64("patient_id")
  6122. dialysis_date, _ := this.GetInt64("dialysis_date")
  6123. adminUserInfo := this.GetMobileAdminUserInfo()
  6124. orgId := adminUserInfo.Org.Id
  6125. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  6126. if err != nil {
  6127. fmt.Println(err)
  6128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6129. return
  6130. }
  6131. this.ServeSuccessJSON(map[string]interface{}{
  6132. "dialysisOrder": dialysisOrder,
  6133. })
  6134. }
  6135. func (this *DialysisAPIController) GetScheduleByPatient() {
  6136. patient_id, _ := this.GetInt64("patient_id")
  6137. schedule_date, _ := this.GetInt64("schedule_date")
  6138. orgid := this.GetMobileAdminUserInfo().Org.Id
  6139. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  6140. this.ServeSuccessJSON(map[string]interface{}{
  6141. "schedule": schedule,
  6142. })
  6143. }
  6144. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  6145. org_id := this.GetMobileAdminUserInfo().Org.Id
  6146. patient_id, _ := this.GetInt64("patient_id")
  6147. schedule_date, _ := this.GetInt64("schedule_date")
  6148. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  6149. this.ServeSuccessJSON(map[string]interface{}{
  6150. "order": order,
  6151. })
  6152. }
  6153. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  6154. org_id := this.GetMobileAdminUserInfo().Org.Id
  6155. schedule_date := this.GetString("schedule_date")
  6156. schedule_type, _ := this.GetInt64("schedule_type")
  6157. timeLayout := "2006-01-02"
  6158. loc, _ := time.LoadLocation("Local")
  6159. var startdateunix int64
  6160. if len(schedule_date) > 0 {
  6161. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  6162. if err != nil {
  6163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6164. return
  6165. }
  6166. startdateunix = theTime.Unix()
  6167. }
  6168. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  6169. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  6170. devices, _ := service.GetAllDevicetByListSix(org_id)
  6171. for key, item := range scheduals {
  6172. // 床位信息
  6173. for _, device := range devices {
  6174. if item.BedId == device.ID {
  6175. scheduals[key].DeviceNumber = device
  6176. break
  6177. }
  6178. }
  6179. }
  6180. this.ServeSuccessJSON(map[string]interface{}{
  6181. "list": list,
  6182. "scheduals": scheduals,
  6183. })
  6184. }
  6185. func (this *DialysisAPIController) SavePatientPicture() {
  6186. patient_id, _ := this.GetInt64("patient_id")
  6187. dialysis_date, _ := this.GetInt64("schedule_date")
  6188. avatar := this.GetString("avatar")
  6189. fmt.Println("patient_id", patient_id)
  6190. orgId := this.GetMobileAdminUserInfo().Org.Id
  6191. order := models.DialysisOrder{
  6192. Url: avatar,
  6193. }
  6194. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  6195. redis := service.RedisClient()
  6196. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6197. redis.Set(key, "", time.Second)
  6198. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6199. //清空key 值
  6200. redis.Set(keyOne, "", time.Second)
  6201. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6202. redis.Set(keyThree, "", time.Second)
  6203. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6204. redis.Set(keyFour, "", time.Second)
  6205. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6206. redis.Set(keyFive, "", time.Second)
  6207. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6208. redis.Set(keySix, "", time.Second)
  6209. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  6210. redis.Set(keySeven, "", time.Second)
  6211. if err != nil {
  6212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6213. return
  6214. }
  6215. this.ServeSuccessJSON(map[string]interface{}{
  6216. "order": order,
  6217. })
  6218. }
  6219. func (this *DialysisAPIController) ExectionMobileAdvice() {
  6220. ids := this.GetString("ids")
  6221. idSplit := strings.Split(ids, ",")
  6222. orgId := this.GetMobileAdminUserInfo().Org.Id
  6223. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6224. execution_time := this.GetString("exce_time")
  6225. timeLayout2 := "2006-01-02 15:04:05"
  6226. loc, _ := time.LoadLocation("Local")
  6227. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  6228. if errs != nil {
  6229. utils.ErrorLog(errs.Error())
  6230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6231. return
  6232. }
  6233. //his客户
  6234. if config.IsOpen == 1 {
  6235. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  6236. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  6237. for _, item := range list {
  6238. for _, it := range adviceList {
  6239. if item.DrugId == it.DrugId {
  6240. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6241. }
  6242. }
  6243. }
  6244. for _, item := range list {
  6245. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6246. var sum_out_count int64
  6247. for _, itemThree := range item.ChildDoctorAdvice {
  6248. var prescribing_number int64
  6249. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6250. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6251. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6252. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6253. }
  6254. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6255. prescribing_number = parseIntPrescribingNumber
  6256. }
  6257. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6258. prescribing_number = parseIntPrescribingNumber
  6259. }
  6260. sum_out_count += prescribing_number
  6261. }
  6262. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
  6263. //库存不足
  6264. if sum_out_count > drugStockOut.FlushCount {
  6265. this.ServeSuccessJSON(map[string]interface{}{
  6266. "msg": "2",
  6267. "drug": medical,
  6268. "ids": ids,
  6269. })
  6270. return
  6271. }
  6272. }
  6273. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6274. //执行医嘱
  6275. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6276. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  6277. for _, item := range advices {
  6278. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6279. redis := service.RedisClient()
  6280. //清空key 值
  6281. redis.Set(key, "", time.Second)
  6282. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6283. redis.Set(keyTwo, "", time.Second)
  6284. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6285. redis.Set(keyThree, "", time.Second)
  6286. recordDate := theTime.Format("2006-01-02")
  6287. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6288. redis.Set(keyFour, "", time.Second)
  6289. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6290. redis.Set(keyFive, "", time.Second)
  6291. defer redis.Close()
  6292. }
  6293. if errs == nil {
  6294. //药品管理信息
  6295. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6296. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6297. if drugStockConfig.IsOpen == 1 {
  6298. for _, item := range advices {
  6299. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  6300. config, _ := service.GetDrugOpenConfigOne(orgId)
  6301. if config.IsOpen != 1 {
  6302. //查询该药品是否有库存
  6303. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6304. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  6305. if medical.IsUse == 2 {
  6306. if config.IsOpen != 1 {
  6307. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6308. service.HisDrugsDelivery(orgId, creater, &advice)
  6309. }
  6310. if pharmacyConfig.IsOpen != 1 {
  6311. service.HisDrugsDelivery(orgId, creater, &advice)
  6312. }
  6313. //更新字典里面的库存
  6314. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6315. var sum_count int64
  6316. for _, its := range stockInfo {
  6317. if its.MaxUnit == medical.MaxUnit {
  6318. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6319. }
  6320. sum_count += its.StockMaxNumber + its.StockMinNumber
  6321. }
  6322. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6323. //剩余库存
  6324. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6325. }
  6326. }
  6327. }
  6328. }
  6329. }
  6330. this.ServeSuccessJSON(map[string]interface{}{
  6331. "msg": "1",
  6332. "ids": ids,
  6333. })
  6334. return
  6335. } else {
  6336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6337. }
  6338. }
  6339. fmt.Println("config233322333223", config.IsOpen)
  6340. //血透客户
  6341. if config.IsOpen == 2 || config.IsOpen == 0 {
  6342. //药品管理信息
  6343. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6344. if drugStockConfig.IsOpen == 1 {
  6345. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  6346. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  6347. for _, item := range list {
  6348. for _, it := range adviceList {
  6349. if item.DrugId == it.DrugId {
  6350. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6351. }
  6352. }
  6353. }
  6354. for _, item := range list {
  6355. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6356. var sum_out_count int64
  6357. for _, itemThree := range item.ChildDoctorAdvice {
  6358. var prescribing_number int64
  6359. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6360. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6361. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6362. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6363. }
  6364. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6365. prescribing_number = parseIntPrescribingNumber
  6366. }
  6367. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6368. prescribing_number = parseIntPrescribingNumber
  6369. }
  6370. sum_out_count += prescribing_number
  6371. }
  6372. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
  6373. //库存不足
  6374. if sum_out_count > drugStockOut.FlushCount {
  6375. this.ServeSuccessJSON(map[string]interface{}{
  6376. "msg": "2",
  6377. "drug": medical,
  6378. "ids": ids,
  6379. })
  6380. return
  6381. }
  6382. }
  6383. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6384. fmt.Println("creater2332243244224242424", creater)
  6385. //执行医嘱
  6386. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6387. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6388. for _, item := range advices {
  6389. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6390. redis := service.RedisClient()
  6391. //清空key 值
  6392. redis.Set(key, "", time.Second)
  6393. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6394. redis.Set(keyTwo, "", time.Second)
  6395. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6396. redis.Set(keyThree, "", time.Second)
  6397. recordDate := theTime.Format("2006-01-02")
  6398. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6399. redis.Set(keyFour, "", time.Second)
  6400. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6401. redis.Set(keyFive, "", time.Second)
  6402. defer redis.Close()
  6403. }
  6404. if errs == nil {
  6405. for _, item := range advices {
  6406. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6407. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6408. //查询是否出库按钮开启
  6409. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  6410. if adviceSetting.IsAdviceOpen == 1 {
  6411. //查询是否出库按钮开启
  6412. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  6413. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6414. if prescriptionConfig.IsOpen == 1 {
  6415. if medical.IsUse == 2 {
  6416. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6417. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6418. }
  6419. if pharmacyConfig.IsOpen != 1 {
  6420. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6421. }
  6422. //更新字典里面的库存
  6423. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6424. var sum_count int64
  6425. for _, its := range stockInfo {
  6426. if its.MaxUnit == medical.MaxUnit {
  6427. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6428. }
  6429. sum_count += its.StockMaxNumber + its.StockMinNumber
  6430. }
  6431. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6432. //剩余库存
  6433. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6434. }
  6435. }
  6436. } else {
  6437. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6438. if medical.IsUse == 2 {
  6439. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6440. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6441. }
  6442. if pharmacyConfig.IsOpen != 1 {
  6443. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6444. }
  6445. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6446. var sum_count int64
  6447. for _, its := range stockInfo {
  6448. if its.MaxUnit == medical.MaxUnit {
  6449. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6450. }
  6451. sum_count += its.StockMaxNumber + its.StockMinNumber
  6452. }
  6453. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6454. //剩余库存
  6455. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6456. }
  6457. }
  6458. }
  6459. }
  6460. this.ServeSuccessJSON(map[string]interface{}{
  6461. "msg": "1",
  6462. "ids": ids,
  6463. })
  6464. return
  6465. } else {
  6466. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6467. //执行医嘱
  6468. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6469. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6470. for _, item := range advices {
  6471. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6472. redis := service.RedisClient()
  6473. //清空key 值
  6474. redis.Set(key, "", time.Second)
  6475. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6476. redis.Set(keyTwo, "", time.Second)
  6477. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6478. redis.Set(keyThree, "", time.Second)
  6479. recordDate := theTime.Format("2006-01-02")
  6480. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6481. redis.Set(keyFour, "", time.Second)
  6482. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6483. redis.Set(keyFive, "", time.Second)
  6484. defer redis.Close()
  6485. }
  6486. this.ServeSuccessJSON(map[string]interface{}{
  6487. "msg": "1",
  6488. "ids": ids,
  6489. })
  6490. return
  6491. }
  6492. }
  6493. }
  6494. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  6495. ids := this.GetString("ids")
  6496. idSplit := strings.Split(ids, ",")
  6497. orgId := this.GetMobileAdminUserInfo().Org.Id
  6498. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6499. if config.IsOpen == 1 {
  6500. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  6501. this.ServeSuccessJSON(map[string]interface{}{
  6502. "msg": "1",
  6503. "ids": ids,
  6504. })
  6505. return
  6506. }
  6507. if config.IsOpen == 0 || config.IsOpen == 2 {
  6508. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  6509. this.ServeSuccessJSON(map[string]interface{}{
  6510. "msg": "1",
  6511. "ids": ids,
  6512. })
  6513. return
  6514. }
  6515. }
  6516. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  6517. ids := this.GetString("ids")
  6518. idSplit := strings.Split(ids, ",")
  6519. orgId := this.GetMobileAdminUserInfo().Org.Id
  6520. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6521. //his
  6522. if config.IsOpen == 1 {
  6523. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6524. theTime := time.Now()
  6525. advices := models.HisDoctorAdviceThirty{
  6526. CheckTime: theTime.Unix(),
  6527. Checker: checker,
  6528. UpdatedTime: time.Now().Unix(),
  6529. }
  6530. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  6531. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6532. for _, item := range list {
  6533. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6534. redis := service.RedisClient()
  6535. //清空key 值
  6536. redis.Set(key, "", time.Second)
  6537. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6538. redis.Set(keyTwo, "", time.Second)
  6539. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6540. redis.Set(keyThree, "", time.Second)
  6541. recordDate := theTime.Format("2006-01-02")
  6542. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6543. redis.Set(keyFour, "", time.Second)
  6544. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6545. redis.Set(keyFive, "", time.Second)
  6546. defer redis.Close()
  6547. }
  6548. this.ServeSuccessJSON(map[string]interface{}{
  6549. "msg": "1",
  6550. "ids": ids,
  6551. })
  6552. return
  6553. }
  6554. //血透
  6555. if config.IsOpen == 0 || config.IsOpen == 2 {
  6556. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6557. theTime := time.Now()
  6558. advices := models.DoctorAdvice{
  6559. CheckTime: theTime.Unix(),
  6560. Checker: checker,
  6561. UpdatedTime: time.Now().Unix(),
  6562. }
  6563. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  6564. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6565. for _, item := range list {
  6566. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6567. redis := service.RedisClient()
  6568. //清空key 值
  6569. redis.Set(key, "", time.Second)
  6570. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6571. redis.Set(keyTwo, "", time.Second)
  6572. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6573. redis.Set(keyThree, "", time.Second)
  6574. recordDate := theTime.Format("2006-01-02")
  6575. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6576. redis.Set(keyFour, "", time.Second)
  6577. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6578. redis.Set(keyFive, "", time.Second)
  6579. defer redis.Close()
  6580. }
  6581. this.ServeSuccessJSON(map[string]interface{}{
  6582. "msg": "1",
  6583. "ids": ids,
  6584. })
  6585. return
  6586. }
  6587. }