dialysis_api_controller.go 340KB

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