dialysis_api_controller.go 307KB

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