dialysis_api_controller.go 309KB

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