dialysis_api_controller.go 381KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628
  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. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2072. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2073. //清空key 值
  2074. redis.Set(keyTwoOne, "", time.Second)
  2075. defer redis.Close()
  2076. if updateErr != nil {
  2077. utils.ErrorLog("%v", updateErr)
  2078. }
  2079. c.ServeSuccessJSON(map[string]interface{}{
  2080. "prescription": prescription,
  2081. })
  2082. }
  2083. }
  2084. func (c *DialysisAPIController) Finish() {
  2085. id, _ := c.GetInt64("patient", 0)
  2086. recordDateStr := c.GetString("record_date")
  2087. nurseID, _ := c.GetInt64("nurse")
  2088. end_time := c.GetString("end_time")
  2089. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2090. internal_fistula := c.GetString("blood_access_internal_fistula")
  2091. catheter := c.GetString("catheter")
  2092. cruor := c.GetString("cruor")
  2093. mission := c.GetString("mission")
  2094. condenser := c.GetString("condenser")
  2095. if id <= 0 || nurseID <= 0 {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. adminUserInfo := c.GetMobileAdminUserInfo()
  2100. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2101. if patient.ID == 0 {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2103. return
  2104. }
  2105. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2106. if getNurseErr != nil {
  2107. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2109. return
  2110. } else if nurse == nil {
  2111. c.ErrorLog("护士不存在")
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. if len(recordDateStr) == 0 {
  2116. recordDateStr = time.Now().Format("2006-01-02")
  2117. }
  2118. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2119. if parseDateErr != nil {
  2120. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2125. if parseEndDateErr != nil {
  2126. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. // 查询信息规挡的设置天数
  2131. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2132. if infor.ID > 0 && infor.WeekDay > 0 {
  2133. var cha_time int64
  2134. timeNowStr := time.Now().Format("2006-01-02")
  2135. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2136. //今日的日期减去设置的日期
  2137. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2138. if cha_time >= recordDate.Unix() {
  2139. //查询审核是否允许
  2140. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2141. //申请状态不允许的情况 拒绝修改
  2142. if infor.ApplicationStatus != 1 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2144. return
  2145. }
  2146. }
  2147. }
  2148. //now := time.Now()
  2149. //year, month, day := now.Date()
  2150. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2151. //todayTimeStamp := today_time.Unix()
  2152. // 获取当天的第一条透析纪录
  2153. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2154. if getMonitorRecordsErr != nil {
  2155. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. // 获取当前的最后一条透析纪录
  2160. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2161. if getMonitorRecordsErr != nil {
  2162. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2164. return
  2165. }
  2166. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2167. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if getAADErr != nil {
  2169. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2174. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2176. if assessmentAfterDislysis != nil {
  2177. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2178. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2179. } else {
  2180. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2181. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2182. tempassessmentAfterDislysis.Status = 1
  2183. tempassessmentAfterDislysis.PatientId = id
  2184. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2185. }
  2186. //长沙南雅
  2187. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2188. //获取最后一条透析处方数据
  2189. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2190. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2192. }
  2193. if dialysisOrder.Stage == 1 {
  2194. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2195. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2196. fmt.Println(value)
  2197. a, b := math.Modf(value)
  2198. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2199. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2200. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2201. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2202. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2203. }
  2204. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2205. //var num1 int64
  2206. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2207. //fmt.Println(num1)
  2208. //sub := float64(num1 / 3600)
  2209. //fmt.Println(sub)
  2210. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2211. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2212. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2213. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2214. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2215. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2216. if adminUserInfo.Org.Id != 10375 {
  2217. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2218. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2219. }
  2220. if adminUserInfo.Org.Id != 10445 {
  2221. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2222. }
  2223. //北方营口医院
  2224. if adminUserInfo.Org.Id == 10445 {
  2225. //获取最后一条透析处方数据
  2226. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2227. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2228. } else {
  2229. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2230. }
  2231. //新化博翔
  2232. if adminUserInfo.Org.Id == 10447 {
  2233. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2234. }
  2235. //阳春
  2236. if adminUserInfo.Org.Id == 10485 {
  2237. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2238. }
  2239. if adminUserInfo.Org.Id == 10551 {
  2240. //获取最后一条透析处方数据
  2241. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2243. }
  2244. if adminUserInfo.Org.Id == 10580 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2246. }
  2247. }
  2248. 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 {
  2249. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2250. if evaluation.SystolicBloodPressure == 0 {
  2251. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2252. pre := models.PredialysisEvaluation{
  2253. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2254. }
  2255. fmt.Println("prew", pre)
  2256. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2257. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2258. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2259. redis := service.RedisClient()
  2260. redis.Set(key, "", time.Second)
  2261. redis.Set(keyOne, "", time.Second)
  2262. defer redis.Close()
  2263. fmt.Println(getNurseErr)
  2264. }
  2265. if evaluation.DiastolicBloodPressure == 0 {
  2266. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2267. pres := models.PredialysisEvaluation{
  2268. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2269. }
  2270. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2271. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2272. redis := service.RedisClient()
  2273. redis.Set(key, "", time.Second)
  2274. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2275. redis.Set(keyOne, "", time.Second)
  2276. defer redis.Close()
  2277. fmt.Println(getNurseErr)
  2278. }
  2279. if evaluation.PulseFrequency == 0 {
  2280. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2281. press := models.PredialysisEvaluation{
  2282. PulseFrequency: evaluation.PulseFrequency,
  2283. }
  2284. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2286. redis := service.RedisClient()
  2287. redis.Set(key, "", time.Second)
  2288. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2289. redis.Set(keyOne, "", time.Second)
  2290. defer redis.Close()
  2291. fmt.Println(getNurseErr)
  2292. }
  2293. if evaluation.Temperature == 0 {
  2294. evaluation.Temperature = fmonitorRecords.Temperature
  2295. press := models.PredialysisEvaluation{
  2296. Temperature: evaluation.Temperature,
  2297. }
  2298. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2299. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2303. redis.Set(keyOne, "", time.Second)
  2304. defer redis.Close()
  2305. fmt.Println(getNurseErr)
  2306. }
  2307. }
  2308. if adminUserInfo.Org.Id == 9583 {
  2309. //获取透析处方的最后一条数据
  2310. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2311. if diaerr != nil {
  2312. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2314. return
  2315. }
  2316. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2317. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2318. }
  2319. }
  2320. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2321. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2322. }
  2323. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2324. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2325. }
  2326. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2327. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2328. }
  2329. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2330. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2331. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2332. }
  2333. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2334. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2335. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2336. }
  2337. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2338. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2339. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2340. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2341. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2342. }
  2343. if lastAssessmentAfterDislysis != nil {
  2344. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2345. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2346. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2347. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2348. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2349. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2350. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2351. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2352. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2353. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2354. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2355. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2356. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2357. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2358. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2359. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2360. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2361. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2362. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2363. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2364. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2365. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2366. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2367. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2368. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2369. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2370. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2371. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2372. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2373. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2374. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2375. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2376. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2377. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2378. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2379. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2380. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2381. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2382. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2383. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2384. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2385. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2386. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2387. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2388. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2389. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2390. if tempassessmentAfterDislysis.PatientId == 18695 {
  2391. tempassessmentAfterDislysis.ActualDisplacement = 0
  2392. }
  2393. if adminUserInfo.Org.Id != 10375 {
  2394. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2395. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2396. }
  2397. }
  2398. finish := models.XtDialysisFinish{
  2399. IsFinish: 1,
  2400. UserOrgId: adminUserInfo.Org.Id,
  2401. Status: 1,
  2402. Ctime: time.Now().Unix(),
  2403. Mtime: 0,
  2404. Module: 9,
  2405. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2406. Sourse: 1,
  2407. PatientId: tempassessmentAfterDislysis.PatientId,
  2408. }
  2409. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2410. if dialysisFinish.ID == 0 {
  2411. service.CreateDialysisFinish(finish)
  2412. }
  2413. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2415. redis := service.RedisClient()
  2416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2417. redis.Set(keyOne, "", time.Second)
  2418. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2419. redis.Set(keyTwo, "", time.Second)
  2420. defer redis.Close()
  2421. //清空key 值
  2422. redis.Set(key, "", time.Second)
  2423. if err != nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. if dialysisOrder == nil {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2429. return
  2430. }
  2431. if dialysisOrder.Stage == 2 {
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2433. return
  2434. }
  2435. if dialysisOrder.Stage == 1 {
  2436. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2437. finish := models.XtDialysisFinish{
  2438. IsFinish: 1,
  2439. UserOrgId: adminUserInfo.Org.Id,
  2440. Status: 1,
  2441. Ctime: time.Now().Unix(),
  2442. Mtime: 0,
  2443. Module: 8,
  2444. RecordDate: recordDate.Unix(),
  2445. Sourse: 1,
  2446. PatientId: id,
  2447. }
  2448. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2449. if dialysisFinish.ID == 0 {
  2450. service.CreateDialysisFinish(finish)
  2451. }
  2452. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2453. redis := service.RedisClient()
  2454. defer redis.Close()
  2455. //清空key 值
  2456. redis.Set(key, "", time.Second)
  2457. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2458. redis.Set(keyOne, "", time.Second)
  2459. //结束时候透析次数加1
  2460. service.UpdateSolutionByPatientId(id)
  2461. //下机完自动消毒,针对长沙南雅
  2462. if dialysisOrder.Stage == 1 {
  2463. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2464. //根据床位号获取设备型号
  2465. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2466. //查询使用消毒最后一条消毒记录
  2467. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2468. fmt.Println("err", err)
  2469. if err == gorm.ErrRecordNotFound {
  2470. //查找排班
  2471. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2472. //查询改设备是否有消毒计划
  2473. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2474. //根据床位号获取设备id
  2475. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2476. //查询病人信息
  2477. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2478. var con = ""
  2479. if patients.IsInfectious == 0 {
  2480. con = ""
  2481. }
  2482. if patients.IsInfectious == 1 {
  2483. con = "无"
  2484. }
  2485. if patients.IsInfectious == 2 {
  2486. con = "有"
  2487. }
  2488. if errcode == nil {
  2489. var end_time int64
  2490. end_time = endDate.Unix() + plan.DisinfecTime*60
  2491. //新增消毒
  2492. information := models.DeviceInformation{
  2493. Date: dialysisOrder.DialysisDate,
  2494. Zone: dialysisOrder.ZoneId,
  2495. Class: dialysisOrder.SchedualType,
  2496. BedNumber: dialysisOrder.BedID,
  2497. PatientId: dialysisOrder.PatientId,
  2498. DialysisMode: scheduleByPatient.ModeId,
  2499. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2500. Disinfection: 1,
  2501. DialysisConcentration: 1,
  2502. DisinfectionStatus: 1,
  2503. Move: 1,
  2504. UserOrgId: dialysisOrder.UserOrgId,
  2505. DisinfectType: plan.Way,
  2506. DisinfectantType: plan.MachineDisinfectant,
  2507. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2508. Disinfectant: plan.Disinfectant,
  2509. Ctime: time.Now().Unix(),
  2510. Status: 1,
  2511. SignName: nurseID,
  2512. EquimentId: addmacher.ID,
  2513. DisinfectionResidue: 2,
  2514. Bed: addmacher.BedNumber,
  2515. StartTime: dialysisOrder.StartTime,
  2516. EndTime: dialysisOrder.EndTime,
  2517. Contagion: con,
  2518. WeightLoss: 0,
  2519. Hyperfiltratio: 0,
  2520. DialysisHour: "",
  2521. MachineRun: 1,
  2522. DisinfecStartime: endDate.Unix(),
  2523. DisinfecEndtime: end_time,
  2524. }
  2525. err := service.CreateInformationTwo(&information)
  2526. fmt.Println("报错", err)
  2527. }
  2528. }
  2529. }
  2530. }
  2531. dialysisOrder.Stage = 2
  2532. dialysisOrder.FinishNurse = nurseID
  2533. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2534. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2535. dialysisOrder.EndTime = endDate.Unix()
  2536. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2537. // 长沙南雅需求
  2538. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2539. //获取最后1条监测的数据
  2540. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2541. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2542. var accumulatedBloodVolume float64
  2543. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2544. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2545. fmt.Println(err)
  2546. // 查询未执行的医嘱
  2547. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2548. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2549. for _, item := range doctorAdvice {
  2550. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2551. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2552. redis := service.RedisClient()
  2553. //清空key 值
  2554. redis.Set(key, "", time.Second)
  2555. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2556. redis.Set(keyTwo, "", time.Second)
  2557. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2558. redis.Set(keyThree, "", time.Second)
  2559. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2560. theTime := toTime.Format("2006-01-02")
  2561. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2562. redis.Set(keyFour, "", time.Second)
  2563. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2564. redis.Set(keyFive, "", time.Second)
  2565. defer redis.Close()
  2566. }
  2567. }
  2568. go func() {
  2569. ssoDomain := beego.AppConfig.String("call_domain")
  2570. api := ssoDomain + "/index/downpatient"
  2571. values := make(url.Values)
  2572. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2573. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2574. values.Set("patient_id", strconv.FormatInt(id, 10))
  2575. http.PostForm(api, values)
  2576. }()
  2577. if err == nil {
  2578. c.ServeSuccessJSON(map[string]interface{}{
  2579. "dialysisOrder": dialysisOrder,
  2580. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2581. })
  2582. } else {
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2584. }
  2585. }
  2586. }
  2587. func (c *DialysisAPIController) GetAllZone() {
  2588. adminUserInfo := c.GetMobileAdminUserInfo()
  2589. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2590. if err == nil {
  2591. c.ServeSuccessJSON(map[string]interface{}{
  2592. "zone": zone,
  2593. })
  2594. }
  2595. }
  2596. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2597. adminUserInfo := c.GetMobileAdminUserInfo()
  2598. page, _ := c.GetInt64("page", 1)
  2599. limit, _ := c.GetInt64("limit", 10)
  2600. schedulType, _ := c.GetInt64("schedul_type", 0)
  2601. startTime, _ := c.GetInt64("schedul_time", 0)
  2602. partitionType, _ := c.GetInt64("partition_type", 0)
  2603. keywords := c.GetString("keywords")
  2604. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2605. if err == nil {
  2606. c.ServeSuccessJSON(map[string]interface{}{
  2607. "schedule": dialysisSchedule,
  2608. })
  2609. }
  2610. return
  2611. }
  2612. // /m/api/dialysis/start [post]
  2613. // @param patient_id:int
  2614. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2615. // @param nurse:int 上机护士
  2616. // @param bed:int 床位号
  2617. func (this *DialysisAPIController) StartDialysis() {
  2618. patientID, _ := this.GetInt64("patient_id")
  2619. recordDateStr := this.GetString("record_date")
  2620. nurseID, _ := this.GetInt64("start_nurse")
  2621. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2622. blood_drawing, _ := this.GetInt64("blood_drawing")
  2623. schedual_type, _ := this.GetInt64("schedual_type")
  2624. bedID, _ := this.GetInt64("bed")
  2625. start_time := this.GetString("start_time")
  2626. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2627. change_nurse, _ := this.GetInt64("change_nurse")
  2628. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2629. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2630. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2631. puncture_needle := this.GetString("puncture_needle")
  2632. puncture_way := this.GetString("puncture_way")
  2633. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2634. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2635. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2636. zone_id, _ := this.GetInt64("zone_id")
  2637. elecsign := this.GetString("url")
  2638. nuclein_date_str := this.GetString("nuclein_date_str")
  2639. schedule_remark := this.GetString("schedule_remark")
  2640. order_remark := this.GetString("order_remark")
  2641. catheter_operation := this.GetString("catheter_operation")
  2642. blood_flow_volume := this.GetString("blood_flow_volume")
  2643. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2645. return
  2646. }
  2647. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2648. if parseStartDateErr != nil {
  2649. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2651. return
  2652. }
  2653. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2654. if parseErr != nil {
  2655. this.ErrorLog("时间解析失败:%v", parseErr)
  2656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2657. return
  2658. }
  2659. adminUserInfo := this.GetMobileAdminUserInfo()
  2660. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2661. if getPatientErr != nil {
  2662. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. } else if patient == nil {
  2666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2667. return
  2668. }
  2669. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2670. if getNurseErr != nil {
  2671. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2673. return
  2674. } else if nurse == nil {
  2675. this.ErrorLog("护士不存在")
  2676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2677. return
  2678. }
  2679. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2680. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2681. if getDeviceNumberErr != nil {
  2682. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2684. return
  2685. } else if deviceNumber == nil {
  2686. this.ErrorLog("床位号不存在")
  2687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2691. if getRecordErr != nil {
  2692. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2694. return
  2695. } else if dialysisRecord != nil {
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2697. return
  2698. }
  2699. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2700. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2701. timeLayout := "2006-01-02 15:04:05"
  2702. loc, _ := time.LoadLocation("Local")
  2703. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2704. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2705. schedulestartTime := theStartTime.Unix()
  2706. scheduleendTime := theEndTime.Unix()
  2707. var theNucleinDate int64
  2708. timeLayoutOne := "2006-01-02"
  2709. if len(nuclein_date_str) > 0 {
  2710. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2711. if err != nil {
  2712. utils.ErrorLog(err.Error())
  2713. }
  2714. theNucleinDate = theTime.Unix()
  2715. }
  2716. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2717. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2718. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2719. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2720. //查询该床位是否有人用了
  2721. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2722. if err == gorm.ErrRecordNotFound { //空床位
  2723. // 修改了床位逻辑
  2724. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2725. if daySchedule.ID > 0 {
  2726. daySchedule.PartitionId = deviceNumber.ZoneID
  2727. daySchedule.BedId = bedID
  2728. daySchedule.ScheduleType = schedual_type
  2729. daySchedule.UpdatedTime = time.Now().Unix()
  2730. xtSchedule := models.Schedule{
  2731. PartitionId: deviceNumber.ZoneID,
  2732. BedId: bedID,
  2733. ScheduleType: schedual_type,
  2734. UpdatedTime: time.Now().Unix(),
  2735. }
  2736. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2737. if err != nil {
  2738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2739. return
  2740. }
  2741. }
  2742. } else if err == nil {
  2743. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2744. if order.ID > 0 { //该机位被其他人占用了
  2745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2746. return
  2747. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2748. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2749. if daySchedule.ID > 0 {
  2750. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2751. if err != nil {
  2752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2753. return
  2754. }
  2755. }
  2756. }
  2757. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2759. return
  2760. }
  2761. //else if order.ID == 0 { //该床位没被占用
  2762. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2763. // if daySchedule.ID > 0 {
  2764. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2765. // //daySchedule.BedId = bedID
  2766. // //daySchedule.ScheduleType = schedual_type
  2767. // //daySchedule.UpdatedTime = time.Now().Unix()
  2768. // //err := service.UpdateSchedule(&daySchedule)
  2769. // xtSchedule := models.Schedule{
  2770. // PartitionId: deviceNumber.ZoneID,
  2771. // BedId: bedID,
  2772. // ScheduleType: schedual_type,
  2773. // UpdatedTime: time.Now().Unix(),
  2774. // }
  2775. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2776. // if err != nil {
  2777. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2778. // return
  2779. // }
  2780. // }
  2781. //}
  2782. //}
  2783. } else if err != nil {
  2784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2785. return
  2786. }
  2787. // 查询信息规挡的设置天数
  2788. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2789. if infor.ID > 0 && infor.WeekDay > 0 {
  2790. var cha_time int64
  2791. timeNowStr := time.Now().Format("2006-01-02")
  2792. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2793. //今日的日期减去设置的日期
  2794. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2795. if cha_time >= recordDate.Unix() {
  2796. //查询审核是否允许
  2797. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2798. //申请状态不允许的情况 拒绝修改
  2799. if infor.ApplicationStatus != 1 {
  2800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2801. return
  2802. }
  2803. }
  2804. }
  2805. dialysisRecord = &models.DialysisOrder{
  2806. DialysisDate: recordDate.Unix(),
  2807. UserOrgId: adminUserInfo.Org.Id,
  2808. PatientId: patientID,
  2809. Stage: 1,
  2810. BedID: bedID,
  2811. StartNurse: nurseID,
  2812. Status: 1,
  2813. StartTime: startDate.Unix(),
  2814. CreatedTime: time.Now().Unix(),
  2815. UpdatedTime: time.Now().Unix(),
  2816. PunctureNurse: puncture_nurse,
  2817. Creator: adminUserInfo.AdminUser.Id,
  2818. Modifier: adminUserInfo.AdminUser.Id,
  2819. SchedualType: schedual_type,
  2820. WashpipeNurse: washpipe_nurse,
  2821. ChangeNurse: change_nurse,
  2822. DifficultPunctureNurse: difficult_puncture_nurse,
  2823. NewFistulaNurse: new_fistula_nurse,
  2824. ZoneId: zone_id,
  2825. QualityNurseId: quality_nurse_id,
  2826. PunctureNeedle: puncture_needle,
  2827. PunctureWay: puncture_way,
  2828. DialysisIrrigation: dialysis_irrigation,
  2829. DialysisDialyszers: dialysis_dialyszers,
  2830. BloodAccessId: blood_access_id,
  2831. Url: elecsign,
  2832. NucleinDate: theNucleinDate,
  2833. ScheduleRemark: schedule_remark,
  2834. OrderRemark: order_remark,
  2835. CatheterOperation: catheter_operation,
  2836. BloodFlowVolume: blood_flow_volume,
  2837. }
  2838. //查询该床位是否有人用了
  2839. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2840. if errorscode == gorm.ErrRecordNotFound {
  2841. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2842. finish := models.XtDialysisFinish{
  2843. IsFinish: 1,
  2844. UserOrgId: adminUserInfo.Org.Id,
  2845. Status: 1,
  2846. Ctime: time.Now().Unix(),
  2847. Mtime: 0,
  2848. Module: 6,
  2849. RecordDate: schedulestartTime,
  2850. Sourse: 1,
  2851. PatientId: patientID,
  2852. }
  2853. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2854. if dialysisFinish.ID == 0 {
  2855. service.CreateDialysisFinish(finish)
  2856. }
  2857. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2858. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2859. //统计该患者总次数
  2860. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2861. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2862. }
  2863. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2864. //统计该患者总次数
  2865. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2866. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2867. }
  2868. redis := service.RedisClient()
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. //清空key 值
  2873. redis.Set(keyOne, "", time.Second)
  2874. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2875. //清空key 值
  2876. redis.Set(keyTwo, "", time.Second)
  2877. if createErr != nil {
  2878. this.ErrorLog("上机失败:%v", createErr)
  2879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2880. return
  2881. }
  2882. }
  2883. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2884. var tempdispose string
  2885. // 只针对中能建
  2886. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2887. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2888. }
  2889. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2890. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2891. }
  2892. var ultrafiltration_rate float64
  2893. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2894. //后期预增脱水量
  2895. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2896. if prescription.ID > 0 {
  2897. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2898. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2899. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2900. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2901. }
  2902. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2903. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2904. }
  2905. //针对医师汇
  2906. if adminUserInfo.Org.Id == 10121 {
  2907. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2908. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2909. }
  2910. //针对通道
  2911. if adminUserInfo.Org.Id == 10234 {
  2912. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2913. }
  2914. //针对监利大垸医院
  2915. if template.TemplateId == 41 {
  2916. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2917. }
  2918. //针对肇庆三鹤血液透析中心
  2919. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2920. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2921. }
  2922. if adminUserInfo.Org.Id == 10469 {
  2923. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2924. }
  2925. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2926. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2927. }
  2928. // 只针对方济医院
  2929. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2930. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2931. ultrafiltration_rate = value
  2932. }
  2933. //针对
  2934. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2936. ultrafiltration_rate = ultrafiltration_rate / 1000
  2937. }
  2938. if adminUserInfo.Org.Id == 10551 {
  2939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2940. ultrafiltration_rate = ultrafiltration_rate / 1000
  2941. }
  2942. if adminUserInfo.Org.Id == 10612 {
  2943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2944. ultrafiltration_rate = ultrafiltration_rate / 1000
  2945. }
  2946. if adminUserInfo.Org.Id == 10580 {
  2947. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2948. ultrafiltration_rate = ultrafiltration_rate / 1000
  2949. }
  2950. }
  2951. }
  2952. record := models.MonitoringRecord{
  2953. UserOrgId: adminUserInfo.Org.Id,
  2954. PatientId: patientID,
  2955. DialysisOrderId: dialysisRecord.ID,
  2956. MonitoringDate: schedulestartTime,
  2957. OperateTime: startDate.Unix(),
  2958. // MonitoringTime: recordTime,
  2959. MonitoringNurse: nurseID,
  2960. Dispose: tempdispose,
  2961. UltrafiltrationRate: ultrafiltration_rate,
  2962. UltrafiltrationVolume: 0,
  2963. Status: 1,
  2964. CreatedTime: time.Now().Unix(),
  2965. UpdatedTime: time.Now().Unix(),
  2966. }
  2967. //只针对广慈医院
  2968. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 {
  2969. // 查询病人是否有透前评估数据
  2970. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2971. //如果有数据就插入
  2972. if errcode == nil {
  2973. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2974. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2975. record.BreathingRate = befor.BreathingRate
  2976. record.PulseFrequency = befor.PulseFrequency
  2977. record.Temperature = befor.Temperature
  2978. }
  2979. }
  2980. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2981. if newdialysisRecord.ID > 0 {
  2982. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2983. record.Temperature = 36.5
  2984. record.ArterialPressure = -100
  2985. record.DialysateTemperature = 36.5
  2986. record.Conductivity = 14
  2987. record.BreathingRate = "20"
  2988. record.VenousPressure = 80
  2989. record.TransmembranePressure = 60
  2990. record.Dispose = catheter_operation
  2991. }
  2992. //针对新化博翔
  2993. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2994. record.BloodOxygenSaturation = "99"
  2995. record.Conductivity = 14
  2996. record.DialysateTemperature = 36.5
  2997. record.BreathingRate = "20"
  2998. }
  2999. //针对兰溪人民医院的需求
  3000. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  3001. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3002. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3003. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3004. record.Temperature = befor.Temperature
  3005. record.PulseFrequency = befor.PulseFrequency
  3006. record.BreathingRate = befor.BreathingRate
  3007. }
  3008. //新化博翔
  3009. if adminUserInfo.Org.Id == 10447 {
  3010. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3011. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3012. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3013. record.BreathingRate = befor.BreathingRate
  3014. }
  3015. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3016. record.PulseFrequency = 80
  3017. record.Temperature = 36.5
  3018. }
  3019. //诊断灵山圣康
  3020. if adminUserInfo.Org.Id == 10375 {
  3021. record.Conductivity = 13.8
  3022. record.DialysateTemperature = 37
  3023. record.DialysateFlow = 500
  3024. record.BloodFlowVolume = 200
  3025. record.BreathingRate = "18"
  3026. record.SodiumConcentration = 140
  3027. }
  3028. //江成肾病医院
  3029. if adminUserInfo.Org.Id == 10517 {
  3030. record.SodiumConcentration = 138
  3031. record.DialysateTemperature = 36.5
  3032. }
  3033. err := service.CreateMonitor(&record)
  3034. //记录日志
  3035. byterequest, _ := json.Marshal(record)
  3036. monitorRecordLog := models.XtMonitorRecordLog{
  3037. RecordDate: record.MonitoringDate,
  3038. PatientId: record.PatientId,
  3039. Module: 1,
  3040. AdminUserId: adminUserInfo.AdminUser.Id,
  3041. Ctime: time.Now().Unix(),
  3042. Mtime: 0,
  3043. Status: 1,
  3044. UserOrgId: record.UserOrgId,
  3045. ErrLog: string(byterequest),
  3046. Source: "执行上机时新增监测",
  3047. }
  3048. service.CreateMonitorRecordLog(monitorRecordLog)
  3049. finish := models.XtDialysisFinish{
  3050. IsFinish: 1,
  3051. UserOrgId: adminUserInfo.Org.Id,
  3052. Status: 1,
  3053. Ctime: time.Now().Unix(),
  3054. Mtime: 0,
  3055. Module: 7,
  3056. RecordDate: schedulestartTime,
  3057. Sourse: 1,
  3058. PatientId: patientID,
  3059. }
  3060. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3061. if dialysisFinish.ID == 0 {
  3062. service.CreateDialysisFinish(finish)
  3063. }
  3064. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3065. redis := service.RedisClient()
  3066. //清空key 值
  3067. redis.Set(key, "", time.Second)
  3068. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3069. redis.Set(keyOne, "", time.Second)
  3070. defer redis.Close()
  3071. if err != nil {
  3072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3073. return
  3074. }
  3075. }
  3076. go func() {
  3077. ssoDomain := beego.AppConfig.String("call_domain")
  3078. api := ssoDomain + "/index/uppatient"
  3079. values := make(url.Values)
  3080. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3081. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3082. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3083. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3084. http.PostForm(api, values)
  3085. }()
  3086. this.ServeSuccessJSON(map[string]interface{}{
  3087. "dialysis_order": newdialysisRecord,
  3088. "monitor": record,
  3089. })
  3090. return
  3091. }
  3092. func (c *DialysisAPIController) PostSolution() {
  3093. id, _ := c.GetInt64("patient", 0)
  3094. recordDateStr := c.GetString("record_date")
  3095. if id <= 0 {
  3096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3097. return
  3098. }
  3099. adminUserInfo := c.GetMobileAdminUserInfo()
  3100. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3101. if patient.ID == 0 {
  3102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3103. return
  3104. }
  3105. if len(recordDateStr) == 0 {
  3106. recordDateStr = time.Now().Format("2006-01-02")
  3107. }
  3108. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3109. if parseDateErr != nil {
  3110. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3112. return
  3113. }
  3114. mode_id, _ := c.GetInt64("mode_id", 0)
  3115. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3116. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3117. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3118. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3119. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3120. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3121. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3122. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3123. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3124. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3125. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3126. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3127. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3128. kalium, _ := c.GetFloat("kalium", 0)
  3129. sodium, _ := c.GetFloat("sodium", 0)
  3130. calcium, _ := c.GetFloat("calcium", 0)
  3131. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3132. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3133. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3134. glucose, _ := c.GetFloat("glucose", 0)
  3135. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3136. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3137. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3138. conductivity, _ := c.GetFloat("conductivity", 0)
  3139. remark := c.GetString("remark")
  3140. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3141. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3142. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3143. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3144. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3145. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3146. special_medicine_other := c.GetString("special_medicine_other")
  3147. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3148. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3149. blood_access, _ := c.GetInt64("blood_access", 0)
  3150. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3151. body_fluid_other := c.GetString("body_fluid_other")
  3152. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3153. niprocart, _ := c.GetInt64("niprocart", 0)
  3154. jms, _ := c.GetInt64("jms", 0)
  3155. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3156. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3157. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3158. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3159. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3160. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3161. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3162. injector, _ := c.GetInt64("injector", 0)
  3163. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3164. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3165. safe_package, _ := c.GetInt64("package", 0)
  3166. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3167. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3168. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3169. blood := c.GetString("blood")
  3170. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3171. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3172. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3173. displace_speed := c.GetString("displace_speed")
  3174. illness, _ := c.GetInt64("illness")
  3175. amylaceum := c.GetString("amylaceum")
  3176. single_time := c.GetString("single_time")
  3177. single_water := c.GetString("single_water")
  3178. replacement_flow := c.GetString("replacement_flow")
  3179. plasma_separator := c.GetString("plasma_separator")
  3180. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3181. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3182. oxygen_flow := c.GetString("oxygen_flow")
  3183. oxygen_time := c.GetString("oxygen_time")
  3184. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3185. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3186. puncture_needle := c.GetString("puncture_needle")
  3187. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3188. epo := c.GetString("epo")
  3189. epo_count, _ := c.GetFloat("epo_count", 0)
  3190. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3191. pre_impulse := c.GetString("pre_impulse")
  3192. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3193. admin_user_id, _ := c.GetInt64("admin_user_id")
  3194. is_water := c.GetString("is_water")
  3195. add_amount, _ := c.GetFloat("add_amount")
  3196. reduce_amount, _ := c.GetFloat("reduce_amount")
  3197. prescribing_number, _ := c.GetFloat("prescribing_number")
  3198. treatment_remark := c.GetString("treatment_remark")
  3199. prescription_sodium := c.GetString("prescription_sodium")
  3200. start_sodium := c.GetString("start_sodium")
  3201. sodium_curve := c.GetString("sodium_curve")
  3202. var is_war int64
  3203. if is_water == "是" {
  3204. is_war = 1
  3205. }
  3206. if is_water == "否" {
  3207. is_war = 2
  3208. }
  3209. if is_water == "请选择" {
  3210. is_war = 0
  3211. }
  3212. drhy_water := c.GetString("drhy_water")
  3213. dry_water_hour := c.GetString("dry_water_hour")
  3214. water_machine := c.GetString("water_machine")
  3215. dialysis_remark := c.GetString("dialysis_remark")
  3216. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3217. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3218. prescription_water, _ := c.GetFloat("prescription_water")
  3219. dialysis_strainer := c.GetString("dialysis_strainer")
  3220. chaptalization := c.GetString("chaptalization")
  3221. washing_time := c.GetString("washing_time")
  3222. warsh_count := c.GetString("warsh_count")
  3223. blood_access_part_id := c.GetString("blood_access_part_id")
  3224. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3225. dialyzate := c.GetString("dialyzate")
  3226. if mode_id > 0 {
  3227. var str string
  3228. //查找该机构用的是什么透析器
  3229. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3230. if filedConfig.ID > 0 {
  3231. str = dialyzerPerfusionApparatus
  3232. } else {
  3233. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3234. }
  3235. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3236. }
  3237. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3238. //
  3239. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3240. // if appRole.UserType == 3 {
  3241. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3242. // if getPermissionErr != nil {
  3243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3244. // return
  3245. // } else if headNursePermission == nil {
  3246. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3247. // return
  3248. // }
  3249. // }
  3250. //}
  3251. // 查询信息规挡的设置天数
  3252. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3253. if infor.ID > 0 && infor.WeekDay > 0 {
  3254. var cha_time int64
  3255. timeNowStr := time.Now().Format("2006-01-02")
  3256. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3257. //今日的日期减去设置的日期
  3258. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3259. if cha_time >= recordDate.Unix() {
  3260. //查询审核是否允许
  3261. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3262. //申请状态不允许的情况 拒绝修改
  3263. if infor.ApplicationStatus != 1 {
  3264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3265. return
  3266. }
  3267. }
  3268. }
  3269. prescription := models.DialysisPrescription{
  3270. UserOrgId: adminUserInfo.Org.Id,
  3271. PatientId: id,
  3272. RecordDate: recordDate.Unix(),
  3273. ModeId: mode_id,
  3274. DialysisDuration: dialysis_duration,
  3275. Dialyzer: dialyzer,
  3276. PerfusionApparatus: perfusion_apparatus,
  3277. BloodFlowVolume: blood_flow_volume,
  3278. DewaterAmount: dewater_amount,
  3279. DisplaceLiqui: displace_liqui,
  3280. ReplacementWay: replacement_way,
  3281. Anticoagulant: anticoagulant,
  3282. AnticoagulantShouji: anticoagulant_shouji,
  3283. AnticoagulantWeichi: anticoagulant_weichi,
  3284. AnticoagulantZongliang: anticoagulant_zongliang,
  3285. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3286. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3287. Kalium: kalium,
  3288. Sodium: sodium,
  3289. Calcium: calcium,
  3290. Bicarbonate: bicarbonate,
  3291. Glucose: glucose,
  3292. // DryWeight: dry_weight,
  3293. DialysateFlow: dialysate_flow,
  3294. DialysateTemperature: dialysate_temperature,
  3295. Conductivity: conductivity,
  3296. Remark: remark,
  3297. Status: 1,
  3298. CreatedTime: time.Now().Unix(),
  3299. UpdatedTime: time.Now().Unix(),
  3300. DialysisDurationMinute: dialysisDurationMinute,
  3301. DialysisDurationHour: dialysisDurationHour,
  3302. TargetUltrafiltration: targetUltrafiltration,
  3303. DialysateFormulation: dialysateFormulation,
  3304. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3305. BodyFluid: body_fluid,
  3306. SpecialMedicine: special_medicine,
  3307. SpecialMedicineOther: special_medicine_other,
  3308. DisplaceLiquiPart: displace_liqui_part,
  3309. DisplaceLiquiValue: displace_liqui_value,
  3310. BloodAccess: blood_access,
  3311. Ultrafiltration: ultrafiltration,
  3312. BodyFluidOther: body_fluid_other,
  3313. ReplacementTotal: replacement_total,
  3314. Niprocart: niprocart,
  3315. Jms: jms,
  3316. FistulaNeedleSet: fistula_needle_set,
  3317. FistulaNeedleSet16: fistula_needle_set_16,
  3318. Hemoperfusion: hemoperfusion,
  3319. DialyserSterilised: dialyser_sterilised,
  3320. Filtryzer: filtryzer,
  3321. TargetKtv: target_ktv,
  3322. Dialyzers: dialyzers,
  3323. Injector: injector,
  3324. Bloodlines: bloodlines,
  3325. TubingHemodialysis: tubing_hemodialysis,
  3326. Package: safe_package,
  3327. ALiquid: a_liquid,
  3328. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3329. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3330. Blood: blood,
  3331. DialysisDialyszers: dialysis_dialyszers,
  3332. DialysisIrrigation: dialysis_irrigation,
  3333. AntioxidantCommodityName: antioxidant_commodity_name,
  3334. DisplaceSpeed: displace_speed,
  3335. Illness: illness,
  3336. Amylaceum: amylaceum,
  3337. SingleWater: single_water,
  3338. SingleTime: single_time,
  3339. ReplacementFlow: replacement_flow,
  3340. PlasmaSeparator: plasma_separator,
  3341. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3342. OxygenUptake: oxygen_uptake,
  3343. OxygenTime: oxygen_time,
  3344. OxygenFlow: oxygen_flow,
  3345. HemodialysisPipelines: hemodialysis_pipelines,
  3346. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3347. PunctureNeedle: puncture_needle,
  3348. PunctureNeedleCount: puncture_needle_count,
  3349. Epo: epo,
  3350. EpoCount: epo_count,
  3351. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3352. PreImpulse: impulse,
  3353. AdminUserId: admin_user_id,
  3354. IsWater: is_war,
  3355. DrhyWater: drhy_water,
  3356. DryWaterHour: dry_water_hour,
  3357. WaterMachine: water_machine,
  3358. AddAmount: add_amount,
  3359. ReduceAmount: reduce_amount,
  3360. DialysisRemark: dialysis_remark,
  3361. PrescribingNumber: prescribing_number,
  3362. PrescriptionSodium: prescription_sodium,
  3363. StartSodium: start_sodium,
  3364. SodiumCurve: sodium_curve,
  3365. TreatmentRemark: treatment_remark,
  3366. DialysisFluidFlow: dialysis_fluid_flow,
  3367. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3368. PrescriptionWater: prescription_water,
  3369. DialysisStrainer: dialysis_strainer,
  3370. Chaptalization: chaptalization,
  3371. WashingTime: washing_time,
  3372. WarshCount: warsh_count,
  3373. BloodAccessPartId: blood_access_part_id,
  3374. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3375. Dialyzate: dialyzate,
  3376. }
  3377. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3378. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3379. //
  3380. if appRole.UserType == 2 || appRole.UserType == 1 {
  3381. prescription_doctor = adminUserInfo.AdminUser.Id
  3382. prescription.PrescriptionDoctor = prescription_doctor
  3383. }
  3384. if dialysisPrescription.ID == 0 { //新增
  3385. prescription.Creater = adminUserInfo.AdminUser.Id
  3386. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3387. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3388. }
  3389. } else { //修改
  3390. if dialysisPrescription.Creater == 0 {
  3391. prescription.Creater = adminUserInfo.AdminUser.Id
  3392. } else {
  3393. prescription.Creater = dialysisPrescription.Creater
  3394. if adminUserInfo.Org.Id == 9882 {
  3395. if appRole.UserType == 2 || appRole.UserType == 1 {
  3396. prescription.Creater = adminUserInfo.AdminUser.Id
  3397. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3398. }
  3399. }
  3400. }
  3401. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3402. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3403. }
  3404. //if/**/
  3405. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3406. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3407. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3408. // if getPermissionErr != nil {
  3409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3410. // return
  3411. // } else if headNursePermission == nil {
  3412. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3413. // return
  3414. // }
  3415. //}
  3416. //prescription.Creater = dialysisPrescription.Creater
  3417. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3418. prescription.Modifier = adminUserInfo.AdminUser.Id
  3419. prescription.ID = dialysisPrescription.ID
  3420. }
  3421. solution := models.DialysisSolution{
  3422. RegistrarsId: adminUserInfo.AdminUser.Id,
  3423. UserOrgId: adminUserInfo.Org.Id,
  3424. Doctor: prescription_doctor,
  3425. PatientId: id,
  3426. ModeId: mode_id,
  3427. DialysisDuration: dialysis_duration,
  3428. PerfusionApparatus: perfusion_apparatus,
  3429. BloodFlowVolume: blood_flow_volume,
  3430. Dewater: dewater_amount,
  3431. DisplaceLiqui: displace_liqui,
  3432. ReplacementWay: replacement_way,
  3433. Anticoagulant: anticoagulant,
  3434. AnticoagulantShouji: anticoagulant_shouji,
  3435. AnticoagulantWeichi: anticoagulant_weichi,
  3436. AnticoagulantZongliang: anticoagulant_zongliang,
  3437. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3438. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3439. Kalium: kalium,
  3440. Sodium: sodium,
  3441. Calcium: calcium,
  3442. Bicarbonate: bicarbonate,
  3443. Glucose: glucose,
  3444. // DryWeight: dry_weight,
  3445. DialysateFlow: dialysate_flow,
  3446. DialysateTemperature: dialysate_temperature,
  3447. Conductivity: conductivity,
  3448. Remark: remark,
  3449. Status: 1,
  3450. CreatedTime: time.Now().Unix(),
  3451. UpdatedTime: time.Now().Unix(),
  3452. DialysisDurationMinute: dialysisDurationMinute,
  3453. DialysisDurationHour: dialysisDurationHour,
  3454. TargetUltrafiltration: targetUltrafiltration,
  3455. DialysateFormulation: dialysateFormulation,
  3456. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3457. BodyFluid: body_fluid,
  3458. SpecialMedicine: special_medicine,
  3459. SpecialMedicineOther: special_medicine_other,
  3460. DisplaceLiquiPart: displace_liqui_part,
  3461. DisplaceLiquiValue: displace_liqui_value,
  3462. BloodAccess: blood_access,
  3463. Ultrafiltration: ultrafiltration,
  3464. BodyFluidOther: body_fluid_other,
  3465. ReplacementTotal: replacement_total,
  3466. TargetKtv: target_ktv,
  3467. DialysisDialyszers: dialysis_dialyszers,
  3468. DialysisIrrigation: dialysis_irrigation,
  3469. HemodialysisPipelines: hemodialysis_pipelines,
  3470. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3471. PunctureNeedle: puncture_needle,
  3472. PunctureNeedleCount: puncture_needle_count,
  3473. Epo: epo,
  3474. EpoCount: epo_count,
  3475. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3476. PreImpulse: impulse,
  3477. SolutionStatus: 1,
  3478. DialysisRemark: dialysis_remark,
  3479. PrescribingNumber: prescribing_number,
  3480. PrescriptionSodium: prescription_sodium,
  3481. StartSodium: start_sodium,
  3482. SodiumCurve: sodium_curve,
  3483. TreatmentRemark: treatment_remark,
  3484. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3485. DialysisFluidFlow: dialysis_fluid_flow,
  3486. PrescriptionWater: prescription_water,
  3487. DialysisStrainer: dialysis_strainer,
  3488. Chaptalization: chaptalization,
  3489. WashingTime: washing_time,
  3490. WarshCount: warsh_count,
  3491. BloodAccessPartId: blood_access_part_id,
  3492. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3493. Dialyzate: dialyzate,
  3494. }
  3495. //针对河间咸的
  3496. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3497. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3498. solution.DisplaceLiquiPart = 0
  3499. solution.DisplaceLiquiValue = 0
  3500. }
  3501. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3502. prescription.DisplaceLiquiPart = 0
  3503. prescription.DisplaceLiquiValue = 0
  3504. }
  3505. }
  3506. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3507. if solution.PrescribingNumber == 0 {
  3508. solution.PrescribingNumber = 1
  3509. }
  3510. if prescription.PrescribingNumber == 0 {
  3511. prescription.PrescribingNumber = 1
  3512. }
  3513. if solution.PrescribingNumber == 0 && id == 14682 {
  3514. solution.PrescribingNumber = 2
  3515. }
  3516. if solution.PrescribingNumber == 0 && id == 18560 {
  3517. solution.PrescribingNumber = 2
  3518. }
  3519. if prescription.PrescribingNumber == 0 && id == 14682 {
  3520. prescription.PrescribingNumber = 2
  3521. }
  3522. if prescription.PrescribingNumber == 0 && id == 18560 {
  3523. prescription.PrescribingNumber = 2
  3524. }
  3525. }
  3526. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3527. //记录日志
  3528. byterequest, _ := json.Marshal(prescription)
  3529. prescriptionLog := models.XtDialysisPrescriptionLog{
  3530. UserOrgId: prescription.UserOrgId,
  3531. Ctime: time.Now().Unix(),
  3532. Mtime: 0,
  3533. ErrLog: string(byterequest),
  3534. AdminUserId: adminUserInfo.AdminUser.Id,
  3535. RecordDate: prescription.RecordDate,
  3536. PatientId: prescription.PatientId,
  3537. Source: "手机端新增长期处方",
  3538. Status: 1,
  3539. }
  3540. service.CreatePrescriptionLog(prescriptionLog)
  3541. finish := models.XtDialysisFinish{
  3542. IsFinish: 1,
  3543. UserOrgId: adminUserInfo.Org.Id,
  3544. Status: 1,
  3545. Ctime: time.Now().Unix(),
  3546. Mtime: 0,
  3547. Module: 1,
  3548. RecordDate: recordDate.Unix(),
  3549. Sourse: 1,
  3550. PatientId: id,
  3551. }
  3552. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3553. if dialysisFinish.ID == 0 {
  3554. service.CreateDialysisFinish(finish)
  3555. }
  3556. //获取最新1条
  3557. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3558. //更新状态
  3559. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3560. //长沙南雅医院,自动生成抗凝剂的临时处方
  3561. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3562. if prescribing_number == 0 {
  3563. prescribing_number = 1
  3564. }
  3565. advice := models.DoctorAdvice{
  3566. UserOrgId: adminUserInfo.Org.Id,
  3567. PatientId: id,
  3568. GroupNo: 0,
  3569. AdviceType: 2,
  3570. RecordDate: recordDate.Unix(),
  3571. AdviceDate: recordDate.Unix(),
  3572. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3573. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3574. AdviceDesc: "",
  3575. ReminderDate: 0,
  3576. SingleDose: prescription.AnticoagulantZongliang,
  3577. SingleDoseUnit: "iu",
  3578. DrugSpec: 0,
  3579. DrugSpecUnit: "",
  3580. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3581. PrescribingNumberUnit: "支",
  3582. DeliveryWay: "静脉注射",
  3583. ExecutionFrequency: "上机前",
  3584. AdviceDoctor: 0,
  3585. Status: 1,
  3586. CreatedTime: time.Now().Unix(),
  3587. UpdatedTime: time.Now().Unix(),
  3588. IsPrescription: 1,
  3589. ExecutionState: 2,
  3590. StopState: 2,
  3591. IsSettle: 2,
  3592. }
  3593. // 查询排班信息
  3594. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3595. if schedulePatient.ID > 0 {
  3596. if schedulePatient.ScheduleType == 1 {
  3597. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3598. }
  3599. if schedulePatient.ScheduleType == 2 {
  3600. advice.StartTime = recordDate.Unix() + 10*60*60
  3601. }
  3602. }
  3603. // 抗凝剂名称
  3604. switch anticoagulant {
  3605. case 1:
  3606. advice.AdviceName = "无肝素"
  3607. break
  3608. case 2:
  3609. advice.AdviceName = "普通肝素"
  3610. break
  3611. case 3:
  3612. advice.AdviceName = "低分子肝素"
  3613. break
  3614. case 4:
  3615. advice.AdviceName = "阿加曲班"
  3616. break
  3617. case 5:
  3618. advice.AdviceName = "枸橼酸钠"
  3619. break
  3620. case 6:
  3621. advice.AdviceName = "低分子肝素钙"
  3622. break
  3623. case 7:
  3624. advice.AdviceName = "低分子肝素钠"
  3625. break
  3626. case 8:
  3627. advice.AdviceName = "依诺肝素"
  3628. break
  3629. case 9:
  3630. advice.AdviceName = "达肝素"
  3631. break
  3632. case 10:
  3633. advice.AdviceName = "体外抗凝"
  3634. break
  3635. case 11:
  3636. advice.AdviceName = "那曲肝素"
  3637. break
  3638. case 12:
  3639. advice.AdviceName = "无抗凝剂"
  3640. break
  3641. }
  3642. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3643. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3644. advice.AdviceDoctor = appRole.AdminUserId
  3645. }
  3646. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3647. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3648. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3649. advice.AdviceName = "低分子肝素钠注射液"
  3650. // 修改患者临时医嘱里的抗凝剂医嘱
  3651. advice.ID = advicePrescription.ID
  3652. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3653. } else {
  3654. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3655. advice.AdviceName = "低分子肝素钠注射液"
  3656. service.CreateDoctorAdvice(&advice)
  3657. }
  3658. }
  3659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3660. redis := service.RedisClient()
  3661. defer redis.Close()
  3662. //清空key 值
  3663. redis.Set(key, "", time.Second)
  3664. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3665. redis.Set(keyOne, "", time.Second)
  3666. }
  3667. //获取key,清空redis
  3668. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3669. redis := service.RedisClient()
  3670. defer redis.Close()
  3671. //清空key 值
  3672. redis.Set(key, "", time.Second)
  3673. //清空长期医嘱的key
  3674. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3675. redis.Set(soulution_key, "", time.Second)
  3676. //查询最近透析准备表里是否存在 透析器 灌流器
  3677. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3678. redis.Set(keyOne, "", time.Second)
  3679. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3680. redis.Set(keyTwo, "", time.Second)
  3681. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3682. redis.Set(keyThree, "", time.Second)
  3683. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3684. redis.Set(keyFour, "", time.Second)
  3685. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3686. //
  3687. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3688. //
  3689. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3690. //if len(mation)>0{
  3691. // for _, item := range splitStr {
  3692. // for _,it := range mation{
  3693. // if(item == it.SpecificationName){
  3694. //
  3695. // //查询最近一次的透析器
  3696. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3697. //
  3698. // if errcode == gorm.ErrRecordNotFound{
  3699. // //插入数据
  3700. // prepare := models.DialysisBeforePrepare{
  3701. // UserOrgId: adminUserInfo.Org.Id,
  3702. // PatientId: id,
  3703. // RecordDate: recordDate.Unix(),
  3704. // GoodTypeId: it.GoodTypeId,
  3705. // GoodId: it.ID,
  3706. // Count: 1,
  3707. // Ctime: time.Now().Unix(),
  3708. // Creater: adminUserInfo.AdminUser.Id,
  3709. // Status:1,
  3710. //
  3711. // }
  3712. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3713. // fmt.Println("",errcode)
  3714. // }
  3715. // }
  3716. // }
  3717. //
  3718. // }
  3719. //
  3720. // for _, item := range splitIrrigation {
  3721. // for _,it := range mation{
  3722. // if(item == it.SpecificationName){
  3723. // //查询最近一次的透析器
  3724. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3725. // if errcode == gorm.ErrRecordNotFound{
  3726. // //插入数据
  3727. // prepare := models.DialysisBeforePrepare{
  3728. // UserOrgId: adminUserInfo.Org.Id,
  3729. // PatientId: id,
  3730. // RecordDate: recordDate.Unix(),
  3731. // GoodTypeId: it.GoodTypeId,
  3732. // GoodId: it.ID,
  3733. // Count: 1,
  3734. // Ctime: time.Now().Unix(),
  3735. // Creater: adminUserInfo.AdminUser.Id,
  3736. // Status:1,
  3737. //
  3738. // }
  3739. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3740. // fmt.Println(errcode)
  3741. // }
  3742. // }
  3743. // }
  3744. // }
  3745. //}
  3746. c.ServeSuccessJSON(map[string]interface{}{
  3747. "solution": &solution,
  3748. "prescription": &prescription,
  3749. })
  3750. }
  3751. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3752. patient, _ := c.GetInt64("patient", 0)
  3753. adminUserInfo := c.GetMobileAdminUserInfo()
  3754. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3755. c.ServeSuccessJSON(map[string]interface{}{
  3756. "receiveTreatmentAsses": receiveTreatmentAsses,
  3757. })
  3758. }
  3759. func (this *DialysisAPIController) PostSignInfo() {
  3760. patientID, _ := this.GetInt64("patient_id")
  3761. recordDateStr := this.GetString("date")
  3762. if patientID <= 0 {
  3763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3764. return
  3765. }
  3766. if len(recordDateStr) == 0 {
  3767. recordDateStr = time.Now().Format("2006-01-02")
  3768. }
  3769. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3770. if parseDateErr != nil {
  3771. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3773. return
  3774. }
  3775. adminInfo := this.GetMobileAdminUserInfo()
  3776. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3777. if err != nil {
  3778. this.ErrorLog("签名失败:%v", err)
  3779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3780. return
  3781. }
  3782. this.ServeSuccessJSON(map[string]interface{}{
  3783. "doctor_id": adminInfo.AdminUser.Id,
  3784. })
  3785. }
  3786. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3787. patientID, _ := this.GetInt64("patient_id")
  3788. adminInfo := this.GetMobileAdminUserInfo()
  3789. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3790. this.ServeSuccessJSON(map[string]interface{}{
  3791. "monitor": record,
  3792. })
  3793. }
  3794. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3795. thisTime := time.Now()
  3796. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3797. timeLayout := "2006-01-02 15:04:05"
  3798. loc, _ := time.LoadLocation("Local")
  3799. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3800. theAssessmentDateTime := theStartTime.Unix()
  3801. patientID, _ := this.GetInt64("patient_id")
  3802. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3803. adminInfo := this.GetMobileAdminUserInfo()
  3804. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3805. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3806. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3807. var ultrafiltration_rate float64
  3808. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3809. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3810. fmt.Println(evaluation)
  3811. fmt.Println("prescription.ID", prescription.ID)
  3812. if prescription.ID > 0 {
  3813. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3814. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3815. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3816. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3817. record.UltrafiltrationRate = ultrafiltration_rate
  3818. }
  3819. if adminInfo.Org.Id == 10597 {
  3820. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3821. record.UltrafiltrationRate = ultrafiltration_rate
  3822. }
  3823. if adminInfo.Org.Id == 10510 {
  3824. record.UltrafiltrationRate = 0
  3825. }
  3826. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3827. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3828. record.UltrafiltrationRate = ultrafiltration_rate
  3829. }
  3830. if template.TemplateId == 20 || template.TemplateId == 22 {
  3831. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3832. record.UltrafiltrationRate = ultrafiltration_rate
  3833. }
  3834. // 只针对方济医院
  3835. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3836. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3837. ultrafiltration_rate = value
  3838. record.UltrafiltrationRate = ultrafiltration_rate
  3839. }
  3840. if template.TemplateId == 41 || template.TemplateId == 47 {
  3841. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3842. record.UltrafiltrationRate = ultrafiltration_rate
  3843. }
  3844. if template.TemplateId == 43 {
  3845. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3846. record.UltrafiltrationRate = ultrafiltration_rate
  3847. }
  3848. if template.TemplateId == 46 || template.TemplateId == 54 {
  3849. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3850. record.UltrafiltrationRate = ultrafiltration_rate
  3851. }
  3852. 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 {
  3853. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3854. record.UltrafiltrationRate = ultrafiltration_rate
  3855. }
  3856. if adminInfo.Org.Id == 10469 {
  3857. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3858. record.UltrafiltrationRate = ultrafiltration_rate
  3859. }
  3860. if adminInfo.Org.Id == 10471 {
  3861. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3862. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3863. }
  3864. if adminInfo.Org.Id == 10460 {
  3865. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3866. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3867. }
  3868. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3869. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3870. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3871. }
  3872. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3873. record.UltrafiltrationRate = 0
  3874. }
  3875. //if template.TemplateId == 47 {
  3876. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3877. // record.UltrafiltrationRate = ultrafiltration_rate
  3878. //}
  3879. }
  3880. }
  3881. // record.UltrafiltrationRate = ultrafiltration_rate
  3882. record.UltrafiltrationVolume = 0
  3883. 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
  3884. if ultrafiltration_rate > 0 {
  3885. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3886. record.UltrafiltrationVolume = value
  3887. }
  3888. }
  3889. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  3890. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3891. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3892. record.UltrafiltrationVolume = ultrafiltration_volume
  3893. }
  3894. }
  3895. if adminInfo.Org.Id == 10597 {
  3896. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3897. record.UltrafiltrationVolume = ultrafiltration_volume
  3898. }
  3899. //长沙南雅
  3900. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 {
  3901. if ultrafiltration_rate > 0 {
  3902. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3903. record.UltrafiltrationVolume = ultrafiltration_volume
  3904. }
  3905. }
  3906. if adminInfo.Org.Id == 10471 {
  3907. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3908. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3909. }
  3910. if adminInfo.Org.Id == 10460 {
  3911. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3912. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3913. }
  3914. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3915. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3916. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3917. }
  3918. //长沙南雅累计血容量自动计算
  3919. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3920. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3921. //}
  3922. if template.TemplateId == 47 || template.TemplateId == 54 {
  3923. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3924. }
  3925. if adminInfo.Org.Id == 10510 {
  3926. record.UltrafiltrationVolume = 0
  3927. }
  3928. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3929. this.ServeSuccessJSON(map[string]interface{}{
  3930. "monitor": record,
  3931. "lastMonitorRecordList": lastMonitorRecordList,
  3932. })
  3933. }
  3934. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3935. record_id, _ := this.GetInt64("id")
  3936. nurseID, _ := this.GetInt64("start_nurse")
  3937. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3938. bedID, _ := this.GetInt64("bed")
  3939. start_time := this.GetString("start_time")
  3940. schedual_type, _ := this.GetInt64("schedual_type")
  3941. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3942. change_nurse, _ := this.GetInt64("change_nurse")
  3943. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3944. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3945. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3946. fmt.Println("quality_nurse_id", quality_nurse_id)
  3947. patient_id, _ := this.GetInt64("patient_id")
  3948. record_date, _ := this.GetInt64("record_date")
  3949. puncture_needle := this.GetString("puncture_needle")
  3950. puncture_way := this.GetString("puncture_way")
  3951. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3952. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3953. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3954. nuclein_date_str := this.GetString("nuclein_date_str")
  3955. order_remark := this.GetString("order_remark")
  3956. schedule_remark := this.GetString("schedule_remark")
  3957. catheter_operation := this.GetString("catheter_operation")
  3958. blood_flow_volume := this.GetString("blood_flow_volume")
  3959. if record_id == 0 {
  3960. this.ErrorLog("id:%v", record_id)
  3961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3962. return
  3963. }
  3964. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3965. if parseStartDateErr != nil {
  3966. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3968. return
  3969. }
  3970. adminUserInfo := this.GetMobileAdminUserInfo()
  3971. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3972. if getNurseErr != nil {
  3973. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3975. return
  3976. } else if nurse == nil {
  3977. this.ErrorLog("护士不存在")
  3978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3979. return
  3980. }
  3981. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3982. //if getNurseErr != nil {
  3983. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3984. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3985. // return
  3986. //} else if nurse == nil {
  3987. // this.ErrorLog("护士不存在")
  3988. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3989. // return
  3990. //}
  3991. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3992. if getDeviceNumberErr != nil {
  3993. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3995. return
  3996. } else if deviceNumber == nil {
  3997. this.ErrorLog("床位号不存在")
  3998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3999. return
  4000. }
  4001. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4002. //
  4003. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4004. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4005. // if getPermissionErr != nil {
  4006. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4007. // return
  4008. // } else if headNursePermission == nil {
  4009. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4010. // return
  4011. // }
  4012. //}
  4013. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4014. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4015. timeLayout := "2006-01-02 15:04:05"
  4016. loc, _ := time.LoadLocation("Local")
  4017. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4018. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4019. schedulestartTime := theStartTime.Unix()
  4020. scheduleendTime := theEndTime.Unix()
  4021. var theNucleinDate int64
  4022. timeLayoutOne := "2006-01-02"
  4023. if len(nuclein_date_str) > 0 {
  4024. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4025. if err != nil {
  4026. utils.ErrorLog(err.Error())
  4027. }
  4028. theNucleinDate = theTime.Unix()
  4029. }
  4030. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4031. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4032. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4033. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4034. if err == gorm.ErrRecordNotFound { //空床位
  4035. // 修改了床位逻辑
  4036. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4037. if daySchedule.ID > 0 {
  4038. //daySchedule.BedId = bedID
  4039. //daySchedule.PartitionId = deviceNumber.ZoneID
  4040. //daySchedule.ScheduleType = schedual_type
  4041. //daySchedule.UpdatedTime = time.Now().Unix()
  4042. //err := service.UpdateSchedule(&daySchedule)
  4043. xtSchedule := models.Schedule{
  4044. PartitionId: deviceNumber.ZoneID,
  4045. BedId: bedID,
  4046. ScheduleType: schedual_type,
  4047. UpdatedTime: time.Now().Unix(),
  4048. }
  4049. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4050. if err != nil {
  4051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4052. return
  4053. }
  4054. }
  4055. } else if err == nil {
  4056. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4057. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4058. if daySchedule.ID > 0 {
  4059. //daySchedule.BedId = bedID
  4060. //daySchedule.PartitionId = deviceNumber.ZoneID
  4061. //
  4062. //daySchedule.ScheduleType = schedual_type
  4063. //daySchedule.UpdatedTime = time.Now().Unix()
  4064. //err := service.UpdateSchedule(&daySchedule)
  4065. xtSchedule := models.Schedule{
  4066. PartitionId: deviceNumber.ZoneID,
  4067. BedId: bedID,
  4068. ScheduleType: schedual_type,
  4069. UpdatedTime: time.Now().Unix(),
  4070. }
  4071. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4072. if err != nil {
  4073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4074. return
  4075. }
  4076. }
  4077. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4079. return
  4080. }
  4081. } else if err != nil {
  4082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4083. return
  4084. }
  4085. }
  4086. dialysisRecord := &models.DialysisOrder{
  4087. ID: record_id,
  4088. UserOrgId: adminUserInfo.Org.Id,
  4089. BedID: bedID,
  4090. StartNurse: nurseID,
  4091. StartTime: startDate.Unix(),
  4092. PunctureNurse: puncture_nurse,
  4093. Creator: adminUserInfo.AdminUser.Id,
  4094. Modifier: adminUserInfo.AdminUser.Id,
  4095. WashpipeNurse: washpipe_nurse,
  4096. SchedualType: schedual_type,
  4097. ChangeNurse: change_nurse,
  4098. DifficultPunctureNurse: difficult_puncture_nurse,
  4099. NewFistulaNurse: new_fistula_nurse,
  4100. QualityNurseId: quality_nurse_id,
  4101. PunctureNeedle: puncture_needle,
  4102. PunctureWay: puncture_way,
  4103. DialysisDialyszers: dialysis_dialyszers,
  4104. DialysisIrrigation: dialysis_irrigation,
  4105. BloodAccessId: blood_access_id,
  4106. NucleinDate: theNucleinDate,
  4107. OrderRemark: order_remark,
  4108. ScheduleRemark: schedule_remark,
  4109. CatheterOperation: catheter_operation,
  4110. BloodFlowVolume: blood_flow_volume,
  4111. }
  4112. //修改床位号需要重新消毒
  4113. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4114. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4115. //查询第一条监测
  4116. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4117. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4118. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4119. redis := service.RedisClient()
  4120. //清空key 值
  4121. redis.Set(key, "", time.Second)
  4122. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4123. redis.Set(keyOne, "", time.Second)
  4124. defer redis.Close()
  4125. }
  4126. // 查询信息规挡的设置天数
  4127. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4128. if infor.ID > 0 && infor.WeekDay > 0 {
  4129. var cha_time int64
  4130. timeNowStr := time.Now().Format("2006-01-02")
  4131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4132. //今日的日期减去设置的日期
  4133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4134. if cha_time >= record_date {
  4135. //查询审核是否允许
  4136. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4137. //申请状态不允许的情况 拒绝修改
  4138. if infor.ApplicationStatus != 1 {
  4139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4140. return
  4141. }
  4142. }
  4143. }
  4144. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4145. order, _ := service.GetLastPatientOrder(record_id)
  4146. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4147. redis := service.RedisClient()
  4148. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4149. redis.Set(key, "", time.Second)
  4150. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4151. //清空key 值
  4152. redis.Set(keyOne, "", time.Second)
  4153. scheduleDateStartOne := startDate.Format("2006-01-02")
  4154. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4155. redis.Set(keyTwo, "", time.Second)
  4156. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4157. redis.Set(keyThree, "", time.Second)
  4158. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4159. redis.Set(keyFour, "", time.Second)
  4160. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4161. redis.Set(keyFive, "", time.Second)
  4162. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4163. redis.Set(keySix, "", time.Second)
  4164. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4165. redis.Set(keySeven, "", time.Second)
  4166. if updateErr != nil {
  4167. this.ErrorLog("修改上机失败:%v", updateErr)
  4168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4169. return
  4170. }
  4171. if updateErr == nil {
  4172. if tempDialysisRecord.Stage == 2 {
  4173. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4174. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4175. fmt.Println(value)
  4176. a, b := math.Modf(value)
  4177. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4178. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4179. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4180. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4181. redis := service.RedisClient()
  4182. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4183. redis.Set(key, "", time.Second)
  4184. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4185. redis.Set(keyOne, "", time.Second)
  4186. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4187. //清空key 值
  4188. redis.Set(keySix, "", time.Second)
  4189. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4190. redis.Set(keySeven, "", time.Second)
  4191. redis.Close()
  4192. if updateAssessmentErr != nil {
  4193. utils.ErrorLog("%v", updateAssessmentErr)
  4194. }
  4195. }
  4196. }
  4197. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4198. this.ServeSuccessJSON(map[string]interface{}{
  4199. "dialysis_order": dialysisRecords,
  4200. })
  4201. }
  4202. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4203. record_id, _ := c.GetInt64("id")
  4204. nurseID, _ := c.GetInt64("nurse")
  4205. end_time := c.GetString("end_time")
  4206. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4207. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4208. catheter := c.GetString("catheter")
  4209. cruor := c.GetString("cruor")
  4210. mission := c.GetString("mission")
  4211. condenser := c.GetString("condenser")
  4212. if record_id <= 0 || nurseID <= 0 {
  4213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4214. return
  4215. }
  4216. adminUserInfo := c.GetMobileAdminUserInfo()
  4217. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4218. if getNurseErr != nil {
  4219. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4221. return
  4222. } else if nurse == nil {
  4223. c.ErrorLog("护士不存在")
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4228. if parseEndDateErr != nil {
  4229. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. return
  4232. }
  4233. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4234. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4235. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4236. // if getPermissionErr != nil {
  4237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4238. // return
  4239. // } else if headNursePermission == nil {
  4240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4241. // return
  4242. // }
  4243. //}
  4244. // 查询信息规挡的设置天数
  4245. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4246. if infor.ID > 0 {
  4247. var cha_time int64
  4248. timeNowStr := time.Now().Format("2006-01-02")
  4249. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4250. //今日的日期减去设置的日期
  4251. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4252. if cha_time >= tempDialysisRecords.DialysisDate {
  4253. //查询审核是否允许
  4254. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4255. //申请状态不允许的情况 拒绝修改
  4256. if infor.ApplicationStatus != 1 {
  4257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4258. return
  4259. }
  4260. }
  4261. }
  4262. dialysisRecord := &models.DialysisOrder{
  4263. ID: record_id,
  4264. UserOrgId: adminUserInfo.Org.Id,
  4265. EndTime: endDate.Unix(),
  4266. FinishNurse: nurseID,
  4267. FinishModifier: adminUserInfo.AdminUser.Id,
  4268. PuncturePointHaematoma: puncture_point_haematoma,
  4269. BloodAccessInternalFistula: blood_access_internal_fistula,
  4270. Catheter: catheter,
  4271. Cruor: cruor,
  4272. Mission: mission,
  4273. Condenser: condenser,
  4274. }
  4275. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4276. redis := service.RedisClient()
  4277. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4278. //清空key 值
  4279. redis.Set(key, "", time.Second)
  4280. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4281. //清空key 值
  4282. redis.Set(keyOne, "", time.Second)
  4283. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4284. redis.Set(keySeven, "", time.Second)
  4285. redis.Close()
  4286. if updateErr != nil {
  4287. c.ErrorLog("修改下机失败:%v", updateErr)
  4288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4289. return
  4290. }
  4291. if updateErr == nil {
  4292. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4293. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4294. a, b := math.Modf(value)
  4295. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4296. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4297. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4298. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4299. redis := service.RedisClient()
  4300. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4301. redis.Set(keyTen, "", time.Second)
  4302. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4303. redis.Set(keyTwo, "", time.Second)
  4304. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4305. redis.Set(key, "", time.Second)
  4306. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4307. redis.Set(keyThree, "", time.Second)
  4308. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4309. redis.Set(keySeven, "", time.Second)
  4310. defer redis.Close()
  4311. if updateAssessmentErr != nil {
  4312. utils.ErrorLog("%v", updateAssessmentErr)
  4313. }
  4314. }
  4315. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4316. c.ServeSuccessJSON(map[string]interface{}{
  4317. "dialysis_order": dialysisRecords,
  4318. })
  4319. }
  4320. func (c *DialysisAPIController) GetLongAdvice() {
  4321. patient_id, _ := c.GetInt64("id")
  4322. adminUserInfo := c.GetMobileAdminUserInfo()
  4323. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4324. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4325. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4326. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4327. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4328. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4329. c.ServeSuccessJSON(map[string]interface{}{
  4330. "status": "1",
  4331. })
  4332. return
  4333. } else { //开启推送提醒
  4334. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4335. var advice_three []*models.DoctorAdvice
  4336. recordDateStr := time.Now().Format("2006-01-02")
  4337. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4338. nowtime := recordDate.Unix()
  4339. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4340. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4341. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4342. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4343. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4344. for _, advice := range advices {
  4345. if advice.FrequencyType == 3 {
  4346. t := time.Now()
  4347. week := int(t.Weekday())
  4348. fmt.Println(t.Weekday())
  4349. fmt.Println(week)
  4350. switch week {
  4351. case 1:
  4352. if strings.Index(advice.WeekDay, "周一") == -1 {
  4353. advice_three = append(advice_three, advice)
  4354. }
  4355. break
  4356. case 2:
  4357. if strings.Index(advice.WeekDay, "周二") == -1 {
  4358. advice_three = append(advice_three, advice)
  4359. }
  4360. break
  4361. case 3:
  4362. if strings.Index(advice.WeekDay, "周三") == -1 {
  4363. advice_three = append(advice_three, advice)
  4364. }
  4365. break
  4366. case 4:
  4367. if strings.Index(advice.WeekDay, "周四") == -1 {
  4368. advice_three = append(advice_three, advice)
  4369. }
  4370. break
  4371. case 5:
  4372. if strings.Index(advice.WeekDay, "周五") == -1 {
  4373. advice_three = append(advice_three, advice)
  4374. }
  4375. break
  4376. case 6:
  4377. if strings.Index(advice.WeekDay, "周六") == -1 {
  4378. advice_three = append(advice_three, advice)
  4379. }
  4380. break
  4381. case 0:
  4382. if strings.Index(advice.WeekDay, "周日") == -1 {
  4383. advice_three = append(advice_three, advice)
  4384. }
  4385. break
  4386. }
  4387. }
  4388. }
  4389. for _, advice := range advices_two {
  4390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4391. now := p.Unix()
  4392. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4393. dayStr2 := "-" + dayStr
  4394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4396. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4397. for _, ad := range advices {
  4398. advice_three = append(advice_three, ad)
  4399. }
  4400. }
  4401. if err == nil {
  4402. c.ServeSuccessJSON(map[string]interface{}{
  4403. "status": "2",
  4404. "advices": advices,
  4405. "advices_two": RemoveRepeatedElement(advice_three),
  4406. "is_open_remind": config.IsOpenRemind,
  4407. "his_config_open": hisConfig.IsOpen,
  4408. "is_advice_open": is_advice_open.IsAdviceOpen,
  4409. "prescription_open": prescription_open.IsOpen,
  4410. })
  4411. }
  4412. }
  4413. }
  4414. func (c *DialysisAPIController) GetLongAdviceOne() {
  4415. patient_id, _ := c.GetInt64("id")
  4416. startTime := c.GetString("schedule_date")
  4417. timeLayout := "2006-01-02"
  4418. loc, _ := time.LoadLocation("Local")
  4419. var theStartTime int64
  4420. if len(startTime) > 0 {
  4421. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4422. if err != nil {
  4423. utils.ErrorLog(err.Error())
  4424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4425. return
  4426. }
  4427. theStartTime = theTime.Unix()
  4428. }
  4429. adminUserInfo := c.GetMobileAdminUserInfo()
  4430. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4431. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4432. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4433. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4434. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4435. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4436. c.ServeSuccessJSON(map[string]interface{}{
  4437. "status": "1",
  4438. })
  4439. return
  4440. } else { //开启推送提醒
  4441. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4442. var advice_three []*models.DoctorAdvice
  4443. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4444. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4445. for _, advice := range advices {
  4446. if advice.FrequencyType == 3 {
  4447. t := time.Now()
  4448. week := int(t.Weekday())
  4449. fmt.Println(t.Weekday())
  4450. fmt.Println(week)
  4451. switch week {
  4452. case 1:
  4453. if strings.Index(advice.WeekDay, "周一") == -1 {
  4454. advice_three = append(advice_three, advice)
  4455. }
  4456. break
  4457. case 2:
  4458. if strings.Index(advice.WeekDay, "周二") == -1 {
  4459. advice_three = append(advice_three, advice)
  4460. }
  4461. break
  4462. case 3:
  4463. if strings.Index(advice.WeekDay, "周三") == -1 {
  4464. advice_three = append(advice_three, advice)
  4465. }
  4466. break
  4467. case 4:
  4468. if strings.Index(advice.WeekDay, "周四") == -1 {
  4469. advice_three = append(advice_three, advice)
  4470. }
  4471. break
  4472. case 5:
  4473. if strings.Index(advice.WeekDay, "周五") == -1 {
  4474. advice_three = append(advice_three, advice)
  4475. }
  4476. break
  4477. case 6:
  4478. if strings.Index(advice.WeekDay, "周六") == -1 {
  4479. advice_three = append(advice_three, advice)
  4480. }
  4481. break
  4482. case 0:
  4483. if strings.Index(advice.WeekDay, "周日") == -1 {
  4484. advice_three = append(advice_three, advice)
  4485. }
  4486. break
  4487. }
  4488. }
  4489. }
  4490. for _, advice := range advices_two {
  4491. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4492. now := p.Unix()
  4493. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4494. dayStr2 := "-" + dayStr
  4495. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4496. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4497. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4498. for _, ad := range advices {
  4499. advice_three = append(advice_three, ad)
  4500. }
  4501. }
  4502. if err == nil {
  4503. c.ServeSuccessJSON(map[string]interface{}{
  4504. "status": "2",
  4505. "advices": advices,
  4506. "advices_two": RemoveRepeatedElement(advice_three),
  4507. "is_open_remind": config.IsOpenRemind,
  4508. "his_config_open": hisConfig.IsOpen,
  4509. "is_advice_open": is_advice_open.IsAdviceOpen,
  4510. "prescription_open": prescription_open.IsOpen,
  4511. })
  4512. }
  4513. }
  4514. }
  4515. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4516. newArr = make([]*models.DoctorAdvice, 0)
  4517. for i := 0; i < len(arr); i++ {
  4518. repeat := false
  4519. for j := i + 1; j < len(arr); j++ {
  4520. if arr[i].ID == arr[j].ID {
  4521. repeat = true
  4522. break
  4523. }
  4524. }
  4525. if !repeat {
  4526. newArr = append(newArr, arr[i])
  4527. }
  4528. }
  4529. return
  4530. }
  4531. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4532. patient, _ := c.GetInt64("id", 0)
  4533. groupNo, _ := c.GetInt64("groupno", 0)
  4534. if patient <= 0 {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4536. return
  4537. }
  4538. adminUserInfo := c.GetMobileAdminUserInfo()
  4539. dataBody := make(map[string]interface{}, 0)
  4540. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4541. if err != nil {
  4542. utils.ErrorLog(err.Error())
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. utils.ErrorLog("%v", dataBody)
  4547. timeLayout := "2006-01-02 15:04"
  4548. loc, _ := time.LoadLocation("Local")
  4549. timeLayout2 := "2006-01-02"
  4550. loc2, _ := time.LoadLocation("Local")
  4551. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4552. utils.ErrorLog("advice_type")
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. adviceType := int64(2)
  4557. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4558. utils.ErrorLog("advice_date")
  4559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4560. return
  4561. }
  4562. adviceDate, _ := dataBody["advice_date"].(string)
  4563. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4564. AdviceDate := theTime.Unix()
  4565. RecordDate := theTime.Unix()
  4566. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4567. utils.ErrorLog("start_time")
  4568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. startTime, _ := dataBody["start_time"].(string)
  4572. if len(startTime) == 0 {
  4573. utils.ErrorLog("len(start_time) == 0")
  4574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4575. return
  4576. }
  4577. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4578. if err != nil {
  4579. utils.ErrorLog(err.Error())
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. StartTime := theTime.Unix()
  4584. Remark := ""
  4585. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4586. remark, _ := dataBody["remark"].(string)
  4587. Remark = remark
  4588. }
  4589. var advices []*models.GroupAdvice
  4590. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4591. utils.ErrorLog("advices")
  4592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4593. return
  4594. }
  4595. adviceNames := dataBody["advices"].([]interface{})
  4596. for _, adviceNameMap := range adviceNames {
  4597. adviceNameM := adviceNameMap.(map[string]interface{})
  4598. var advice models.GroupAdvice
  4599. advice.Remark = Remark
  4600. advice.AdviceType = adviceType
  4601. advice.StartTime = StartTime
  4602. advice.AdviceDate = AdviceDate
  4603. advice.RecordDate = RecordDate
  4604. advice.Status = 1
  4605. advice.CreatedTime = time.Now().Unix()
  4606. advice.UpdatedTime = time.Now().Unix()
  4607. advice.StopState = 2
  4608. advice.ExecutionState = 2
  4609. advice.UserOrgId = adminUserInfo.Org.Id
  4610. advice.PatientId = patient
  4611. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4612. advice.IsSettle = 2
  4613. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4614. utils.ErrorLog("advice_name")
  4615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4616. return
  4617. }
  4618. adviceName, _ := adviceNameM["advice_name"].(string)
  4619. if len(adviceName) == 0 {
  4620. utils.ErrorLog("len(advice_name) == 0")
  4621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4622. return
  4623. }
  4624. advice.AdviceName = adviceName
  4625. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4626. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4627. advice.DrugSpec = drugSpec
  4628. }
  4629. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4630. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4631. advice.AdviceDesc = adviceDesc
  4632. }
  4633. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4634. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4635. advice.DrugSpecUnit = drugSpecUnit
  4636. }
  4637. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4638. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4639. // advice.SingleDose = singleDose
  4640. //}
  4641. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4642. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4643. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4644. }
  4645. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4646. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4647. advice.SingleDoseUnit = singleDoseUnit
  4648. }
  4649. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4650. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4651. // advice.PrescribingNumber = prescribingNumber
  4652. //}
  4653. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4654. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4655. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4656. }
  4657. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4658. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4659. advice.PrescribingNumberUnit = prescribingNumberUnit
  4660. }
  4661. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4662. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4663. advice.DeliveryWay = deliveryWay
  4664. }
  4665. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4666. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4667. advice.ExecutionFrequency = executionFrequency
  4668. }
  4669. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4670. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4671. advice.FrequencyType = frequency_type
  4672. }
  4673. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4674. day_count := int64(adviceNameM["day_count"].(float64))
  4675. advice.DayCount = day_count
  4676. }
  4677. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4678. week_day, _ := adviceNameM["week_day"].(string)
  4679. advice.WeekDay = week_day
  4680. }
  4681. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4682. way := int64(adviceNameM["way"].(float64))
  4683. advice.Way = way
  4684. }
  4685. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4686. drug_id := int64(adviceNameM["drug_id"].(float64))
  4687. advice.DrugId = drug_id
  4688. }
  4689. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4690. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4691. advice.DrugNameId = drug_name_id
  4692. }
  4693. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4694. remark, _ := adviceNameM["remark"].(string)
  4695. advice.Remark = remark
  4696. }
  4697. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4698. groupno := int64(adviceNameM["groupno"].(float64))
  4699. advice.GroupNo = groupno
  4700. }
  4701. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4702. template_id, _ := adviceNameM["template_id"].(string)
  4703. advice.TemplateId = template_id
  4704. }
  4705. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4706. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4707. advice.ExecutionFrequency = executionFrequency
  4708. }
  4709. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4710. children := adviceNameM["child"].([]interface{})
  4711. if len(children) > 0 {
  4712. for _, childrenMap := range children {
  4713. childMap := childrenMap.(map[string]interface{})
  4714. var child models.GroupAdvice
  4715. child.Remark = Remark
  4716. child.AdviceType = adviceType
  4717. child.StartTime = StartTime
  4718. child.AdviceDate = AdviceDate
  4719. child.RecordDate = RecordDate
  4720. child.Status = 1
  4721. child.CreatedTime = time.Now().Unix()
  4722. child.UpdatedTime = time.Now().Unix()
  4723. child.StopState = 2
  4724. child.ExecutionState = 2
  4725. child.UserOrgId = adminUserInfo.Org.Id
  4726. child.PatientId = patient
  4727. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4728. child.IsSettle = 1
  4729. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4730. utils.ErrorLog("child advice_name")
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4732. return
  4733. }
  4734. childAdviceName, _ := childMap["advice_name"].(string)
  4735. if len(childAdviceName) == 0 {
  4736. utils.ErrorLog("len(child advice_name) == 0")
  4737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4738. return
  4739. }
  4740. child.AdviceName = childAdviceName
  4741. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4742. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4743. child.AdviceDesc = childAdviceDesc
  4744. }
  4745. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4746. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4747. child.DrugSpec = childDrugSpec
  4748. }
  4749. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4750. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4751. child.DrugSpecUnit = childDrugSpecUnit
  4752. }
  4753. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4754. child.SingleDose = childMap["single_dose"].(float64)
  4755. }
  4756. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4757. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4758. child.SingleDoseUnit = childSingleDoseUnit
  4759. }
  4760. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4761. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4762. }
  4763. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4764. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4765. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4766. }
  4767. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4768. groupno := int64(childMap["groupno"].(float64))
  4769. advice.GroupNo = groupno
  4770. }
  4771. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4772. remark, _ := childMap["remark"].(string)
  4773. child.Remark = remark
  4774. }
  4775. child.DeliveryWay = advice.DeliveryWay
  4776. child.ExecutionFrequency = advice.ExecutionFrequency
  4777. advice.Children = append(advice.Children, &child)
  4778. }
  4779. }
  4780. }
  4781. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4782. if temp_advice.ID == 0 {
  4783. advices = append(advices, &advice)
  4784. }
  4785. }
  4786. if len(advices) > 0 {
  4787. finish := models.XtDialysisFinish{
  4788. IsFinish: 1,
  4789. UserOrgId: adminUserInfo.Org.Id,
  4790. Status: 1,
  4791. Ctime: time.Now().Unix(),
  4792. Mtime: 0,
  4793. Module: 4,
  4794. RecordDate: AdviceDate,
  4795. Sourse: 1,
  4796. PatientId: patient,
  4797. }
  4798. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4799. if dialysisFinish.ID == 0 {
  4800. service.CreateDialysisFinish(finish)
  4801. }
  4802. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4803. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4804. for _, item := range advices {
  4805. byterequest, _ := json.Marshal(item)
  4806. adviceLog := models.XtDoctorAdviceLog{
  4807. UserOrgId: adminUserInfo.Org.Id,
  4808. PatientId: patient,
  4809. AdminUserId: adminUserInfo.AdminUser.Id,
  4810. Module: 1,
  4811. ErrLog: string(byterequest),
  4812. Status: 1,
  4813. Ctime: time.Now().Unix(),
  4814. Mtime: 0,
  4815. Source: "手机端医嘱推送",
  4816. RecordDate: item.AdviceDate,
  4817. }
  4818. service.CreateDoctorAdviceLog(adviceLog)
  4819. }
  4820. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4821. redis := service.RedisClient()
  4822. //清空key 值
  4823. redis.Set(key, "", time.Second)
  4824. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4825. redis.Set(keyOne, "", time.Second)
  4826. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4827. defer redis.Close()
  4828. redis.Set(keyThree, "", time.Second)
  4829. if err != nil {
  4830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4831. return
  4832. }
  4833. c.ServeSuccessJSON(map[string]interface{}{
  4834. "msg": "ok",
  4835. "advices": list,
  4836. })
  4837. } else {
  4838. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4839. for _, item := range advices {
  4840. byterequest, _ := json.Marshal(item)
  4841. adviceLog := models.XtDoctorAdviceLog{
  4842. UserOrgId: adminUserInfo.Org.Id,
  4843. PatientId: patient,
  4844. AdminUserId: adminUserInfo.AdminUser.Id,
  4845. Module: 1,
  4846. ErrLog: string(byterequest),
  4847. Status: 1,
  4848. Ctime: time.Now().Unix(),
  4849. Mtime: 0,
  4850. Source: "手机端医嘱推送",
  4851. RecordDate: item.AdviceDate,
  4852. }
  4853. service.CreateDoctorAdviceLog(adviceLog)
  4854. }
  4855. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4856. redis := service.RedisClient()
  4857. //清空key 值
  4858. redis.Set(key, "", time.Second)
  4859. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4860. redis.Set(keyOne, "", time.Second)
  4861. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4862. defer redis.Close()
  4863. redis.Set(keyThree, "", time.Second)
  4864. if err != nil {
  4865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4866. return
  4867. }
  4868. c.ServeSuccessJSON(map[string]interface{}{
  4869. "msg": "ok",
  4870. "advices": list,
  4871. })
  4872. }
  4873. } else {
  4874. c.ServeSuccessJSON(map[string]interface{}{
  4875. "msg": "ok",
  4876. })
  4877. }
  4878. return
  4879. }
  4880. func (c *DialysisAPIController) UploadDryWeight() {
  4881. patient_id, _ := c.GetInt64("id")
  4882. dry_weight, _ := c.GetFloat("dry_weight")
  4883. doctor_id, _ := c.GetInt64("doctor_id")
  4884. remark := c.GetString("remark")
  4885. adminUserInfo := c.GetMobileAdminUserInfo()
  4886. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4887. if err == gorm.ErrRecordNotFound {
  4888. dryWeight := &models.SgjPatientDryweight{
  4889. PatientId: patient_id,
  4890. DryWeight: dry_weight,
  4891. Remakes: remark,
  4892. Ctime: time.Now().Unix(),
  4893. Mtime: time.Now().Unix(),
  4894. Creator: doctor_id,
  4895. Status: 1,
  4896. UserOrgId: adminUserInfo.Org.Id,
  4897. AdjustedValue: "/",
  4898. UserId: adminUserInfo.AdminUser.Id,
  4899. }
  4900. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4901. redis := service.RedisClient()
  4902. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4903. redis.Set(keyOne, "", time.Second)
  4904. loc, _ := time.LoadLocation("Local")
  4905. nowTime := time.Now()
  4906. nowDay := nowTime.Format("2006-01-02")
  4907. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4908. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4909. redis.Set(key, "", time.Second)
  4910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4911. redis.Set(keyTwo, "", time.Second)
  4912. redis.Close()
  4913. if createErr == nil {
  4914. c.ServeSuccessJSON(map[string]interface{}{
  4915. "msg": "提交成功",
  4916. "weight": dryWeight,
  4917. })
  4918. }
  4919. } else {
  4920. dryWeight := &models.SgjPatientDryweight{
  4921. PatientId: patient_id,
  4922. DryWeight: dry_weight,
  4923. Remakes: remark,
  4924. Ctime: time.Now().Unix(),
  4925. Mtime: time.Now().Unix(),
  4926. Creator: doctor_id,
  4927. Status: 1,
  4928. UserOrgId: adminUserInfo.Org.Id,
  4929. AdjustedValue: "/",
  4930. UserId: adminUserInfo.AdminUser.Id,
  4931. }
  4932. var value float64
  4933. value = dry_weight - weightAdjust.DryWeight
  4934. if value < 0 {
  4935. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4936. } else if value == 0 {
  4937. dryWeight.AdjustedValue = "/"
  4938. } else if value > 0 {
  4939. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4940. }
  4941. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4942. redis := service.RedisClient()
  4943. loc, _ := time.LoadLocation("Local")
  4944. nowTime := time.Now()
  4945. nowDay := nowTime.Format("2006-01-02")
  4946. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4947. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4948. redis.Set(keyOne, "", time.Second)
  4949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4950. redis.Set(key, "", time.Second)
  4951. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4952. redis.Set(keyTwo, "", time.Second)
  4953. redis.Close()
  4954. if createErr == nil {
  4955. c.ServeSuccessJSON(map[string]interface{}{
  4956. "msg": "提交成功",
  4957. "weight": dryWeight,
  4958. })
  4959. }
  4960. }
  4961. }
  4962. func (c *DialysisAPIController) GetSolution() {
  4963. patient_id, _ := c.GetInt64("patient_id")
  4964. mode_id, _ := c.GetInt64("mode_id")
  4965. adminUserInfo := c.GetMobileAdminUserInfo()
  4966. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4967. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4968. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4969. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4970. if err != nil {
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4972. return
  4973. }
  4974. c.ServeSuccessJSON(map[string]interface{}{
  4975. "solution": solution,
  4976. "prescription": prescription,
  4977. "system_prescription": system_prescription,
  4978. "dialysisPrescription": dialysisPrescription,
  4979. })
  4980. }
  4981. func (c *DialysisAPIController) GetSchedule() {
  4982. schedual_type, _ := c.GetInt64("schedual_type")
  4983. adminUserInfo := c.GetMobileAdminUserInfo()
  4984. scheduleTime, _ := c.GetInt64("record_date")
  4985. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4986. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4987. c.ServeSuccessJSON(map[string]interface{}{
  4988. "number": deviceNumber,
  4989. "list": list,
  4990. })
  4991. }
  4992. func (c *DialysisAPIController) GetPatientId() {
  4993. id, _ := c.GetInt64("id")
  4994. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4995. patientId, _ := service.GetPatientId(id)
  4996. //获取该患者的所有传染病
  4997. list, _ := service.GetPatientInfectious(id)
  4998. c.ServeSuccessJSON(map[string]interface{}{
  4999. "patient": patientId,
  5000. "infectioulist": list,
  5001. })
  5002. }
  5003. func (this *DialysisAPIController) GetDialysisSchedule() {
  5004. schedualDate := this.GetString("date")
  5005. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5006. if parseDateErr != nil {
  5007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5008. return
  5009. }
  5010. adminInfo := this.GetMobileAdminUserInfo()
  5011. orgID := adminInfo.Org.Id
  5012. redis := service.RedisClient()
  5013. defer redis.Close()
  5014. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5015. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5016. if len(scheduals) > 0 {
  5017. //缓存数据
  5018. scheduals_json, err := json.Marshal(scheduals)
  5019. if err == nil {
  5020. redis.Set(key, scheduals_json, time.Second*30)
  5021. }
  5022. }
  5023. this.ServeSuccessJSON(map[string]interface{}{
  5024. "scheduals": scheduals,
  5025. })
  5026. }
  5027. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5028. change_type, _ := this.GetInt64("type", 0)
  5029. record_date := this.GetString("record_time")
  5030. patient_id, _ := this.GetInt64("patient_id", 0)
  5031. timeLayout := "2006-01-02"
  5032. loc, _ := time.LoadLocation("Local")
  5033. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5034. record_time := theAdviceRecordTime.Unix()
  5035. adminUserInfo := this.GetMobileAdminUserInfo()
  5036. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5037. if err == nil {
  5038. if len(advices) == 0 {
  5039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5040. return
  5041. } else {
  5042. this.ServeSuccessJSON(map[string]interface{}{
  5043. "advices": advices,
  5044. "schedule": sch,
  5045. })
  5046. return
  5047. }
  5048. } else {
  5049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5050. return
  5051. }
  5052. }
  5053. func (c *DialysisAPIController) CreateConsumables() {
  5054. record_date := c.GetString("record_time")
  5055. patient_id, _ := c.GetInt64("patient_id", 0)
  5056. active, _ := c.GetInt64("active")
  5057. adminUser := c.GetMobileAdminUserInfo()
  5058. timeLayout := "2006-01-02"
  5059. loc, _ := time.LoadLocation("Local")
  5060. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5061. record_time := theRecordTime.Unix()
  5062. // 查询信息规挡的设置天数
  5063. orgid := c.GetMobileAdminUserInfo().Org.Id
  5064. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5065. if infor.ID > 0 {
  5066. var cha_time int64
  5067. timeNowStr := time.Now().Format("2006-01-02")
  5068. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5069. //今日的日期减去设置的日期
  5070. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5071. if cha_time >= record_time {
  5072. //查询审核是否允许
  5073. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5074. //申请状态不允许的情况 拒绝修改
  5075. if infor.ApplicationStatus != 1 {
  5076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5077. return
  5078. }
  5079. }
  5080. }
  5081. dataBody := make(map[string]interface{}, 0)
  5082. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5083. if err != nil {
  5084. utils.ErrorLog(err.Error())
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5086. return
  5087. }
  5088. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5089. var beforePrepares []*models.DialysisBeforePrepareGoods
  5090. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5091. var dialysisBefor []*models.DialysisBeforePrepare
  5092. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5093. goods, _ := dataBody["goods"].([]interface{})
  5094. if len(goods) > 0 {
  5095. for _, item := range goods {
  5096. items := item.(map[string]interface{})
  5097. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5098. utils.ErrorLog("good_id")
  5099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5100. return
  5101. }
  5102. good_id := int64(items["good_id"].(float64))
  5103. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5104. utils.ErrorLog("good_type_id")
  5105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5106. return
  5107. }
  5108. good_type_id := int64(items["good_type_id"].(float64))
  5109. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5110. utils.ErrorLog("count")
  5111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5112. return
  5113. }
  5114. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5115. commdity_code := items["commdity_code"].(string)
  5116. fmt.Println("commdity", commdity_code)
  5117. prepareGoods := &models.DialysisBeforePrepareGoods{
  5118. GoodTypeId: good_type_id,
  5119. GoodId: good_id,
  5120. Count: count,
  5121. StorehouseId: houseConfig.StorehouseOutInfo,
  5122. }
  5123. beforePrepares = append(beforePrepares, prepareGoods)
  5124. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5125. GoodTypeId: good_type_id,
  5126. GoodId: good_id,
  5127. Count: count,
  5128. StorehouseId: houseConfig.StorehouseOutInfo,
  5129. }
  5130. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5131. prepare := &models.DialysisBeforePrepare{
  5132. GoodTypeId: good_type_id,
  5133. GoodId: good_id,
  5134. Count: count,
  5135. PatientId: patient_id,
  5136. RecordDate: record_time,
  5137. UserOrgId: adminUser.Org.Id,
  5138. Status: 1,
  5139. Ctime: time.Now().Unix(),
  5140. Creater: adminUser.AdminUser.Id,
  5141. CommdityCode: commdity_code,
  5142. StorehouseId: houseConfig.StorehouseOutInfo,
  5143. }
  5144. dialysisBefor = append(dialysisBefor, prepare)
  5145. }
  5146. }
  5147. //查询是否有库存
  5148. for _, item := range dialysisBefor {
  5149. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5150. if err == gorm.ErrRecordNotFound {
  5151. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5152. c.ServeSuccessJSON(map[string]interface{}{
  5153. "message": "1",
  5154. "good_name": goodObj.GoodName,
  5155. "specification_name": goodObj.SpecificationName,
  5156. })
  5157. return
  5158. }
  5159. if err != nil {
  5160. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5161. c.ServeSuccessJSON(map[string]interface{}{
  5162. "message": "1",
  5163. "good_name": goodObj.GoodName,
  5164. "specification_name": goodObj.SpecificationName,
  5165. })
  5166. return
  5167. }
  5168. }
  5169. //新增
  5170. if active == 1 && len(goods) > 0 {
  5171. for _, item := range dialysisBefor {
  5172. dialyPrepareOne := models.DialysisBeforePrepare{
  5173. GoodTypeId: item.GoodTypeId,
  5174. GoodId: item.GoodId,
  5175. PatientId: item.PatientId,
  5176. RecordDate: item.RecordDate,
  5177. UserOrgId: item.UserOrgId,
  5178. Count: item.Count,
  5179. Ctime: time.Now().Unix(),
  5180. Creater: item.Creater,
  5181. CommdityCode: item.CommdityCode,
  5182. Status: 1,
  5183. StorehouseId: houseConfig.StorehouseOutInfo,
  5184. }
  5185. //先清除再插入
  5186. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5187. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5188. //查询默认仓库
  5189. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5190. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5191. var total_count int64
  5192. for _, it := range stockList {
  5193. total_count += it.StockCount
  5194. }
  5195. //基础库插入数据
  5196. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5197. //更新库存
  5198. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5199. var flush_count int64
  5200. for _, it := range goodList {
  5201. flush_count += it.StockCount
  5202. }
  5203. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5204. }
  5205. if err == nil {
  5206. c.ServeSuccessJSON(map[string]interface{}{
  5207. "msg": "保存成功",
  5208. "message": "2",
  5209. })
  5210. return
  5211. } else {
  5212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5213. return
  5214. }
  5215. }
  5216. if len(beforePrepares) > 0 && active == 2 {
  5217. for _, item := range beforePrepares {
  5218. //1.查看该患者该耗材型号最后一次出库数量
  5219. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5220. //判断当前出库数量和最后一次出库数量的大小
  5221. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5222. if item.Count <= goodInfo.Count {
  5223. //退库
  5224. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5225. //查询今日出库数据
  5226. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5227. for _, it := range list {
  5228. prepare := models.DialysisBeforePrepare{
  5229. UserOrgId: it.OrgId,
  5230. PatientId: patient_id,
  5231. RecordDate: it.RecordTime,
  5232. GoodId: it.GoodId,
  5233. GoodTypeId: it.GoodTypeId,
  5234. Count: it.Count,
  5235. Ctime: time.Now().Unix(),
  5236. Creater: adminUser.AdminUser.Id,
  5237. Status: 1,
  5238. StorehouseId: houseConfig.StorehouseOutInfo,
  5239. }
  5240. //删除准备表数据
  5241. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5242. service.CreateDialysisBeforePrepareOne(&prepare)
  5243. }
  5244. }
  5245. var last_total int64
  5246. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5247. if item.Count >= goodInfo.Count {
  5248. //查询当前批次当前耗材最后一条出库数据
  5249. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5250. //计算当前出库和最后一次出库数据相差数据
  5251. last_total = item.Count - lastOutInfo.Count
  5252. //查询该批次剩余库存
  5253. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5254. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5255. if lastInfo.StockCount >= last_total {
  5256. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5257. //查询今日出库数据
  5258. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5259. for _, it := range list {
  5260. prepare := models.DialysisBeforePrepare{
  5261. UserOrgId: it.OrgId,
  5262. PatientId: patient_id,
  5263. RecordDate: it.RecordTime,
  5264. GoodId: it.GoodId,
  5265. GoodTypeId: it.GoodTypeId,
  5266. Count: it.Count,
  5267. Ctime: time.Now().Unix(),
  5268. Creater: adminUser.AdminUser.Id,
  5269. Status: 1,
  5270. StorehouseId: houseConfig.StorehouseOutInfo,
  5271. }
  5272. //删除准备表数据
  5273. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5274. service.CreateDialysisBeforePrepareOne(&prepare)
  5275. //查询默认仓库
  5276. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5277. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5278. var total_count int64
  5279. for _, it := range stockList {
  5280. total_count += it.StockCount
  5281. }
  5282. //基础库插入数据
  5283. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5284. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5285. var flush_count int64
  5286. for _, it := range goodList {
  5287. flush_count += it.StockCount
  5288. }
  5289. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5290. }
  5291. }
  5292. //如果库存不够,则出库到下一个批次
  5293. if lastInfo.StockCount < last_total {
  5294. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5295. //查询今日出库数据
  5296. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5297. for _, it := range list {
  5298. prepare := models.DialysisBeforePrepare{
  5299. UserOrgId: it.OrgId,
  5300. PatientId: patient_id,
  5301. RecordDate: it.RecordTime,
  5302. GoodId: it.GoodId,
  5303. GoodTypeId: it.GoodTypeId,
  5304. Count: it.Count,
  5305. Ctime: time.Now().Unix(),
  5306. Creater: adminUser.AdminUser.Id,
  5307. Status: 1,
  5308. StorehouseId: houseConfig.StorehouseOutInfo,
  5309. }
  5310. //删除准备表数据
  5311. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5312. service.CreateDialysisBeforePrepareOne(&prepare)
  5313. //查询默认仓库
  5314. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5315. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5316. var total_count int64
  5317. for _, it := range stockList {
  5318. total_count += it.StockCount
  5319. }
  5320. //基础库插入数据
  5321. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5322. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5323. var flush_count int64
  5324. for _, it := range goodList {
  5325. flush_count += it.StockCount
  5326. }
  5327. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5328. }
  5329. if err != nil {
  5330. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5331. c.ServeSuccessJSON(map[string]interface{}{
  5332. "message": "1",
  5333. "good_name": goodObj.GoodName,
  5334. "specification_name": goodObj.SpecificationName,
  5335. })
  5336. return
  5337. }
  5338. }
  5339. }
  5340. if err != nil {
  5341. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5342. c.ServeSuccessJSON(map[string]interface{}{
  5343. "message": "1",
  5344. "good_name": goodObj.GoodName,
  5345. "specification_name": goodObj.SpecificationName,
  5346. })
  5347. return
  5348. }
  5349. }
  5350. }
  5351. }
  5352. var errs error
  5353. if errs == nil {
  5354. c.ServeSuccessJSON(map[string]interface{}{
  5355. "msg": "提交成功",
  5356. "message": "2",
  5357. "good_name": "",
  5358. "specification_name": "",
  5359. })
  5360. return
  5361. } else {
  5362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5363. return
  5364. }
  5365. }
  5366. func (c *DialysisAPIController) CreateStockOutInfo() {
  5367. patient_id, _ := c.GetInt64("patient_id", 0)
  5368. record_date := c.GetString("record_time")
  5369. if patient_id <= 0 {
  5370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5371. return
  5372. }
  5373. adminInfo := c.GetMobileAdminUserInfo()
  5374. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5375. timeLayout := "2006-01-02"
  5376. loc, _ := time.LoadLocation("Local")
  5377. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5378. record_time := theRecordTime.Unix()
  5379. // 查询信息规挡的设置天数
  5380. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5381. if infor.ID > 0 && infor.WeekDay > 0 {
  5382. var cha_time int64
  5383. timeNowStr := time.Now().Format("2006-01-02")
  5384. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5385. //今日的日期减去设置的日期
  5386. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5387. if cha_time >= record_time {
  5388. //查询审核是否允许
  5389. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5390. //申请状态不允许的情况 拒绝修改
  5391. if infor.ApplicationStatus != 1 {
  5392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5393. return
  5394. }
  5395. }
  5396. }
  5397. //创建步骤表
  5398. finish := models.XtDialysisFinish{
  5399. IsFinish: 1,
  5400. UserOrgId: adminInfo.Org.Id,
  5401. Status: 1,
  5402. Ctime: time.Now().Unix(),
  5403. Mtime: 0,
  5404. Module: 11,
  5405. RecordDate: record_time,
  5406. Sourse: 1,
  5407. PatientId: patient_id,
  5408. }
  5409. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5410. if dialysisFinish.ID == 0 {
  5411. service.CreateDialysisFinish(finish)
  5412. }
  5413. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5414. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5415. //去重
  5416. consumables = RemoveRepeatedGood(consumables)
  5417. if adminInfo.Org.Id == 9919 {
  5418. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5419. //查询是否有库存
  5420. for _, item := range consumables {
  5421. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5422. if item.Count > warehouse.Count {
  5423. goodErrcode := models.XtGoodErrcode{
  5424. UserOrgId: item.UserOrgId,
  5425. Errcode: "自动出库库存不足",
  5426. GoodId: item.GoodId,
  5427. Status: 1,
  5428. Ctime: time.Now().Unix(),
  5429. Mtime: 0,
  5430. Count: 0,
  5431. StockCount: 0,
  5432. Creater: creator,
  5433. BatchNumberId: warehouse.ID,
  5434. WarehouseOutId: 0,
  5435. }
  5436. service.CreateGoodErrcode(goodErrcode)
  5437. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5438. c.ServeSuccessJSON(map[string]interface{}{
  5439. "message": "1",
  5440. "good_name": goodObj.GoodName,
  5441. "specification_name": goodObj.SpecificationName,
  5442. })
  5443. return
  5444. }
  5445. }
  5446. //查询是否有出库单
  5447. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5448. if err == gorm.ErrRecordNotFound {
  5449. //没有记录,则创建出库单
  5450. timeStr := time.Now().Format("2006-01-02")
  5451. timeArr := strings.Split(timeStr, "-")
  5452. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5453. total = total + 1
  5454. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5455. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5456. number = number + total
  5457. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5458. creater := adminInfo.AdminUser.Id
  5459. warehouseOut := models.WarehouseOut{
  5460. WarehouseOutOrderNumber: warehousing_out_order,
  5461. OperationTime: time.Now().Unix(),
  5462. OrgId: adminInfo.Org.Id,
  5463. Creater: creater,
  5464. Ctime: time.Now().Unix(),
  5465. Status: 1,
  5466. WarehouseOutTime: record_time,
  5467. Dealer: 0,
  5468. Manufacturer: 0,
  5469. Type: 1,
  5470. IsSys: 1,
  5471. StorehouseId: houseConfig.StorehouseOutInfo,
  5472. IsCheck: 1,
  5473. }
  5474. err := service.AddSigleWarehouseOut(&warehouseOut)
  5475. if err != nil {
  5476. goodErrcode := models.XtGoodErrcode{
  5477. UserOrgId: adminInfo.Org.Id,
  5478. Errcode: "创建出库单失败",
  5479. GoodId: 0,
  5480. Status: 1,
  5481. Ctime: time.Now().Unix(),
  5482. Mtime: 0,
  5483. Count: 0,
  5484. StockCount: 0,
  5485. Creater: creator,
  5486. BatchNumberId: 0,
  5487. WarehouseOutId: 0,
  5488. }
  5489. service.CreateGoodErrcode(goodErrcode)
  5490. utils.TraceLog("创建出库单失败 err = %v", err)
  5491. } else {
  5492. for _, item := range consumables {
  5493. //出库
  5494. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5495. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5496. if err == nil {
  5497. goodErrcode := models.XtGoodErrcode{
  5498. UserOrgId: adminInfo.Org.Id,
  5499. Errcode: "自动出库接口报错",
  5500. GoodId: 0,
  5501. Status: 1,
  5502. Ctime: time.Now().Unix(),
  5503. Mtime: 0,
  5504. Count: 0,
  5505. StockCount: 0,
  5506. Creater: creator,
  5507. BatchNumberId: 0,
  5508. WarehouseOutId: 0,
  5509. }
  5510. service.CreateGoodErrcode(goodErrcode)
  5511. utils.TraceLog("创建出库单失败 err = %v", err)
  5512. }
  5513. //查询
  5514. //出库数量相加
  5515. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5516. if errs != nil {
  5517. goodErrcode := models.XtGoodErrcode{
  5518. UserOrgId: item.UserOrgId,
  5519. Errcode: "创建剩余库存字段报错",
  5520. GoodId: item.GoodId,
  5521. Status: 1,
  5522. Ctime: time.Now().Unix(),
  5523. Mtime: 0,
  5524. Count: 0,
  5525. StockCount: 0,
  5526. Creater: creater,
  5527. BatchNumberId: 0,
  5528. WarehouseOutId: 0,
  5529. }
  5530. service.CreateGoodErrcode(goodErrcode)
  5531. }
  5532. }
  5533. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5534. if len(list) == 0 {
  5535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5536. return
  5537. }
  5538. for _, item := range list {
  5539. prepare := models.DialysisBeforePrepare{
  5540. UserOrgId: adminInfo.Org.Id,
  5541. PatientId: patient_id,
  5542. RecordDate: record_time,
  5543. GoodId: item.GoodId,
  5544. GoodTypeId: item.GoodTypeId,
  5545. Count: item.Count,
  5546. Creater: adminInfo.AdminUser.Id,
  5547. Status: 1,
  5548. Ctime: time.Now().Unix(),
  5549. StorehouseId: houseConfig.StorehouseOutInfo,
  5550. }
  5551. //清空准备表数据
  5552. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5553. if err != nil {
  5554. goodErrcode := models.XtGoodErrcode{
  5555. UserOrgId: item.OrgId,
  5556. Errcode: "自动出库清空准备表数据报错",
  5557. GoodId: item.GoodId,
  5558. Status: 1,
  5559. Ctime: time.Now().Unix(),
  5560. Mtime: 0,
  5561. Count: 0,
  5562. StockCount: 0,
  5563. Creater: creater,
  5564. BatchNumberId: 0,
  5565. WarehouseOutId: 0,
  5566. }
  5567. service.CreateGoodErrcode(goodErrcode)
  5568. }
  5569. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5570. if errs != nil {
  5571. goodErrcode := models.XtGoodErrcode{
  5572. UserOrgId: item.OrgId,
  5573. Errcode: "自动出库创建准备表数据报错",
  5574. GoodId: item.GoodId,
  5575. Status: 1,
  5576. Ctime: time.Now().Unix(),
  5577. Mtime: 0,
  5578. Count: 0,
  5579. StockCount: 0,
  5580. Creater: creater,
  5581. BatchNumberId: 0,
  5582. WarehouseOutId: 0,
  5583. }
  5584. service.CreateGoodErrcode(goodErrcode)
  5585. }
  5586. //查询默认仓库
  5587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5588. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5589. var total_count int64
  5590. for _, it := range stockList {
  5591. total_count += it.StockCount
  5592. }
  5593. //基础库插入数据
  5594. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5595. if errcodes != nil {
  5596. goodErrcode := models.XtGoodErrcode{
  5597. UserOrgId: item.OrgId,
  5598. Errcode: "自动出库基础库插入数据",
  5599. GoodId: item.GoodId,
  5600. Status: 1,
  5601. Ctime: time.Now().Unix(),
  5602. Mtime: 0,
  5603. Count: 0,
  5604. StockCount: 0,
  5605. Creater: creater,
  5606. BatchNumberId: 0,
  5607. WarehouseOutId: 0,
  5608. }
  5609. service.CreateGoodErrcode(goodErrcode)
  5610. }
  5611. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5612. var flush_count int64
  5613. for _, it := range goodList {
  5614. flush_count += it.StockCount
  5615. }
  5616. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5617. if errsss != nil {
  5618. goodErrcode := models.XtGoodErrcode{
  5619. UserOrgId: item.OrgId,
  5620. Errcode: "自动出库剩余库存更新数据",
  5621. GoodId: item.GoodId,
  5622. Status: 1,
  5623. Ctime: time.Now().Unix(),
  5624. Mtime: 0,
  5625. Count: 0,
  5626. StockCount: 0,
  5627. Creater: creater,
  5628. BatchNumberId: 0,
  5629. WarehouseOutId: 0,
  5630. }
  5631. service.CreateGoodErrcode(goodErrcode)
  5632. }
  5633. }
  5634. }
  5635. //
  5636. } else if err == nil {
  5637. for _, item := range consumables {
  5638. //出库
  5639. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5640. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5641. if err != nil {
  5642. goodErrcode := models.XtGoodErrcode{
  5643. UserOrgId: adminInfo.Org.Id,
  5644. Errcode: "自动出库接口报错",
  5645. GoodId: 0,
  5646. Status: 1,
  5647. Ctime: time.Now().Unix(),
  5648. Mtime: 0,
  5649. Count: 0,
  5650. StockCount: 0,
  5651. Creater: creator,
  5652. BatchNumberId: 0,
  5653. WarehouseOutId: 0,
  5654. }
  5655. service.CreateGoodErrcode(goodErrcode)
  5656. }
  5657. //出库数量相加
  5658. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5659. if errss != nil {
  5660. goodErrcode := models.XtGoodErrcode{
  5661. UserOrgId: item.UserOrgId,
  5662. Errcode: "创建剩余库存字段报错",
  5663. GoodId: item.GoodId,
  5664. Status: 1,
  5665. Ctime: time.Now().Unix(),
  5666. Mtime: time.Now().Unix(),
  5667. Count: 0,
  5668. StockCount: 0,
  5669. Creater: item.Creater,
  5670. BatchNumberId: 0,
  5671. WarehouseOutId: 0,
  5672. }
  5673. service.CreateGoodErrcode(goodErrcode)
  5674. }
  5675. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5676. if len(list) == 0 {
  5677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5678. return
  5679. }
  5680. for _, item := range list {
  5681. prepare := models.DialysisBeforePrepare{
  5682. UserOrgId: adminInfo.Org.Id,
  5683. PatientId: patient_id,
  5684. RecordDate: record_time,
  5685. GoodId: item.GoodId,
  5686. GoodTypeId: item.GoodTypeId,
  5687. Count: item.Count,
  5688. Creater: adminInfo.AdminUser.Id,
  5689. Status: 1,
  5690. Ctime: time.Now().Unix(),
  5691. StorehouseId: houseConfig.StorehouseOutInfo,
  5692. }
  5693. //清空准备表数据
  5694. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5695. if errs != nil {
  5696. goodErrcode := models.XtGoodErrcode{
  5697. UserOrgId: adminInfo.Org.Id,
  5698. Errcode: "自动出库清空准备表数据报错",
  5699. GoodId: 0,
  5700. Status: 1,
  5701. Ctime: time.Now().Unix(),
  5702. Mtime: 0,
  5703. Count: 0,
  5704. StockCount: 0,
  5705. Creater: creator,
  5706. BatchNumberId: 0,
  5707. WarehouseOutId: 0,
  5708. }
  5709. service.CreateGoodErrcode(goodErrcode)
  5710. }
  5711. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5712. if errcodes != nil {
  5713. goodErrcode := models.XtGoodErrcode{
  5714. UserOrgId: adminInfo.Org.Id,
  5715. Errcode: "自动出库创建准备表数据报错",
  5716. GoodId: 0,
  5717. Status: 1,
  5718. Ctime: time.Now().Unix(),
  5719. Mtime: 0,
  5720. Count: 0,
  5721. StockCount: 0,
  5722. Creater: creator,
  5723. BatchNumberId: 0,
  5724. WarehouseOutId: 0,
  5725. }
  5726. service.CreateGoodErrcode(goodErrcode)
  5727. }
  5728. //查询默认仓库
  5729. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5730. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5731. var total_count int64
  5732. for _, it := range stockList {
  5733. total_count += it.StockCount
  5734. }
  5735. //基础库插入数据
  5736. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5737. if errcodes != nil {
  5738. goodErrcode := models.XtGoodErrcode{
  5739. UserOrgId: adminInfo.Org.Id,
  5740. Errcode: "自动出库基础库插入数据报错",
  5741. GoodId: 0,
  5742. Status: 1,
  5743. Ctime: time.Now().Unix(),
  5744. Mtime: 0,
  5745. Count: 0,
  5746. StockCount: 0,
  5747. Creater: creator,
  5748. BatchNumberId: 0,
  5749. WarehouseOutId: 0,
  5750. }
  5751. service.CreateGoodErrcode(goodErrcode)
  5752. }
  5753. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5754. var flush_count int64
  5755. for _, it := range goodList {
  5756. flush_count += it.StockCount
  5757. }
  5758. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5759. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5760. if errss != nil {
  5761. goodErrcode := models.XtGoodErrcode{
  5762. UserOrgId: item.OrgId,
  5763. Errcode: "自动出库剩余库存更新数据",
  5764. GoodId: item.GoodId,
  5765. Status: 1,
  5766. Ctime: time.Now().Unix(),
  5767. Mtime: 0,
  5768. Count: 0,
  5769. StockCount: 0,
  5770. Creater: creater,
  5771. BatchNumberId: 0,
  5772. WarehouseOutId: 0,
  5773. }
  5774. service.CreateGoodErrcode(goodErrcode)
  5775. }
  5776. }
  5777. }
  5778. }
  5779. c.ServeSuccessJSON(map[string]interface{}{
  5780. "msg": "提交成功",
  5781. "message": "2",
  5782. "good_name": "",
  5783. "specification_name": "",
  5784. })
  5785. return
  5786. }
  5787. if record.IsOpen == 1 {
  5788. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5789. //查询是否有库存
  5790. for _, item := range consumables {
  5791. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5792. if item.Count > warehouse.Count {
  5793. goodErrcode := models.XtGoodErrcode{
  5794. UserOrgId: item.UserOrgId,
  5795. Errcode: "自动出库库存不足",
  5796. GoodId: item.GoodId,
  5797. Status: 1,
  5798. Ctime: time.Now().Unix(),
  5799. Mtime: 0,
  5800. Count: 0,
  5801. StockCount: 0,
  5802. Creater: creator,
  5803. BatchNumberId: warehouse.ID,
  5804. WarehouseOutId: 0,
  5805. }
  5806. service.CreateGoodErrcode(goodErrcode)
  5807. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5808. c.ServeSuccessJSON(map[string]interface{}{
  5809. "message": "1",
  5810. "good_name": goodObj.GoodName,
  5811. "specification_name": goodObj.SpecificationName,
  5812. })
  5813. return
  5814. }
  5815. }
  5816. //查询是否有出库单
  5817. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5818. if err == gorm.ErrRecordNotFound {
  5819. //没有记录,则创建出库单
  5820. timeStr := time.Now().Format("2006-01-02")
  5821. timeArr := strings.Split(timeStr, "-")
  5822. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5823. total = total + 1
  5824. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5825. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5826. number = number + total
  5827. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5828. creater := adminInfo.AdminUser.Id
  5829. warehouseOut := models.WarehouseOut{
  5830. WarehouseOutOrderNumber: warehousing_out_order,
  5831. OperationTime: time.Now().Unix(),
  5832. OrgId: adminInfo.Org.Id,
  5833. Creater: creater,
  5834. Ctime: time.Now().Unix(),
  5835. Status: 1,
  5836. WarehouseOutTime: record_time,
  5837. Dealer: 0,
  5838. Manufacturer: 0,
  5839. Type: 1,
  5840. IsSys: 1,
  5841. StorehouseId: houseConfig.StorehouseOutInfo,
  5842. IsCheck: 1,
  5843. }
  5844. err := service.AddSigleWarehouseOut(&warehouseOut)
  5845. if err != nil {
  5846. goodErrcode := models.XtGoodErrcode{
  5847. UserOrgId: adminInfo.Org.Id,
  5848. Errcode: "创建出库单失败",
  5849. GoodId: 0,
  5850. Status: 1,
  5851. Ctime: time.Now().Unix(),
  5852. Mtime: 0,
  5853. Count: 0,
  5854. StockCount: 0,
  5855. Creater: creator,
  5856. BatchNumberId: 0,
  5857. WarehouseOutId: 0,
  5858. }
  5859. service.CreateGoodErrcode(goodErrcode)
  5860. utils.TraceLog("创建出库单失败 err = %v", err)
  5861. } else {
  5862. for _, item := range consumables {
  5863. //出库
  5864. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5865. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5866. if err == nil {
  5867. goodErrcode := models.XtGoodErrcode{
  5868. UserOrgId: adminInfo.Org.Id,
  5869. Errcode: "自动出库接口报错",
  5870. GoodId: 0,
  5871. Status: 1,
  5872. Ctime: time.Now().Unix(),
  5873. Mtime: 0,
  5874. Count: 0,
  5875. StockCount: 0,
  5876. Creater: creator,
  5877. BatchNumberId: 0,
  5878. WarehouseOutId: 0,
  5879. }
  5880. service.CreateGoodErrcode(goodErrcode)
  5881. utils.TraceLog("创建出库单失败 err = %v", err)
  5882. }
  5883. //查询
  5884. //出库数量相加
  5885. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5886. if errs != nil {
  5887. goodErrcode := models.XtGoodErrcode{
  5888. UserOrgId: item.UserOrgId,
  5889. Errcode: "创建剩余库存字段报错",
  5890. GoodId: item.GoodId,
  5891. Status: 1,
  5892. Ctime: time.Now().Unix(),
  5893. Mtime: 0,
  5894. Count: 0,
  5895. StockCount: 0,
  5896. Creater: creater,
  5897. BatchNumberId: 0,
  5898. WarehouseOutId: 0,
  5899. }
  5900. service.CreateGoodErrcode(goodErrcode)
  5901. }
  5902. }
  5903. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5904. if len(list) == 0 {
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5906. return
  5907. }
  5908. for _, item := range list {
  5909. prepare := models.DialysisBeforePrepare{
  5910. UserOrgId: adminInfo.Org.Id,
  5911. PatientId: patient_id,
  5912. RecordDate: record_time,
  5913. GoodId: item.GoodId,
  5914. GoodTypeId: item.GoodTypeId,
  5915. Count: item.Count,
  5916. Creater: adminInfo.AdminUser.Id,
  5917. Status: 1,
  5918. Ctime: time.Now().Unix(),
  5919. StorehouseId: houseConfig.StorehouseOutInfo,
  5920. }
  5921. //清空准备表数据
  5922. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5923. if err != nil {
  5924. goodErrcode := models.XtGoodErrcode{
  5925. UserOrgId: item.OrgId,
  5926. Errcode: "自动出库清空准备表数据报错",
  5927. GoodId: item.GoodId,
  5928. Status: 1,
  5929. Ctime: time.Now().Unix(),
  5930. Mtime: 0,
  5931. Count: 0,
  5932. StockCount: 0,
  5933. Creater: creater,
  5934. BatchNumberId: 0,
  5935. WarehouseOutId: 0,
  5936. }
  5937. service.CreateGoodErrcode(goodErrcode)
  5938. }
  5939. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5940. if errs != nil {
  5941. goodErrcode := models.XtGoodErrcode{
  5942. UserOrgId: item.OrgId,
  5943. Errcode: "自动出库创建准备表数据报错",
  5944. GoodId: item.GoodId,
  5945. Status: 1,
  5946. Ctime: time.Now().Unix(),
  5947. Mtime: 0,
  5948. Count: 0,
  5949. StockCount: 0,
  5950. Creater: creater,
  5951. BatchNumberId: 0,
  5952. WarehouseOutId: 0,
  5953. }
  5954. service.CreateGoodErrcode(goodErrcode)
  5955. }
  5956. //查询默认仓库
  5957. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5958. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5959. var total_count int64
  5960. for _, it := range stockList {
  5961. total_count += it.StockCount
  5962. }
  5963. //基础库插入数据
  5964. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5965. if errcodes != nil {
  5966. goodErrcode := models.XtGoodErrcode{
  5967. UserOrgId: item.OrgId,
  5968. Errcode: "自动出库基础库插入数据",
  5969. GoodId: item.GoodId,
  5970. Status: 1,
  5971. Ctime: time.Now().Unix(),
  5972. Mtime: 0,
  5973. Count: 0,
  5974. StockCount: 0,
  5975. Creater: creater,
  5976. BatchNumberId: 0,
  5977. WarehouseOutId: 0,
  5978. }
  5979. service.CreateGoodErrcode(goodErrcode)
  5980. }
  5981. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5982. var flush_count int64
  5983. for _, it := range goodList {
  5984. flush_count += it.StockCount
  5985. }
  5986. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5987. if errsss != nil {
  5988. goodErrcode := models.XtGoodErrcode{
  5989. UserOrgId: item.OrgId,
  5990. Errcode: "自动出库剩余库存更新数据",
  5991. GoodId: item.GoodId,
  5992. Status: 1,
  5993. Ctime: time.Now().Unix(),
  5994. Mtime: 0,
  5995. Count: 0,
  5996. StockCount: 0,
  5997. Creater: creater,
  5998. BatchNumberId: 0,
  5999. WarehouseOutId: 0,
  6000. }
  6001. service.CreateGoodErrcode(goodErrcode)
  6002. }
  6003. }
  6004. }
  6005. //
  6006. } else if err == nil {
  6007. for _, item := range consumables {
  6008. //出库
  6009. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6010. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6011. if err != nil {
  6012. goodErrcode := models.XtGoodErrcode{
  6013. UserOrgId: adminInfo.Org.Id,
  6014. Errcode: "自动出库接口报错",
  6015. GoodId: 0,
  6016. Status: 1,
  6017. Ctime: time.Now().Unix(),
  6018. Mtime: 0,
  6019. Count: 0,
  6020. StockCount: 0,
  6021. Creater: creator,
  6022. BatchNumberId: 0,
  6023. WarehouseOutId: 0,
  6024. }
  6025. service.CreateGoodErrcode(goodErrcode)
  6026. }
  6027. //出库数量相加
  6028. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6029. if errss != nil {
  6030. goodErrcode := models.XtGoodErrcode{
  6031. UserOrgId: item.UserOrgId,
  6032. Errcode: "创建剩余库存字段报错",
  6033. GoodId: item.GoodId,
  6034. Status: 1,
  6035. Ctime: time.Now().Unix(),
  6036. Mtime: time.Now().Unix(),
  6037. Count: 0,
  6038. StockCount: 0,
  6039. Creater: item.Creater,
  6040. BatchNumberId: 0,
  6041. WarehouseOutId: 0,
  6042. }
  6043. service.CreateGoodErrcode(goodErrcode)
  6044. }
  6045. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6046. if len(list) == 0 {
  6047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6048. return
  6049. }
  6050. for _, item := range list {
  6051. prepare := models.DialysisBeforePrepare{
  6052. UserOrgId: adminInfo.Org.Id,
  6053. PatientId: patient_id,
  6054. RecordDate: record_time,
  6055. GoodId: item.GoodId,
  6056. GoodTypeId: item.GoodTypeId,
  6057. Count: item.Count,
  6058. Creater: adminInfo.AdminUser.Id,
  6059. Status: 1,
  6060. Ctime: time.Now().Unix(),
  6061. StorehouseId: houseConfig.StorehouseOutInfo,
  6062. }
  6063. //清空准备表数据
  6064. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6065. if errs != nil {
  6066. goodErrcode := models.XtGoodErrcode{
  6067. UserOrgId: adminInfo.Org.Id,
  6068. Errcode: "自动出库清空准备表数据报错",
  6069. GoodId: 0,
  6070. Status: 1,
  6071. Ctime: time.Now().Unix(),
  6072. Mtime: 0,
  6073. Count: 0,
  6074. StockCount: 0,
  6075. Creater: creator,
  6076. BatchNumberId: 0,
  6077. WarehouseOutId: 0,
  6078. }
  6079. service.CreateGoodErrcode(goodErrcode)
  6080. }
  6081. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6082. if errcodes != nil {
  6083. goodErrcode := models.XtGoodErrcode{
  6084. UserOrgId: adminInfo.Org.Id,
  6085. Errcode: "自动出库创建准备表数据报错",
  6086. GoodId: 0,
  6087. Status: 1,
  6088. Ctime: time.Now().Unix(),
  6089. Mtime: 0,
  6090. Count: 0,
  6091. StockCount: 0,
  6092. Creater: creator,
  6093. BatchNumberId: 0,
  6094. WarehouseOutId: 0,
  6095. }
  6096. service.CreateGoodErrcode(goodErrcode)
  6097. }
  6098. //查询默认仓库
  6099. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6100. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6101. var total_count int64
  6102. for _, it := range stockList {
  6103. total_count += it.StockCount
  6104. }
  6105. //基础库插入数据
  6106. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6107. if errcodes != nil {
  6108. goodErrcode := models.XtGoodErrcode{
  6109. UserOrgId: adminInfo.Org.Id,
  6110. Errcode: "自动出库基础库插入数据报错",
  6111. GoodId: 0,
  6112. Status: 1,
  6113. Ctime: time.Now().Unix(),
  6114. Mtime: 0,
  6115. Count: 0,
  6116. StockCount: 0,
  6117. Creater: creator,
  6118. BatchNumberId: 0,
  6119. WarehouseOutId: 0,
  6120. }
  6121. service.CreateGoodErrcode(goodErrcode)
  6122. }
  6123. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6124. var flush_count int64
  6125. for _, it := range goodList {
  6126. flush_count += it.StockCount
  6127. }
  6128. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6129. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6130. if errss != nil {
  6131. goodErrcode := models.XtGoodErrcode{
  6132. UserOrgId: item.OrgId,
  6133. Errcode: "自动出库剩余库存更新数据",
  6134. GoodId: item.GoodId,
  6135. Status: 1,
  6136. Ctime: time.Now().Unix(),
  6137. Mtime: 0,
  6138. Count: 0,
  6139. StockCount: 0,
  6140. Creater: creater,
  6141. BatchNumberId: 0,
  6142. WarehouseOutId: 0,
  6143. }
  6144. service.CreateGoodErrcode(goodErrcode)
  6145. }
  6146. }
  6147. }
  6148. }
  6149. c.ServeSuccessJSON(map[string]interface{}{
  6150. "msg": "提交成功",
  6151. "message": "2",
  6152. "good_name": "",
  6153. "specification_name": "",
  6154. })
  6155. return
  6156. } else {
  6157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6158. return
  6159. }
  6160. }
  6161. func (c *DialysisAPIController) EditConsumables() {
  6162. patient_id, _ := c.GetInt64("patient_id", 0)
  6163. record_date := c.GetString("record_time")
  6164. if patient_id <= 0 {
  6165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6166. return
  6167. }
  6168. adminInfo := c.GetMobileAdminUserInfo()
  6169. timeLayout := "2006-01-02"
  6170. loc, _ := time.LoadLocation("Local")
  6171. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6172. record_time := theRecordTime.Unix()
  6173. // 查询信息规挡的设置天数
  6174. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6175. if infor.ID > 0 && infor.WeekDay > 0 {
  6176. var cha_time int64
  6177. timeNowStr := time.Now().Format("2006-01-02")
  6178. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6179. //今日的日期减去设置的日期
  6180. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6181. if cha_time >= record_time {
  6182. //查询审核是否允许
  6183. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6184. //申请状态不允许的情况 拒绝修改
  6185. if infor.ApplicationStatus != 1 {
  6186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6187. return
  6188. }
  6189. }
  6190. }
  6191. dataBody := make(map[string]interface{}, 0)
  6192. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6193. if err != nil {
  6194. utils.ErrorLog(err.Error())
  6195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6196. return
  6197. }
  6198. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6199. var beforePrepares []*models.DialysisBeforePrepareGoods
  6200. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6201. var cancelbefor []*models.DialysisBeforePrepareGoods
  6202. var outbefor []*models.DialysisBeforePrepareGoods
  6203. //判断是否开启自动出库
  6204. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6205. if record.IsOpen == 1 {
  6206. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6207. goods, _ := dataBody["goods"].([]interface{})
  6208. if len(goods) > 0 {
  6209. for _, item := range goods {
  6210. items := item.(map[string]interface{})
  6211. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6212. utils.ErrorLog("good_id")
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6214. return
  6215. }
  6216. good_id := int64(items["good_id"].(float64))
  6217. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6218. utils.ErrorLog("good_type_id")
  6219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6220. return
  6221. }
  6222. good_type_id := int64(items["good_type_id"].(float64))
  6223. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6224. utils.ErrorLog("count")
  6225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6226. return
  6227. }
  6228. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6229. commdity_code := items["commdity_code"].(string)
  6230. fmt.Println(commdity_code)
  6231. prepareGoods := &models.DialysisBeforePrepareGoods{
  6232. GoodTypeId: good_type_id,
  6233. GoodId: good_id,
  6234. Count: count,
  6235. StorehouseId: houseConfig.StorehouseOutInfo,
  6236. }
  6237. beforePrepares = append(beforePrepares, prepareGoods)
  6238. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6239. GoodTypeId: good_type_id,
  6240. GoodId: good_id,
  6241. Count: count,
  6242. StorehouseId: houseConfig.StorehouseOutInfo,
  6243. }
  6244. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6245. }
  6246. for _, item := range beforePrepares {
  6247. //1.查看该患者该耗材型号最后一次出库数量
  6248. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6249. //判断当前出库数量和最后一次出库数量的大小
  6250. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6251. if item.Count < goodInfo.Count {
  6252. cancelbefor = append(cancelbefor, item)
  6253. }
  6254. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6255. if item.Count > goodInfo.Count {
  6256. outbefor = append(outbefor, item)
  6257. }
  6258. //处理编辑耗材新增不了的问题
  6259. if goodInfo.Count == item.Count {
  6260. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6261. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6262. }
  6263. }
  6264. if len(cancelbefor) > 0 {
  6265. //退库
  6266. for _, item := range cancelbefor {
  6267. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6268. creater := adminInfo.AdminUser.Id
  6269. //查询该患者当天已经出库的耗材信息
  6270. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6271. var delete_count int64 = 0
  6272. delete_count = warehouseOutInfos.Count - item.Count
  6273. //增加库存数量
  6274. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6275. //减少实际出库库存数量
  6276. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6277. // 删除出库完成后,要增加对应批次的库存数量
  6278. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6279. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6280. //更新剩余库存
  6281. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6282. var flush_count int64
  6283. for _, it := range goodListOne {
  6284. flush_count += it.StockCount
  6285. }
  6286. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6287. //查询剩余库存
  6288. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6289. var sum_count int64
  6290. for _, item := range goodList {
  6291. sum_count += item.StockCount
  6292. }
  6293. // 在出库记录表里记录退库详情
  6294. warehouseOutInfo := &models.WarehouseOutInfo{
  6295. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6296. WarehouseOutId: warehouseOut.ID,
  6297. Status: 1,
  6298. Ctime: time.Now().Unix(),
  6299. OrgId: adminInfo.Org.Id,
  6300. Type: 1,
  6301. IsSys: 1,
  6302. SysRecordTime: record_time,
  6303. GoodTypeId: item.GoodTypeId,
  6304. GoodId: item.GoodId,
  6305. PatientId: patient_id,
  6306. ConsumableType: 2,
  6307. StorehouseId: houseConfig.StorehouseOutInfo,
  6308. IsCheck: 1,
  6309. OverCount: sum_count,
  6310. }
  6311. warehouseOutInfo.Count = item.Count
  6312. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6313. warehouseOutInfo.Price = stockInInfo.Price
  6314. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6315. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6316. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6317. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6318. warehouseOutInfo.Number = warehouseOutInfos.Number
  6319. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6320. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6321. //查找当天是否存在出库记录
  6322. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6323. if errcod == gorm.ErrRecordNotFound {
  6324. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6325. //插入详情明细表
  6326. stockFlow := models.VmStockFlow{
  6327. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6328. WarehouseOutId: warehouseOut.ID,
  6329. GoodId: item.GoodId,
  6330. Number: warehouseOutInfos.Number,
  6331. ProductDate: stockInInfo.ProductDate,
  6332. ExpireDate: stockInInfo.ExpiryDate,
  6333. Count: item.Count,
  6334. Price: stockInInfo.Price,
  6335. Status: 1,
  6336. Ctime: time.Now().Unix(),
  6337. UserOrgId: adminInfo.Org.Id,
  6338. Manufacturer: stockInInfo.Manufacturer,
  6339. Dealer: stockInInfo.Dealer,
  6340. LicenseNumber: stockInInfo.LicenseNumber,
  6341. IsEdit: 2,
  6342. Creator: creater,
  6343. SystemTime: record_time,
  6344. ConsumableType: 3,
  6345. WarehousingDetailId: 0,
  6346. IsSys: 1,
  6347. UpdateCreator: creater,
  6348. PatientId: patient_id,
  6349. StorehouseId: houseConfig.StorehouseOutInfo,
  6350. }
  6351. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6352. if errflow == gorm.ErrRecordNotFound {
  6353. //创建流水表
  6354. err := service.CreateStockFlowOne(stockFlow)
  6355. fmt.Println("err", err)
  6356. } else if errflow == nil {
  6357. //插入详情明细表
  6358. stockFlow := models.VmStockFlow{
  6359. ID: exsit.ID,
  6360. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6361. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6362. WarehouseOutId: warehouseOut.ID,
  6363. GoodId: item.GoodId,
  6364. Number: warehouseOutInfos.Number,
  6365. ProductDate: stockInInfo.ProductDate,
  6366. ExpireDate: stockInInfo.ExpiryDate,
  6367. Count: exsit.Count - delete_count,
  6368. Price: stockInInfo.Price,
  6369. Status: 1,
  6370. Ctime: time.Now().Unix(),
  6371. UserOrgId: adminInfo.Org.Id,
  6372. Manufacturer: stockInInfo.Manufacturer,
  6373. Dealer: stockInInfo.Dealer,
  6374. LicenseNumber: stockInInfo.LicenseNumber,
  6375. IsEdit: 2,
  6376. Creator: creater,
  6377. SystemTime: record_time,
  6378. ConsumableType: 3,
  6379. WarehousingDetailId: 0,
  6380. IsSys: 1,
  6381. UpdateCreator: creater,
  6382. PatientId: patient_id,
  6383. StorehouseId: houseConfig.StorehouseOutInfo,
  6384. }
  6385. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6386. }
  6387. } else if errcod == nil {
  6388. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6389. //查询剩余库存
  6390. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6391. var sum_count int64
  6392. for _, item := range goodList {
  6393. sum_count += item.StockCount
  6394. }
  6395. //创建退库单,生成退库数据
  6396. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6397. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6398. operation_time := time.Now().Unix()
  6399. creater := adminInfo.AdminUser.Id
  6400. //创建退库单
  6401. timeStr := time.Now().Format("2006-01-02")
  6402. timeArr := strings.Split(timeStr, "-")
  6403. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6404. total = total + 1
  6405. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6406. cancelStock := models.CancelStock{
  6407. OrderNumber: orderNumber,
  6408. OperaTime: operation_time,
  6409. OrgId: adminInfo.Org.Id,
  6410. Creater: creater,
  6411. Ctime: time.Now().Unix(),
  6412. Status: 1,
  6413. ReturnTime: record_time,
  6414. Type: 1,
  6415. StorehouseId: houseConfig.StorehouseOutInfo,
  6416. IsCheck: 1,
  6417. }
  6418. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6419. if msgerrkonde == gorm.ErrRecordNotFound {
  6420. service.AddSigleCancelStock(&cancelStock)
  6421. }
  6422. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6423. //查询是否有出库
  6424. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6425. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6426. deaerler, _ := service.GetDealerById(info.Dealer)
  6427. if info.ID > 0 {
  6428. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6429. cancelStockInfo := models.CancelStockInfo{
  6430. GoodId: item.GoodId,
  6431. CancelStockId: cancel.ID,
  6432. GoodTypeId: good.GoodTypeId,
  6433. Count: delete_count,
  6434. Price: info.Price,
  6435. Total: 0,
  6436. ProductDate: info.ProductDate,
  6437. ExpiryDate: info.ExpiryDate,
  6438. Ctime: time.Now().Unix(),
  6439. Status: 1,
  6440. OrgId: adminInfo.Org.Id,
  6441. OrderNumber: cancel.OrderNumber,
  6442. Type: 0,
  6443. Dealer: deaerler.DealerName,
  6444. Manufacturer: manufacturer.ManufacturerName,
  6445. Number: info.Number,
  6446. RegisterAccount: "",
  6447. Remark: "",
  6448. WarehouseInfoId: info.WarehouseInfotId,
  6449. PatientId: info.PatientId,
  6450. RecordDate: info.SysRecordTime,
  6451. StorehouseId: houseConfig.StorehouseOutInfo,
  6452. IsCheck: 1,
  6453. }
  6454. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6455. //退库数量增加
  6456. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6457. //查询剩余库存
  6458. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6459. var over_count int64
  6460. for _, it := range goodList {
  6461. over_count += it.StockCount
  6462. }
  6463. flow := models.VmStockFlow{
  6464. WarehousingId: info.WarehouseInfotId,
  6465. GoodId: item.GoodId,
  6466. Number: info.Number,
  6467. LicenseNumber: info.LicenseNumber,
  6468. Count: delete_count,
  6469. UserOrgId: adminInfo.Org.Id,
  6470. PatientId: patient_id,
  6471. SystemTime: info.SysRecordTime,
  6472. ConsumableType: 7,
  6473. IsSys: 0,
  6474. WarehousingOrder: "",
  6475. WarehouseOutId: info.WarehouseOutId,
  6476. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6477. IsEdit: 0,
  6478. CancelStockId: cancel.ID,
  6479. CancelOrderNumber: cancel.OrderNumber,
  6480. Manufacturer: manufacturer.ID,
  6481. Dealer: 0,
  6482. Creator: adminInfo.AdminUser.Id,
  6483. UpdateCreator: 0,
  6484. Status: 1,
  6485. Ctime: time.Now().Unix(),
  6486. Mtime: 0,
  6487. Price: info.Price,
  6488. WarehousingDetailId: info.WarehouseInfotId,
  6489. WarehouseOutDetailId: info.ID,
  6490. CancelOutDetailId: cancelInfo.ID,
  6491. ProductDate: info.ProductDate,
  6492. ExpireDate: info.ExpiryDate,
  6493. StorehouseId: houseConfig.StorehouseOutInfo,
  6494. OverCount: over_count,
  6495. }
  6496. service.CreateStockFlowOne(flow)
  6497. }
  6498. }
  6499. //更改自动出库的表格
  6500. details := models.BloodAutomaticReduceDetail{
  6501. WarehouseOutId: warehouseOutInfo.ID,
  6502. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6503. PatientId: patient_id,
  6504. Ctime: time.Now().Unix(),
  6505. Mtime: time.Now().Unix(),
  6506. Status: 1,
  6507. RecordTime: record_time,
  6508. OrgId: adminInfo.Org.Id,
  6509. GoodId: item.GoodId,
  6510. GoodTypeId: item.GoodTypeId,
  6511. Count: item.Count,
  6512. StorehouseId: houseConfig.StorehouseOutInfo,
  6513. }
  6514. //查询当天耗材是否已经存在数据
  6515. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6516. if errcode == gorm.ErrRecordNotFound {
  6517. service.CreateAutoReduceRecord(&details)
  6518. } else if errcode == nil {
  6519. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6520. service.CreateAutoReduceRecord(&details)
  6521. }
  6522. //查询默认仓库
  6523. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6524. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6525. var total_count int64
  6526. for _, it := range stockList {
  6527. total_count += it.StockCount
  6528. }
  6529. //基础库插入数据
  6530. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6531. }
  6532. }
  6533. if len(outbefor) > 0 {
  6534. //出库
  6535. for _, item := range outbefor {
  6536. var last_total int64
  6537. //1.查看该患者该耗材型号最后一次出库数量
  6538. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6539. //计算当前出库和最后一次出库数据相差数据
  6540. last_total = item.Count - goodInfoOne.Count
  6541. //查询该耗材的总库存
  6542. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6543. // 如果库存差大于剩余库存则提示库存不足
  6544. if last_total > wareinfo.StockCount {
  6545. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6546. c.ServeSuccessJSON(map[string]interface{}{
  6547. "message": "1",
  6548. "good_name": goodObj.GoodName,
  6549. "specification_name": goodObj.SpecificationName,
  6550. })
  6551. return
  6552. } else {
  6553. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6554. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6555. if err == gorm.ErrRecordNotFound {
  6556. //没有记录,则创建出库单
  6557. timeStr := time.Now().Format("2006-01-02")
  6558. timeArr := strings.Split(timeStr, "-")
  6559. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6560. total = total + 1
  6561. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6562. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6563. number = number + total
  6564. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6565. warehouseOut := models.WarehouseOut{
  6566. WarehouseOutOrderNumber: warehousing_out_order,
  6567. OperationTime: time.Now().Unix(),
  6568. OrgId: adminInfo.Org.Id,
  6569. Creater: adminInfo.AdminUser.Id,
  6570. Ctime: time.Now().Unix(),
  6571. Status: 1,
  6572. WarehouseOutTime: record_time,
  6573. Dealer: 0,
  6574. Manufacturer: 0,
  6575. Type: 1,
  6576. IsSys: 1,
  6577. StorehouseId: houseConfig.StorehouseOutInfo,
  6578. IsCheck: 1,
  6579. }
  6580. service.AddSigleWarehouseOut(&warehouseOut)
  6581. }
  6582. //出库
  6583. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6584. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6585. //1.查看该患者该耗材型号最后一次出库数量
  6586. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6587. prepare := models.DialysisBeforePrepare{
  6588. UserOrgId: adminInfo.Org.Id,
  6589. PatientId: patient_id,
  6590. RecordDate: record_time,
  6591. GoodId: item.GoodId,
  6592. GoodTypeId: item.GoodTypeId,
  6593. Count: item.Count - goodInfoTwo.Count,
  6594. Ctime: time.Now().Unix(),
  6595. Mtime: 0,
  6596. Creater: adminInfo.AdminUser.Id,
  6597. Modifier: adminInfo.AdminUser.Id,
  6598. Status: 1,
  6599. CommdityCode: "",
  6600. NewCount: 0,
  6601. ProjectId: 0,
  6602. StorehouseId: houseConfig.StorehouseOutInfo,
  6603. }
  6604. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6605. //增加出库数量
  6606. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6607. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6608. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6609. var total_count int64
  6610. for _, it := range stockList {
  6611. total_count += it.StockCount
  6612. }
  6613. //基础库插入数据
  6614. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6615. //剩余库存
  6616. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6617. var flush_count int64
  6618. for _, it := range goodList {
  6619. flush_count += it.StockCount
  6620. }
  6621. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6622. }
  6623. }
  6624. }
  6625. //查询今日出库数据
  6626. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6627. for _, it := range list {
  6628. prepare := models.DialysisBeforePrepare{
  6629. UserOrgId: it.OrgId,
  6630. PatientId: patient_id,
  6631. RecordDate: it.RecordTime,
  6632. GoodId: it.GoodId,
  6633. GoodTypeId: it.GoodTypeId,
  6634. Count: it.Count,
  6635. Ctime: time.Now().Unix(),
  6636. Creater: adminInfo.AdminUser.Id,
  6637. Status: 1,
  6638. StorehouseId: houseConfig.StorehouseOutInfo,
  6639. ProjectId: it.ProjectId,
  6640. }
  6641. //删除准备表数据
  6642. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6643. service.CreateDialysisBeforePrepareOne(&prepare)
  6644. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6645. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6646. var total_count int64
  6647. for _, it := range stockList {
  6648. total_count += it.StockCount
  6649. }
  6650. //基础库插入数据
  6651. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6652. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6653. var flush_count int64
  6654. for _, it := range goodList {
  6655. flush_count += it.StockCount
  6656. }
  6657. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6658. }
  6659. }
  6660. }
  6661. //更新自动出库的地方
  6662. var errs error
  6663. if errs == nil {
  6664. c.ServeSuccessJSON(map[string]interface{}{
  6665. "msg": "修改成功",
  6666. "message": "2",
  6667. "good_name": "",
  6668. "specification_name": "",
  6669. })
  6670. return
  6671. } else {
  6672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6673. return
  6674. }
  6675. }
  6676. }
  6677. func (c *DialysisAPIController) GetDialysisGoods() {
  6678. schedualDate := c.GetString("schedule_date")
  6679. schedule_type, _ := c.GetInt64("schedule_type")
  6680. partition_id, _ := c.GetInt64("partition_id")
  6681. page, _ := c.GetInt("page")
  6682. patient_id, _ := c.GetInt64("patient_id")
  6683. schedualEndDate := int64(0)
  6684. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6685. if parseDateErr != nil && len(schedualDate) != 0 {
  6686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6687. return
  6688. }
  6689. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6690. if parseDateErr != nil && len(schedualDate) != 0 {
  6691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6692. return
  6693. }
  6694. schedualEndDate = endDate.Unix()
  6695. adminUser := c.GetMobileAdminUserInfo()
  6696. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6697. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6698. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6699. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6700. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6701. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6702. //获取当天该病人的透析处方
  6703. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6704. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6705. if err == gorm.ErrRecordNotFound {
  6706. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6707. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6708. if patient_id != 0 {
  6709. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6710. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6711. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6712. //获取患者总的出库数据
  6713. item.LastAutomaticReduceDetail = goodUser
  6714. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6715. item.Project = project
  6716. }
  6717. }
  6718. c.ServeSuccessJSON(map[string]interface{}{
  6719. "dialysis_goods": dialysisGoods,
  6720. "good_type": goodTypes,
  6721. "total": total,
  6722. "prescribe": prescribe,
  6723. "good_info": good_info,
  6724. "warehouseOutList": warehouseOutList,
  6725. "config": config,
  6726. "outConfig": outConfig,
  6727. "settleConfig": settleConfig,
  6728. })
  6729. return
  6730. } else if err == nil {
  6731. //获取当天排班的每个患者的库存使用情况
  6732. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6733. //获取患者总的出库数据
  6734. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6735. if patient_id != 0 {
  6736. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6737. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6738. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6739. item.Project = project
  6740. item.LastAutomaticReduceDetail = goodUser
  6741. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6742. }
  6743. }
  6744. if err == nil {
  6745. c.ServeSuccessJSON(map[string]interface{}{
  6746. "dialysis_goods": dialysisGoods,
  6747. "good_type": goodTypes,
  6748. "total": total,
  6749. "prescribe": prescribe,
  6750. "good_info": good_info,
  6751. "project": project,
  6752. "warehouseOutList": warehouseOutList,
  6753. "config": config,
  6754. "outConfig": outConfig,
  6755. "settleConfig": settleConfig,
  6756. })
  6757. return
  6758. } else {
  6759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6760. return
  6761. }
  6762. } else if err != nil {
  6763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6764. return
  6765. }
  6766. }
  6767. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6768. start_time := c.GetString("start_time")
  6769. end_time := c.GetString("end_time")
  6770. timeLayout := "2006-01-02"
  6771. loc, _ := time.LoadLocation("Local")
  6772. var theStartTime int64
  6773. if len(start_time) > 0 {
  6774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6775. if err != nil {
  6776. utils.ErrorLog(err.Error())
  6777. }
  6778. theStartTime = theTime.Unix()
  6779. }
  6780. var theEndtTime int64
  6781. if len(end_time) > 0 {
  6782. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6783. if err != nil {
  6784. utils.ErrorLog(err.Error())
  6785. }
  6786. theEndtTime = theTime.Unix()
  6787. }
  6788. adminUser := c.GetMobileAdminUserInfo()
  6789. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6790. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6791. if err == nil {
  6792. c.ServeSuccessJSON(map[string]interface{}{
  6793. "stock_out": outInfo,
  6794. "stockCount": stockCount,
  6795. })
  6796. return
  6797. } else {
  6798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6799. return
  6800. }
  6801. }
  6802. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6803. patient_id, _ := c.GetInt64("patient_id", 0)
  6804. record_time := c.GetString("record_time")
  6805. adminUser := c.GetMobileAdminUserInfo()
  6806. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6807. if parseDateErr != nil && len(record_time) != 0 {
  6808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6809. return
  6810. }
  6811. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6812. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6813. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6814. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6815. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6816. //获取今日患者的透析处方参数
  6817. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6818. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6819. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6820. c.ServeSuccessJSON(map[string]interface{}{
  6821. "good_type": goodTypes,
  6822. "good_user": goodUser,
  6823. "good_info": good_info,
  6824. "last_good_user": lastGoodUserDetial,
  6825. "project": project,
  6826. "prescription": prescribe,
  6827. "outInfo": outInfo,
  6828. "configs": configs,
  6829. })
  6830. return
  6831. }
  6832. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6833. patient_id, _ := c.GetInt64("patient_id", 0)
  6834. record_date := c.GetString("record_time")
  6835. timeLayout := "2006-01-02"
  6836. loc, _ := time.LoadLocation("Local")
  6837. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6838. record_time := theRecordTime.Unix()
  6839. adminInfo := c.GetMobileAdminUserInfo()
  6840. dataBody := make(map[string]interface{}, 0)
  6841. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6842. if err != nil {
  6843. utils.ErrorLog(err.Error())
  6844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6845. return
  6846. }
  6847. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6848. var beforePrepares []*models.DialysisBeforePrepareGoods
  6849. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6850. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6851. goods, _ := dataBody["goods"].([]interface{})
  6852. if len(goods) > 0 {
  6853. for _, item := range goods {
  6854. items := item.(map[string]interface{})
  6855. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6856. utils.ErrorLog("good_id")
  6857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6858. return
  6859. }
  6860. good_id := int64(items["good_id"].(float64))
  6861. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6862. utils.ErrorLog("good_type_id")
  6863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6864. return
  6865. }
  6866. good_type_id := int64(items["good_type_id"].(float64))
  6867. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6868. utils.ErrorLog("count")
  6869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6870. return
  6871. }
  6872. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6873. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6874. utils.ErrorLog("project_id")
  6875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6876. return
  6877. }
  6878. project_id := int64(items["project_id"].(float64))
  6879. new_count := int64(items["new_count"].(float64))
  6880. old_count := int64(items["old_count"].(float64))
  6881. prepare := &models.DialysisBeforePrepareGoods{
  6882. GoodId: good_id,
  6883. GoodTypeId: good_type_id,
  6884. Count: count,
  6885. ProjectId: project_id,
  6886. StorehouseId: houseConfig.StorehouseOutInfo,
  6887. NewCount: new_count,
  6888. OldCount: old_count,
  6889. }
  6890. beforePrepares = append(beforePrepares, prepare)
  6891. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6892. GoodId: good_id,
  6893. GoodTypeId: good_type_id,
  6894. Count: count,
  6895. ProjectId: project_id,
  6896. StorehouseId: houseConfig.StorehouseOutInfo,
  6897. NewCount: new_count,
  6898. OldCount: old_count,
  6899. }
  6900. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6901. }
  6902. }
  6903. }
  6904. //查询是否有库存
  6905. for _, item := range beforePrepares {
  6906. if item.NewCount > 0 {
  6907. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6908. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6909. if item.Count > warehouse.Count {
  6910. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6911. c.ServeSuccessJSON(map[string]interface{}{
  6912. "message": "1",
  6913. "good_name": goodObj.GoodName,
  6914. "specification_name": goodObj.SpecificationName,
  6915. })
  6916. return
  6917. }
  6918. }
  6919. }
  6920. // 查询信息规挡的设置天数
  6921. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6922. if infor.ID > 0 && infor.WeekDay > 0 {
  6923. var cha_time int64
  6924. timeNowStr := time.Now().Format("2006-01-02")
  6925. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6926. //今日的日期减去设置的日期
  6927. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6928. if cha_time >= record_time {
  6929. //查询审核是否允许
  6930. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6931. //申请状态不允许的情况 拒绝修改
  6932. if infor.ApplicationStatus != 1 {
  6933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6934. return
  6935. }
  6936. }
  6937. }
  6938. //出库逻辑
  6939. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6940. if err != nil {
  6941. utils.ErrorLog(err.Error())
  6942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6943. return
  6944. }
  6945. finish := models.XtDialysisFinish{
  6946. IsFinish: 1,
  6947. UserOrgId: adminInfo.Org.Id,
  6948. Status: 1,
  6949. Ctime: time.Now().Unix(),
  6950. Mtime: 0,
  6951. Module: 11,
  6952. RecordDate: record_time,
  6953. Sourse: 1,
  6954. PatientId: patient_id,
  6955. }
  6956. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6957. if dialysisFinish.ID == 0 {
  6958. service.CreateDialysisFinish(finish)
  6959. }
  6960. //查询当天出库的数据
  6961. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6962. for _, item := range list {
  6963. prepare := models.DialysisBeforePrepare{
  6964. UserOrgId: item.OrgId,
  6965. PatientId: item.PatientId,
  6966. RecordDate: item.RecordTime,
  6967. GoodId: item.GoodId,
  6968. GoodTypeId: item.GoodTypeId,
  6969. Count: item.Count,
  6970. Creater: adminInfo.AdminUser.Id,
  6971. Status: 1,
  6972. Ctime: time.Now().Unix(),
  6973. ProjectId: item.ProjectId,
  6974. StorehouseId: houseConfig.StorehouseOutInfo,
  6975. }
  6976. //清空准备表的数据
  6977. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6978. //插入准备表数据
  6979. service.CreateDialysisBeforePrepareOne(&prepare)
  6980. //查询默认仓库
  6981. //查询默认仓库
  6982. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6983. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6984. var total_count int64
  6985. for _, it := range stockList {
  6986. total_count += it.StockCount
  6987. }
  6988. //基础库插入数据
  6989. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6990. ////更新剩余库存
  6991. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6992. var flush_count int64
  6993. for _, it := range goodList {
  6994. flush_count += it.StockCount
  6995. }
  6996. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6997. if errs != nil {
  6998. goodErrcode := models.XtGoodErrcode{
  6999. UserOrgId: item.OrgId,
  7000. Errcode: "手动出库更新剩余出库失败",
  7001. GoodId: item.GoodId,
  7002. Status: 1,
  7003. Ctime: time.Now().Unix(),
  7004. Mtime: 0,
  7005. Count: 0,
  7006. StockCount: 0,
  7007. Creater: adminInfo.AdminUser.Id,
  7008. BatchNumberId: 0,
  7009. WarehouseOutId: 0,
  7010. }
  7011. service.CreateGoodErrcode(goodErrcode)
  7012. }
  7013. }
  7014. //更新自动出库的地方
  7015. var errs error
  7016. if errs == nil {
  7017. c.ServeSuccessJSON(map[string]interface{}{
  7018. "msg": "修改成功",
  7019. "message": "2",
  7020. "good_name": "",
  7021. "specification_name": "",
  7022. })
  7023. return
  7024. } else {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7026. return
  7027. }
  7028. }
  7029. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7030. newArr = make([]*models.DialysisBeforePrepare, 0)
  7031. for i := 0; i < len(arr); i++ {
  7032. repeat := false
  7033. for j := i + 1; j < len(arr); j++ {
  7034. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7035. repeat = true
  7036. break
  7037. }
  7038. }
  7039. if !repeat {
  7040. newArr = append(newArr, arr[i])
  7041. }
  7042. }
  7043. return
  7044. }
  7045. func (c *DialysisAPIController) GetAllDrug() {
  7046. patient_id, _ := c.GetInt64("patient_id", 0)
  7047. adminInfo := c.GetMobileAdminUserInfo()
  7048. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7049. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7050. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7051. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7052. c.ServeSuccessJSON(map[string]interface{}{
  7053. "base_drug_config": drugStockConfig,
  7054. "private_drug_config": privateDrugConfig,
  7055. "base_drug_list": drugList,
  7056. "private_drug_list": privateDrugList,
  7057. })
  7058. }
  7059. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7060. newArr = make([]*models.DialysisBeforePrepare, 0)
  7061. for i := 0; i < len(arr); i++ {
  7062. repeat := false
  7063. for j := i + 1; j < len(arr); j++ {
  7064. if arr[i].GoodId == arr[j].GoodId {
  7065. repeat = true
  7066. break
  7067. }
  7068. }
  7069. if !repeat {
  7070. newArr = append(newArr, arr[i])
  7071. }
  7072. }
  7073. return
  7074. }
  7075. func (c *DialysisAPIController) GetDepartment() {
  7076. adminInfo := c.GetMobileAdminUserInfo()
  7077. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7078. if err == nil {
  7079. c.ServeSuccessJSON(map[string]interface{}{
  7080. "departments": departments,
  7081. })
  7082. } else {
  7083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7084. return
  7085. }
  7086. }
  7087. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7088. types, _ := c.GetInt("type", 0)
  7089. start_time := c.GetString("start_time")
  7090. end_time := c.GetString("end_time")
  7091. orgId := c.GetMobileAdminUserInfo().Org.Id
  7092. timeLayout := "2006-01-02"
  7093. loc, _ := time.LoadLocation("Local")
  7094. var startTime int64
  7095. if len(start_time) > 0 {
  7096. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7097. if err != nil {
  7098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7099. return
  7100. }
  7101. startTime = theTime.Unix()
  7102. }
  7103. var endTime int64
  7104. if len(end_time) > 0 {
  7105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7106. if err != nil {
  7107. utils.ErrorLog(err.Error())
  7108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7109. return
  7110. }
  7111. endTime = theTime.Unix()
  7112. }
  7113. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7114. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7115. if err != nil {
  7116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7117. } else {
  7118. c.ServeSuccessJSON(map[string]interface{}{
  7119. "list": list,
  7120. "type": types,
  7121. "stockTotal": stockTotal,
  7122. })
  7123. }
  7124. }
  7125. func (c *DialysisAPIController) GetPrescriptionList() {
  7126. start_time := c.GetString("start_time")
  7127. end_time := c.GetString("end_time")
  7128. schedule_type, _ := c.GetInt64("schedule_type")
  7129. partion_id, _ := c.GetInt64("partion_id")
  7130. orgId := c.GetMobileAdminUserInfo().Org.Id
  7131. timeLayout := "2006-01-02"
  7132. loc, _ := time.LoadLocation("Local")
  7133. var startTime int64
  7134. if len(start_time) > 0 {
  7135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7136. if err != nil {
  7137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7138. return
  7139. }
  7140. startTime = theTime.Unix()
  7141. }
  7142. var endTime int64
  7143. if len(end_time) > 0 {
  7144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7145. if err != nil {
  7146. utils.ErrorLog(err.Error())
  7147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7148. return
  7149. }
  7150. endTime = theTime.Unix()
  7151. }
  7152. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7153. fmt.Println("schedulelist22222222", schedulelist)
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "list": schedulelist,
  7156. })
  7157. return
  7158. }
  7159. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7160. ids := c.GetString("ids")
  7161. //patient_id, _ := c.GetInt64("patient_id")
  7162. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7163. idArray := strings.Split(ids, ",")
  7164. err := service.BatchDeleteMonitor(idArray)
  7165. fmt.Print("err", err)
  7166. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7167. //redis := service.RedisClient()
  7168. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7169. //redis.Set(key, "", time.Second)
  7170. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7171. //redis.Set(keyOne, "", time.Second)
  7172. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7173. //redis.Close()
  7174. c.ServeSuccessJSON(map[string]interface{}{
  7175. "msg": "批量删除成功",
  7176. })
  7177. return
  7178. }
  7179. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7180. id, _ := c.GetInt64("id")
  7181. timeLayout := "2006-01-02"
  7182. loc, _ := time.LoadLocation("Local")
  7183. //start_time := time.Now().Format("2006-01-02")
  7184. start_time := c.GetString("start_time")
  7185. end_time := c.GetString("end_time")
  7186. var startdateunix int64
  7187. if len(start_time) > 0 {
  7188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7189. if err != nil {
  7190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7191. return
  7192. }
  7193. startdateunix = theTime.Unix()
  7194. }
  7195. var enddateunix int64
  7196. if len(end_time) > 0 {
  7197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7198. if err != nil {
  7199. utils.ErrorLog(err.Error())
  7200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7201. return
  7202. }
  7203. enddateunix = theTime.Unix()
  7204. }
  7205. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7206. //nowTime := time.Now()
  7207. //endTime := nowTime.AddDate(-30, 0, 0)
  7208. //endTimes := endTime.Format("2006-01-02")
  7209. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7210. org_id := c.GetMobileAdminUserInfo().Org.Id
  7211. //if org_id == 10579 {
  7212. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7213. // c.ServeSuccessJSON(map[string]interface{}{
  7214. // "list": list,
  7215. // })
  7216. // return
  7217. //} else {
  7218. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7219. // c.ServeSuccessJSON(map[string]interface{}{
  7220. // "list": list,
  7221. // })
  7222. // return
  7223. //}
  7224. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7225. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7226. c.ServeSuccessJSON(map[string]interface{}{
  7227. "list": list,
  7228. })
  7229. return
  7230. } else {
  7231. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7232. c.ServeSuccessJSON(map[string]interface{}{
  7233. "list": list,
  7234. })
  7235. }
  7236. return
  7237. }
  7238. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7239. dataBody := make(map[string]interface{}, 0)
  7240. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7241. ids := c.GetString("ids")
  7242. idArray := strings.Split(ids, ",")
  7243. origin, _ := c.GetInt64("origin")
  7244. if origin == 1 {
  7245. err = service.BatchDeleteAdvice(idArray)
  7246. fmt.Print("err", err)
  7247. c.ServeSuccessJSON(map[string]interface{}{
  7248. "msg": "批量删除成功",
  7249. })
  7250. return
  7251. }
  7252. if origin == 2 {
  7253. service.BatchDeleteHisAdvice(idArray)
  7254. }
  7255. }
  7256. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7257. good_id, _ := c.GetInt64("good_id")
  7258. count, _ := c.GetInt64("count")
  7259. record_time, _ := c.GetInt64("record_time")
  7260. patient_id, _ := c.GetInt64("patient_id")
  7261. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "detail": detail,
  7264. })
  7265. return
  7266. }
  7267. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7268. good_id, _ := c.GetInt64("good_id")
  7269. record_time, _ := c.GetInt64("record_time")
  7270. patient_id, _ := c.GetInt64("patient_id")
  7271. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7272. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7273. fmt.Print("err", err)
  7274. c.ServeSuccessJSON(map[string]interface{}{
  7275. "msg": "批量删除成功",
  7276. })
  7277. return
  7278. }
  7279. func (c *DialysisAPIController) BatchAdviceCheck() {
  7280. ids := c.GetString("ids")
  7281. idArray := strings.Split(ids, ",")
  7282. creator, _ := c.GetInt64("creator")
  7283. origin, _ := c.GetInt64("origin")
  7284. if origin == 1 {
  7285. err := service.BatchAdviceCheck(idArray, creator)
  7286. fmt.Println(err)
  7287. list, _ := service.GetAdviceExecutionById(idArray)
  7288. c.ServeSuccessJSON(map[string]interface{}{
  7289. "list": list,
  7290. })
  7291. return
  7292. }
  7293. if origin == 2 {
  7294. service.BatchHisAdviceCheck(idArray, creator)
  7295. list, _ := service.GetHisAdviceExecutionById(idArray)
  7296. c.ServeSuccessJSON(map[string]interface{}{
  7297. "list": list,
  7298. })
  7299. return
  7300. }
  7301. }
  7302. func (c *DialysisAPIController) BatchAdviceExecution() {
  7303. ids := c.GetString("ids")
  7304. idArray := strings.Split(ids, ",")
  7305. executionTime := c.GetString("execution_time")
  7306. creator, _ := c.GetInt64("creator")
  7307. timeLayout := "2006-01-02 15:04:05"
  7308. loc, _ := time.LoadLocation("Local")
  7309. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7310. orgin, _ := c.GetInt64("origin")
  7311. if orgin == 1 {
  7312. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7313. list, _ := service.GetAdviceExecutionById(idArray)
  7314. fmt.Println(err)
  7315. c.ServeSuccessJSON(map[string]interface{}{
  7316. "list": list,
  7317. })
  7318. return
  7319. }
  7320. if orgin == 2 {
  7321. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7322. list, _ := service.GetHisAdviceExecutionById(idArray)
  7323. fmt.Println(err)
  7324. c.ServeSuccessJSON(map[string]interface{}{
  7325. "list": list,
  7326. })
  7327. return
  7328. }
  7329. }
  7330. func (c *DialysisAPIController) UpdateStockGoods() {
  7331. good_id, _ := c.GetInt64("good_id")
  7332. record_time, _ := c.GetInt64("record_time")
  7333. patient_id, _ := c.GetInt64("patient_id")
  7334. count, _ := c.GetInt64("count")
  7335. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7336. fmt.Print("err", err)
  7337. c.ServeSuccessJSON(map[string]interface{}{
  7338. "msg": "更新成功",
  7339. })
  7340. return
  7341. }
  7342. // 当前数据比上一次出库数据少
  7343. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7344. //查询该患者当天已经出库的耗材信息
  7345. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7346. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7347. for i := len(goods_yc) - 1; i >= 0; i-- {
  7348. goods_yc_temp := goods_yc[i]
  7349. for j := len(goods) - 1; j >= 0; j-- {
  7350. goods_temp := goods[j]
  7351. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7352. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7353. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7354. if goods_yc_temp.Count == goods_temp.Count {
  7355. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7356. goods = append(goods[:j], goods[j+1:]...)
  7357. break
  7358. }
  7359. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7360. if goods_yc_temp.Count > goods_temp.Count {
  7361. temp_count := goods_yc_temp.Count - goods_temp.Count
  7362. goods_yc[i].Count = temp_count
  7363. goods = append(goods[:j], goods[j+1:]...)
  7364. break
  7365. }
  7366. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7367. if goods_yc_temp.Count < goods_temp.Count {
  7368. temp_count := goods_temp.Count - goods_yc_temp.Count
  7369. goods[j].Count = temp_count
  7370. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7371. break
  7372. }
  7373. }
  7374. }
  7375. }
  7376. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7377. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7378. //退库
  7379. if len(goods_yc) > 0 {
  7380. for _, good_yc := range goods_yc {
  7381. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7382. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7383. }
  7384. }
  7385. return nil
  7386. }
  7387. // 耗材出库删除
  7388. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7389. // 先根据相关信息查询当天该耗材的出库信息
  7390. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7391. if err != nil {
  7392. return err
  7393. }
  7394. var delete_count int64 = 0
  7395. delete_count = warehouseOutInfos.Count - count
  7396. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7397. // 在出库记录表里记录退库详情
  7398. warehouseOutInfo := &models.WarehouseOutInfo{
  7399. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7400. WarehouseOutId: warehouseOut.ID,
  7401. Status: 1,
  7402. Ctime: time.Now().Unix(),
  7403. OrgId: orgID,
  7404. Type: 1,
  7405. IsSys: 1,
  7406. SysRecordTime: record_time,
  7407. GoodTypeId: good_yc.GoodTypeId,
  7408. GoodId: good_yc.GoodId,
  7409. PatientId: good_yc.PatientId,
  7410. ConsumableType: 2,
  7411. StorehouseId: houseConfig.StorehouseOutInfo,
  7412. IsCheck: 1,
  7413. }
  7414. warehouseOutInfo.Count = count
  7415. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7416. warehouseOutInfo.Price = stockInInfo.Price
  7417. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7418. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7419. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7420. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7421. warehouseOutInfo.Number = warehouseOutInfos.Number
  7422. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7423. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7424. //查找当天是否存在出库记录
  7425. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7426. if errcod == gorm.ErrRecordNotFound {
  7427. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7428. //插入详情明细表
  7429. stockFlow := models.VmStockFlow{
  7430. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7431. WarehouseOutId: warehouseOut.ID,
  7432. GoodId: good_yc.GoodId,
  7433. Number: warehouseOutInfos.Number,
  7434. ProductDate: stockInInfo.ProductDate,
  7435. ExpireDate: stockInInfo.ExpiryDate,
  7436. Count: count,
  7437. Price: stockInInfo.Price,
  7438. Status: 1,
  7439. Ctime: time.Now().Unix(),
  7440. UserOrgId: good_yc.OrgId,
  7441. Manufacturer: stockInInfo.Manufacturer,
  7442. Dealer: stockInInfo.Dealer,
  7443. LicenseNumber: stockInInfo.LicenseNumber,
  7444. IsEdit: 2,
  7445. Creator: creater,
  7446. SystemTime: record_time,
  7447. ConsumableType: 3,
  7448. WarehousingDetailId: 0,
  7449. IsSys: 1,
  7450. UpdateCreator: creater,
  7451. PatientId: patient_id,
  7452. StorehouseId: houseConfig.StorehouseOutInfo,
  7453. }
  7454. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7455. if errflow == gorm.ErrRecordNotFound {
  7456. //创建流水表
  7457. err := service.CreateStockFlowOne(stockFlow)
  7458. fmt.Println("err", err)
  7459. } else if errflow == nil {
  7460. //插入详情明细表
  7461. stockFlow := models.VmStockFlow{
  7462. ID: exsit.ID,
  7463. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7464. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7465. WarehouseOutId: warehouseOut.ID,
  7466. GoodId: good_yc.GoodId,
  7467. Number: warehouseOutInfos.Number,
  7468. ProductDate: stockInInfo.ProductDate,
  7469. ExpireDate: stockInInfo.ExpiryDate,
  7470. Count: exsit.Count - delete_count,
  7471. Price: stockInInfo.Price,
  7472. Status: 1,
  7473. Ctime: time.Now().Unix(),
  7474. UserOrgId: good_yc.OrgId,
  7475. Manufacturer: stockInInfo.Manufacturer,
  7476. Dealer: stockInInfo.Dealer,
  7477. LicenseNumber: stockInInfo.LicenseNumber,
  7478. IsEdit: 2,
  7479. Creator: creater,
  7480. SystemTime: record_time,
  7481. ConsumableType: 3,
  7482. WarehousingDetailId: 0,
  7483. IsSys: 1,
  7484. UpdateCreator: creater,
  7485. PatientId: patient_id,
  7486. StorehouseId: houseConfig.StorehouseOutInfo,
  7487. }
  7488. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7489. }
  7490. if errOne != nil {
  7491. return errOne
  7492. }
  7493. } else if errcod == nil {
  7494. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7495. //插入详情明细表
  7496. stockFlow := models.VmStockFlow{
  7497. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7498. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7499. WarehouseOutId: warehouseOut.ID,
  7500. GoodId: good_yc.GoodId,
  7501. Number: warehouseOutInfos.Number,
  7502. ProductDate: stockInInfo.ProductDate,
  7503. ExpireDate: stockInInfo.ExpiryDate,
  7504. Count: count,
  7505. Price: stockInInfo.Price,
  7506. Status: 1,
  7507. Ctime: time.Now().Unix(),
  7508. UserOrgId: good_yc.OrgId,
  7509. Manufacturer: stockInInfo.Manufacturer,
  7510. Dealer: stockInInfo.Dealer,
  7511. LicenseNumber: stockInInfo.LicenseNumber,
  7512. IsEdit: 2,
  7513. Creator: creater,
  7514. SystemTime: record_time,
  7515. ConsumableType: 3,
  7516. WarehousingDetailId: 0,
  7517. IsSys: 1,
  7518. UpdateCreator: creater,
  7519. PatientId: patient_id,
  7520. ReturnCount: delete_count,
  7521. StorehouseId: houseConfig.StorehouseOutInfo,
  7522. }
  7523. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7524. if errflows == gorm.ErrRecordNotFound {
  7525. //创建流水表
  7526. service.CreateStockFlowOne(stockFlow)
  7527. } else if errflows == nil {
  7528. stockFlow := models.VmStockFlow{
  7529. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7530. ID: exsit.ID,
  7531. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7532. WarehouseOutId: warehouseOut.ID,
  7533. GoodId: good_yc.GoodId,
  7534. Number: warehouseOutInfos.Number,
  7535. ProductDate: stockInInfo.ProductDate,
  7536. ExpireDate: stockInInfo.ExpiryDate,
  7537. Count: exsit.Count - delete_count,
  7538. Price: stockInInfo.Price,
  7539. Status: 1,
  7540. Ctime: time.Now().Unix(),
  7541. UserOrgId: good_yc.OrgId,
  7542. Manufacturer: stockInInfo.Manufacturer,
  7543. Dealer: stockInInfo.Dealer,
  7544. LicenseNumber: stockInInfo.LicenseNumber,
  7545. IsEdit: 2,
  7546. Creator: creater,
  7547. SystemTime: record_time,
  7548. ConsumableType: 3,
  7549. WarehousingDetailId: 0,
  7550. IsSys: 1,
  7551. UpdateCreator: creater,
  7552. PatientId: patient_id,
  7553. ReturnCount: delete_count,
  7554. StorehouseId: houseConfig.StorehouseOutInfo,
  7555. }
  7556. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7557. }
  7558. }
  7559. //更改自动出库的表格
  7560. details := models.BloodAutomaticReduceDetail{
  7561. WarehouseOutId: warehouseOutInfo.ID,
  7562. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7563. PatientId: patient_id,
  7564. Ctime: time.Now().Unix(),
  7565. Mtime: time.Now().Unix(),
  7566. Status: 1,
  7567. RecordTime: record_time,
  7568. OrgId: orgID,
  7569. GoodId: good_yc.GoodId,
  7570. GoodTypeId: good_yc.GoodTypeId,
  7571. Count: count,
  7572. StorehouseId: houseConfig.StorehouseOutInfo,
  7573. }
  7574. //查询当天耗材是否已经存在数据
  7575. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7576. if errcode == gorm.ErrRecordNotFound {
  7577. errTwo := service.CreateAutoReduceRecord(&details)
  7578. if errTwo != nil {
  7579. return errTwo
  7580. }
  7581. } else if errcode == nil {
  7582. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7583. service.CreateAutoReduceRecord(&details)
  7584. }
  7585. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7586. //增加出库库存数量
  7587. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7588. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7589. fmt.Println("errOne", errOne)
  7590. // 删除出库完成后,要增加对应批次的库存数量
  7591. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7592. if errThree != nil {
  7593. return errThree
  7594. }
  7595. if good_yc.Count == 0 {
  7596. return nil
  7597. } else {
  7598. return errors.New("退库和出库数据不匹配")
  7599. }
  7600. }
  7601. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7602. //查询该患者当天已经出库的耗材信息
  7603. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7604. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7605. for i := len(goods_yc) - 1; i >= 0; i-- {
  7606. goods_yc_temp := goods_yc[i]
  7607. for j := len(goods) - 1; j >= 0; j-- {
  7608. goods_temp := goods[j]
  7609. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7610. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7611. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7612. if goods_yc_temp.Count == goods_temp.Count {
  7613. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7614. goods = append(goods[:j], goods[j+1:]...)
  7615. break
  7616. }
  7617. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7618. if goods_yc_temp.Count > goods_temp.Count {
  7619. temp_count := goods_yc_temp.Count - goods_temp.Count
  7620. goods_yc[i].Count = temp_count
  7621. goods = append(goods[:j], goods[j+1:]...)
  7622. break
  7623. }
  7624. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7625. if goods_yc_temp.Count < goods_temp.Count {
  7626. temp_count := goods_temp.Count - goods_yc_temp.Count
  7627. goods[j].Count = temp_count
  7628. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7629. break
  7630. }
  7631. }
  7632. }
  7633. }
  7634. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7635. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7636. fmt.Println("剩余需要出库的", len(goods))
  7637. if len(goods) > 0 {
  7638. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7639. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7640. if err == gorm.ErrRecordNotFound {
  7641. //没有记录,则创建出库单
  7642. timeStr := time.Now().Format("2006-01-02")
  7643. timeArr := strings.Split(timeStr, "-")
  7644. total, _ := service.FindAllWarehouseOut(orgID)
  7645. total = total + 1
  7646. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7647. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7648. number = number + total
  7649. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7650. warehouseOut := models.WarehouseOut{
  7651. WarehouseOutOrderNumber: warehousing_out_order,
  7652. OperationTime: time.Now().Unix(),
  7653. OrgId: orgID,
  7654. Creater: creater,
  7655. Ctime: time.Now().Unix(),
  7656. Status: 1,
  7657. WarehouseOutTime: record_time,
  7658. Dealer: 0,
  7659. Manufacturer: 0,
  7660. Type: 1,
  7661. IsSys: 1,
  7662. StorehouseId: houseConfig.StorehouseOutInfo,
  7663. IsCheck: 1,
  7664. }
  7665. err := service.AddSigleWarehouseOut(&warehouseOut)
  7666. if err != nil {
  7667. utils.TraceLog("创建出库单失败 err = %v", err)
  7668. return err
  7669. } else {
  7670. out = warehouseOut
  7671. }
  7672. }
  7673. for _, item := range goods {
  7674. var newCount int64 = 0
  7675. for _, it := range goodOne {
  7676. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7677. newCount = it.Count
  7678. }
  7679. }
  7680. prepare := models.DialysisBeforePrepare{
  7681. GoodTypeId: item.GoodTypeId,
  7682. GoodId: item.GoodId,
  7683. Count: item.Count,
  7684. StorehouseId: houseConfig.StorehouseOutInfo,
  7685. }
  7686. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7687. //增加出库数量
  7688. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7689. }
  7690. }
  7691. if len(goods_yc) > 0 {
  7692. for _, good_yc := range goods_yc {
  7693. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7694. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7695. }
  7696. }
  7697. return nil
  7698. }
  7699. // 耗材出库删除
  7700. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7701. // 先根据相关信息查询当天该耗材的出库信息
  7702. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7703. if err != nil {
  7704. return err
  7705. }
  7706. var delete_count int64 = 0
  7707. for _, ware := range warehouseOutInfos {
  7708. // 判断当前出库的数据和删除出库数量
  7709. if good_yc.Count <= ware.Count {
  7710. delete_count = good_yc.Count
  7711. } else {
  7712. delete_count = ware.Count
  7713. }
  7714. warehouseOutInfo := &models.WarehouseOutInfo{
  7715. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7716. WarehouseOutId: warehouseOut.ID,
  7717. Status: 1,
  7718. Ctime: time.Now().Unix(),
  7719. Remark: "",
  7720. OrgId: orgID,
  7721. Type: 1,
  7722. Manufacturer: 0,
  7723. Dealer: 0,
  7724. IsSys: 0,
  7725. SysRecordTime: record_time,
  7726. GoodTypeId: good_yc.GoodTypeId,
  7727. GoodId: good_yc.GoodId,
  7728. StorehouseId: warehouseOut.StorehouseId,
  7729. IsCheck: 1,
  7730. }
  7731. warehouseOutInfo.Count = delete_count
  7732. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7733. warehouseOutInfo.Price = stockInInfo.Price
  7734. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7735. if errOne != nil {
  7736. return errOne
  7737. }
  7738. // 删除出库完成后,要改变流水库存(有疑问)
  7739. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7740. fmt.Println("errOne", errOne)
  7741. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7742. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7743. //扣减出库数量
  7744. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7745. if errThree != nil {
  7746. return errThree
  7747. }
  7748. }
  7749. if good_yc.Count == 0 {
  7750. return nil
  7751. } else {
  7752. return errors.New("退库和出库数据不匹配")
  7753. }
  7754. }
  7755. func (this *DialysisAPIController) GetMobileScheduleList() {
  7756. limit, _ := this.GetInt64("limit")
  7757. page, _ := this.GetInt64("page")
  7758. type_options_visible, _ := this.GetInt64("type_options_visible")
  7759. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7760. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7761. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7762. }
  7763. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7764. newArr = make([]*models.HisPrescriptionProject, 0)
  7765. for i := 0; i < len(arr); i++ {
  7766. repeat := false
  7767. for j := i + 1; j < len(arr); j++ {
  7768. if arr[i].TeamId == arr[j].TeamId {
  7769. repeat = true
  7770. break
  7771. }
  7772. }
  7773. if !repeat {
  7774. newArr = append(newArr, arr[i])
  7775. }
  7776. }
  7777. return
  7778. }
  7779. func (this *DialysisAPIController) GetRoleList() {
  7780. admin_user_id, _ := this.GetInt64("admin_user_id")
  7781. orgid := this.GetMobileAdminUserInfo().Org.Id
  7782. list, err := service.GetRoleList(orgid, admin_user_id)
  7783. fmt.Println(err)
  7784. this.ServeSuccessJSON(map[string]interface{}{
  7785. "list": list,
  7786. })
  7787. return
  7788. }
  7789. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7790. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7791. // 先根据相关信息查询当天该耗材的出库信息
  7792. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7793. if err != nil {
  7794. return err
  7795. }
  7796. var delete_count int64 = 0
  7797. delete_count = warehouseOutInfos.Count - count
  7798. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7799. // 删除出库完成后,要增加对应批次的库存数量
  7800. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7801. if errThree != nil {
  7802. return errThree
  7803. }
  7804. //增加退库数量
  7805. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7806. //扣减出库数量
  7807. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7808. //查询剩余库存
  7809. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7810. var sum_count int64
  7811. for _, item := range goodList {
  7812. sum_count += item.StockCount
  7813. }
  7814. // 在出库记录表里记录退库详情
  7815. warehouseOutInfo := &models.WarehouseOutInfo{
  7816. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7817. WarehouseOutId: warehouseOut.ID,
  7818. Status: 1,
  7819. Ctime: time.Now().Unix(),
  7820. OrgId: orgID,
  7821. Type: 1,
  7822. IsSys: 1,
  7823. SysRecordTime: record_time,
  7824. GoodTypeId: good_yc.GoodTypeId,
  7825. GoodId: good_yc.GoodId,
  7826. PatientId: good_yc.PatientId,
  7827. ConsumableType: 2,
  7828. StorehouseId: houseConfig.StorehouseOutInfo,
  7829. IsCheck: 1,
  7830. OverCount: sum_count,
  7831. }
  7832. warehouseOutInfo.Count = count
  7833. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7834. warehouseOutInfo.Price = stockInInfo.Price
  7835. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7836. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7837. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7838. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7839. warehouseOutInfo.Number = warehouseOutInfos.Number
  7840. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7841. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7842. //查找当天是否存在出库记录
  7843. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7844. if errcod == gorm.ErrRecordNotFound {
  7845. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7846. //插入详情明细表
  7847. if errOne != nil {
  7848. return errOne
  7849. }
  7850. //插入详情明细表
  7851. stockFlow := models.VmStockFlow{
  7852. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7853. WarehouseOutId: warehouseOut.ID,
  7854. GoodId: good_yc.GoodId,
  7855. Number: warehouseOutInfos.Number,
  7856. ProductDate: stockInInfo.ProductDate,
  7857. ExpireDate: stockInInfo.ExpiryDate,
  7858. Count: count,
  7859. Price: stockInInfo.Price,
  7860. Status: 1,
  7861. Ctime: time.Now().Unix(),
  7862. UserOrgId: good_yc.OrgId,
  7863. Manufacturer: stockInInfo.Manufacturer,
  7864. Dealer: stockInInfo.Dealer,
  7865. LicenseNumber: stockInInfo.LicenseNumber,
  7866. IsEdit: 2,
  7867. Creator: creater,
  7868. SystemTime: record_time,
  7869. ConsumableType: 3,
  7870. WarehousingDetailId: 0,
  7871. IsSys: 1,
  7872. UpdateCreator: creater,
  7873. PatientId: patient_id,
  7874. StorehouseId: houseConfig.StorehouseOutInfo,
  7875. OverCount: sum_count,
  7876. ProjectId: good_yc.ProjectId,
  7877. }
  7878. err := service.CreateStockFlowOne(stockFlow)
  7879. fmt.Println("err", err)
  7880. } else if errcod == nil {
  7881. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7882. }
  7883. //创建退库单
  7884. operation_time := time.Now().Unix()
  7885. //创建退库单
  7886. timeStr := time.Now().Format("2006-01-02")
  7887. timeArr := strings.Split(timeStr, "-")
  7888. total, _ := service.FindAllCancelStockTotal(orgID)
  7889. total = total + 1
  7890. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7891. cancelStock := models.CancelStock{
  7892. OrderNumber: orderNumber,
  7893. OperaTime: operation_time,
  7894. OrgId: orgID,
  7895. Creater: warehouseOut.Creater,
  7896. Ctime: time.Now().Unix(),
  7897. Status: 1,
  7898. ReturnTime: record_time,
  7899. Type: 1,
  7900. StorehouseId: stockInInfo.StorehouseId,
  7901. IsCheck: 1,
  7902. }
  7903. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7904. if msgerrkonde == gorm.ErrRecordNotFound {
  7905. service.AddSigleCancelStock(&cancelStock)
  7906. }
  7907. cancel, _ := service.GetLastCancelStockById(orgID)
  7908. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7909. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7910. cancelStockInfo := models.CancelStockInfo{
  7911. GoodId: stockInInfo.GoodId,
  7912. CancelStockId: cancel.ID,
  7913. GoodTypeId: stockInInfo.GoodTypeId,
  7914. Count: delete_count,
  7915. Price: stockInInfo.PackingPrice,
  7916. Total: 0,
  7917. ProductDate: stockInInfo.ProductDate,
  7918. ExpiryDate: stockInInfo.ExpiryDate,
  7919. Ctime: time.Now().Unix(),
  7920. Status: 1,
  7921. OrgId: orgID,
  7922. OrderNumber: cancel.OrderNumber,
  7923. Type: 0,
  7924. Dealer: deaerler.DealerName,
  7925. Manufacturer: manufacturer.ManufacturerName,
  7926. Number: stockInInfo.Number,
  7927. RegisterAccount: "",
  7928. Remark: "",
  7929. WarehouseInfoId: stockInInfo.ID,
  7930. PatientId: patient_id,
  7931. RecordDate: record_time,
  7932. StorehouseId: stockInInfo.StorehouseId,
  7933. IsCheck: 1,
  7934. }
  7935. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7936. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7937. flow := models.VmStockFlow{
  7938. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7939. GoodId: good_yc.GoodId,
  7940. Number: warehouseOutInfos.Number,
  7941. LicenseNumber: stockInInfo.LicenseNumber,
  7942. Count: delete_count,
  7943. UserOrgId: orgID,
  7944. PatientId: patient_id,
  7945. SystemTime: record_time,
  7946. ConsumableType: 7,
  7947. IsSys: 0,
  7948. WarehousingOrder: "",
  7949. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7950. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7951. IsEdit: 0,
  7952. CancelStockId: cancel.ID,
  7953. CancelOrderNumber: cancel.OrderNumber,
  7954. Manufacturer: manufacturer.ID,
  7955. Dealer: 0,
  7956. Creator: warehouseOut.Creater,
  7957. UpdateCreator: 0,
  7958. Status: 1,
  7959. Ctime: time.Now().Unix(),
  7960. Mtime: 0,
  7961. Price: stockInInfo.Price,
  7962. WarehousingDetailId: stockInInfo.ID,
  7963. WarehouseOutDetailId: warehouseOutInfos.ID,
  7964. CancelOutDetailId: cancelInfo.ID,
  7965. ProductDate: stockInInfo.ProductDate,
  7966. ExpireDate: stockInInfo.ExpiryDate,
  7967. StorehouseId: houseConfig.StorehouseOutInfo,
  7968. OverCount: sum_count,
  7969. }
  7970. service.CreateStockFlowOne(flow)
  7971. //更改自动出库的表格
  7972. details := models.BloodAutomaticReduceDetail{
  7973. WarehouseOutId: warehouseOutInfo.ID,
  7974. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7975. PatientId: patient_id,
  7976. Ctime: time.Now().Unix(),
  7977. Mtime: time.Now().Unix(),
  7978. Status: 1,
  7979. RecordTime: record_time,
  7980. OrgId: orgID,
  7981. GoodId: good_yc.GoodId,
  7982. GoodTypeId: good_yc.GoodTypeId,
  7983. Count: count,
  7984. StorehouseId: houseConfig.StorehouseOutInfo,
  7985. }
  7986. //查询当天耗材是否已经存在数据
  7987. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7988. if errcode == gorm.ErrRecordNotFound {
  7989. errTwo := service.CreateAutoReduceRecord(&details)
  7990. if errTwo != nil {
  7991. return errTwo
  7992. }
  7993. } else if errcode == nil {
  7994. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7995. service.CreateAutoReduceRecord(&details)
  7996. }
  7997. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7998. //增加出库库存数量
  7999. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8000. if good_yc.Count == 0 {
  8001. return nil
  8002. } else {
  8003. return errors.New("退库和出库数据不匹配")
  8004. }
  8005. }
  8006. func (this *DialysisAPIController) SavePatientSign() {
  8007. adminUserInfo := this.GetMobileAdminUserInfo()
  8008. patient_id, _ := this.GetInt64("patient_id")
  8009. dialysis_date, _ := this.GetInt64("dialysis_date")
  8010. orgid := adminUserInfo.Org.Id
  8011. var esdata models.DialysisOrder
  8012. var err error
  8013. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8015. return
  8016. }
  8017. esdata.Hash = esdata.Hash
  8018. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8019. order := models.DialysisOrder{
  8020. Hash: esdata.Hash,
  8021. Url: esdata.Url,
  8022. }
  8023. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8024. redis := service.RedisClient()
  8025. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8026. redis.Set(key, "", time.Second)
  8027. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8028. //清空key 值
  8029. redis.Set(keyOne, "", time.Second)
  8030. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8031. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8032. //redis.Set(keyTwo, "", time.Second)
  8033. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8034. redis.Set(keyThree, "", time.Second)
  8035. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8036. redis.Set(keyFour, "", time.Second)
  8037. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8038. redis.Set(keyFive, "", time.Second)
  8039. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8040. redis.Set(keySix, "", time.Second)
  8041. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8042. redis.Set(keySeven, "", time.Second)
  8043. if err != nil {
  8044. fmt.Println(err)
  8045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8046. return
  8047. }
  8048. this.ServeSuccessJSON(map[string]interface{}{
  8049. "electronic_signature": esdata,
  8050. })
  8051. }
  8052. func (this *DialysisAPIController) GetPatientSign() {
  8053. patient_id, _ := this.GetInt64("patient_id")
  8054. dialysis_date, _ := this.GetInt64("dialysis_date")
  8055. adminUserInfo := this.GetMobileAdminUserInfo()
  8056. orgId := adminUserInfo.Org.Id
  8057. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8058. if err != nil {
  8059. fmt.Println(err)
  8060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8061. return
  8062. }
  8063. this.ServeSuccessJSON(map[string]interface{}{
  8064. "dialysisOrder": dialysisOrder,
  8065. })
  8066. }
  8067. func (this *DialysisAPIController) GetScheduleByPatient() {
  8068. patient_id, _ := this.GetInt64("patient_id")
  8069. schedule_date, _ := this.GetInt64("schedule_date")
  8070. orgid := this.GetMobileAdminUserInfo().Org.Id
  8071. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8072. this.ServeSuccessJSON(map[string]interface{}{
  8073. "schedule": schedule,
  8074. })
  8075. }
  8076. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8077. org_id := this.GetMobileAdminUserInfo().Org.Id
  8078. patient_id, _ := this.GetInt64("patient_id")
  8079. schedule_date, _ := this.GetInt64("schedule_date")
  8080. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8081. this.ServeSuccessJSON(map[string]interface{}{
  8082. "order": order,
  8083. })
  8084. }
  8085. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8086. org_id := this.GetMobileAdminUserInfo().Org.Id
  8087. schedule_date := this.GetString("schedule_date")
  8088. schedule_type, _ := this.GetInt64("schedule_type")
  8089. timeLayout := "2006-01-02"
  8090. loc, _ := time.LoadLocation("Local")
  8091. var startdateunix int64
  8092. if len(schedule_date) > 0 {
  8093. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8094. if err != nil {
  8095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8096. return
  8097. }
  8098. startdateunix = theTime.Unix()
  8099. }
  8100. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8101. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8102. devices, _ := service.GetAllDevicetByListSix(org_id)
  8103. for key, item := range scheduals {
  8104. // 床位信息
  8105. for _, device := range devices {
  8106. if item.BedId == device.ID {
  8107. scheduals[key].DeviceNumber = device
  8108. break
  8109. }
  8110. }
  8111. }
  8112. this.ServeSuccessJSON(map[string]interface{}{
  8113. "list": list,
  8114. "scheduals": scheduals,
  8115. })
  8116. }
  8117. func (this *DialysisAPIController) SavePatientPicture() {
  8118. patient_id, _ := this.GetInt64("patient_id")
  8119. dialysis_date, _ := this.GetInt64("schedule_date")
  8120. avatar := this.GetString("avatar")
  8121. fmt.Println("patient_id", patient_id)
  8122. orgId := this.GetMobileAdminUserInfo().Org.Id
  8123. order := models.DialysisOrder{
  8124. Url: avatar,
  8125. }
  8126. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8127. redis := service.RedisClient()
  8128. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8129. redis.Set(key, "", time.Second)
  8130. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8131. //清空key 值
  8132. redis.Set(keyOne, "", time.Second)
  8133. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8134. redis.Set(keyThree, "", time.Second)
  8135. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8136. redis.Set(keyFour, "", time.Second)
  8137. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8138. redis.Set(keyFive, "", time.Second)
  8139. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8140. redis.Set(keySix, "", time.Second)
  8141. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8142. redis.Set(keySeven, "", time.Second)
  8143. if err != nil {
  8144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8145. return
  8146. }
  8147. this.ServeSuccessJSON(map[string]interface{}{
  8148. "order": order,
  8149. })
  8150. }
  8151. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8152. ids := this.GetString("ids")
  8153. idSplit := strings.Split(ids, ",")
  8154. orgId := this.GetMobileAdminUserInfo().Org.Id
  8155. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8156. execution_time := this.GetString("exce_time")
  8157. timeLayout2 := "2006-01-02 15:04:05"
  8158. loc, _ := time.LoadLocation("Local")
  8159. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8160. if errs != nil {
  8161. utils.ErrorLog(errs.Error())
  8162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8163. return
  8164. }
  8165. //his客户
  8166. if config.IsOpen == 1 {
  8167. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8168. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8169. for _, item := range list {
  8170. for _, it := range adviceList {
  8171. if item.DrugId == it.DrugId {
  8172. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8173. }
  8174. }
  8175. }
  8176. for _, item := range list {
  8177. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8178. var sum_out_count int64
  8179. for _, itemThree := range item.ChildDoctorAdvice {
  8180. var prescribing_number int64
  8181. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8182. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8183. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8184. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8185. }
  8186. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8187. prescribing_number = parseIntPrescribingNumber
  8188. }
  8189. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8190. prescribing_number = parseIntPrescribingNumber
  8191. }
  8192. sum_out_count += prescribing_number
  8193. }
  8194. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8195. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8196. //库存不足
  8197. if sum_out_count > drugStockOut.FlushCount {
  8198. this.ServeSuccessJSON(map[string]interface{}{
  8199. "msg": "2",
  8200. "drug": medical,
  8201. "ids": ids,
  8202. })
  8203. return
  8204. }
  8205. }
  8206. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8207. //执行医嘱
  8208. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8209. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8210. for _, item := range advices {
  8211. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8212. redis := service.RedisClient()
  8213. //清空key 值
  8214. redis.Set(key, "", time.Second)
  8215. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8216. redis.Set(keyTwo, "", time.Second)
  8217. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8218. redis.Set(keyThree, "", time.Second)
  8219. recordDate := theTime.Format("2006-01-02")
  8220. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8221. redis.Set(keyFour, "", time.Second)
  8222. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8223. redis.Set(keyFive, "", time.Second)
  8224. defer redis.Close()
  8225. }
  8226. if errs == nil {
  8227. //药品管理信息
  8228. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8229. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8230. if drugStockConfig.IsOpen == 1 {
  8231. for _, item := range advices {
  8232. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8233. config, _ := service.GetDrugOpenConfigOne(orgId)
  8234. if config.IsOpen != 1 {
  8235. //查询该药品是否有库存
  8236. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8237. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8238. if medical.IsUse == 2 {
  8239. if config.IsOpen != 1 {
  8240. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8241. service.HisDrugsDelivery(orgId, creater, &advice)
  8242. if orgId == 3877 || orgId == 10265 {
  8243. //查询该药品是否有出库记录
  8244. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8245. if len(flowMap) == 0 {
  8246. errs := service.UpdateHisAdviceById(advice.ID)
  8247. if errs != nil {
  8248. drugError := models.XtDrugError{
  8249. UserOrgId: orgId,
  8250. DrugId: item.DrugId,
  8251. RecordDate: item.AdviceDate,
  8252. PatientId: item.PatientId,
  8253. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8254. Status: 1,
  8255. Ctime: time.Now().Unix(),
  8256. Mtime: 0,
  8257. SumCount: 0,
  8258. Prescribingnumber: advice.PrescribingNumber,
  8259. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8260. }
  8261. service.CreateDrugError(drugError)
  8262. }
  8263. this.ServeSuccessJSON(map[string]interface{}{
  8264. "msg": "2",
  8265. "drug": medical,
  8266. "ids": ids,
  8267. })
  8268. return
  8269. }
  8270. }
  8271. }
  8272. if pharmacyConfig.IsOpen != 1 {
  8273. service.HisDrugsDelivery(orgId, creater, &advice)
  8274. if orgId == 3877 || orgId == 10265 {
  8275. //查询该药品是否有出库记录
  8276. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8277. if len(flowMap) == 0 {
  8278. errs := service.UpdateHisAdviceById(advice.ID)
  8279. if errs != nil {
  8280. drugError := models.XtDrugError{
  8281. UserOrgId: orgId,
  8282. DrugId: item.DrugId,
  8283. RecordDate: item.AdviceDate,
  8284. PatientId: item.PatientId,
  8285. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8286. Status: 1,
  8287. Ctime: time.Now().Unix(),
  8288. Mtime: 0,
  8289. SumCount: 0,
  8290. Prescribingnumber: advice.PrescribingNumber,
  8291. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8292. }
  8293. service.CreateDrugError(drugError)
  8294. }
  8295. this.ServeSuccessJSON(map[string]interface{}{
  8296. "msg": "2",
  8297. "drug": medical,
  8298. "ids": ids,
  8299. })
  8300. return
  8301. }
  8302. }
  8303. }
  8304. //更新字典里面的库存
  8305. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8306. var sum_count int64
  8307. for _, its := range stockInfo {
  8308. if its.MaxUnit == medical.MaxUnit {
  8309. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8310. }
  8311. sum_count += its.StockMaxNumber + its.StockMinNumber
  8312. }
  8313. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8314. //剩余库存
  8315. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8316. }
  8317. }
  8318. }
  8319. }
  8320. }
  8321. this.ServeSuccessJSON(map[string]interface{}{
  8322. "msg": "1",
  8323. "ids": ids,
  8324. })
  8325. return
  8326. } else {
  8327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8328. }
  8329. }
  8330. fmt.Println("config233322333223", config.IsOpen)
  8331. //血透客户
  8332. if config.IsOpen == 2 || config.IsOpen == 0 {
  8333. //药品管理信息
  8334. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8335. if drugStockConfig.IsOpen == 1 {
  8336. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8337. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8338. for _, item := range list {
  8339. for _, it := range adviceList {
  8340. if item.DrugId == it.DrugId {
  8341. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8342. }
  8343. }
  8344. }
  8345. for _, item := range list {
  8346. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8347. var sum_out_count int64
  8348. for _, itemThree := range item.ChildDoctorAdvice {
  8349. var prescribing_number int64
  8350. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8351. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8352. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8353. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8354. }
  8355. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8356. prescribing_number = parseIntPrescribingNumber
  8357. }
  8358. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8359. prescribing_number = parseIntPrescribingNumber
  8360. }
  8361. sum_out_count += prescribing_number
  8362. }
  8363. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8364. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8365. //库存不足
  8366. if sum_out_count > drugStockOut.FlushCount {
  8367. this.ServeSuccessJSON(map[string]interface{}{
  8368. "msg": "2",
  8369. "drug": medical,
  8370. "ids": ids,
  8371. })
  8372. return
  8373. }
  8374. }
  8375. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8376. fmt.Println("creater2332243244224242424", creater)
  8377. //执行医嘱
  8378. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8379. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8380. for _, item := range advices {
  8381. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8382. redis := service.RedisClient()
  8383. //清空key 值
  8384. redis.Set(key, "", time.Second)
  8385. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8386. redis.Set(keyTwo, "", time.Second)
  8387. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8388. redis.Set(keyThree, "", time.Second)
  8389. recordDate := theTime.Format("2006-01-02")
  8390. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8391. redis.Set(keyFour, "", time.Second)
  8392. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8393. redis.Set(keyFive, "", time.Second)
  8394. defer redis.Close()
  8395. }
  8396. if errs == nil {
  8397. for _, item := range advices {
  8398. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8399. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8400. //查询是否出库按钮开启
  8401. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8402. if adviceSetting.IsAdviceOpen == 1 {
  8403. //查询是否出库按钮开启
  8404. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8405. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8406. if prescriptionConfig.IsOpen == 1 {
  8407. if medical.IsUse == 2 {
  8408. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8409. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8410. }
  8411. if pharmacyConfig.IsOpen != 1 {
  8412. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8413. }
  8414. //更新字典里面的库存
  8415. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8416. var sum_count int64
  8417. for _, its := range stockInfo {
  8418. if its.MaxUnit == medical.MaxUnit {
  8419. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8420. }
  8421. sum_count += its.StockMaxNumber + its.StockMinNumber
  8422. }
  8423. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8424. //剩余库存
  8425. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8426. }
  8427. }
  8428. } else {
  8429. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8430. if medical.IsUse == 2 {
  8431. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8432. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8433. }
  8434. if pharmacyConfig.IsOpen != 1 {
  8435. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8436. }
  8437. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8438. var sum_count int64
  8439. for _, its := range stockInfo {
  8440. if its.MaxUnit == medical.MaxUnit {
  8441. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8442. }
  8443. sum_count += its.StockMaxNumber + its.StockMinNumber
  8444. }
  8445. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8446. //剩余库存
  8447. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8448. }
  8449. }
  8450. }
  8451. }
  8452. this.ServeSuccessJSON(map[string]interface{}{
  8453. "msg": "1",
  8454. "ids": ids,
  8455. })
  8456. return
  8457. } else {
  8458. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8459. //执行医嘱
  8460. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8461. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8462. for _, item := range advices {
  8463. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8464. redis := service.RedisClient()
  8465. //清空key 值
  8466. redis.Set(key, "", time.Second)
  8467. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8468. redis.Set(keyTwo, "", time.Second)
  8469. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8470. redis.Set(keyThree, "", time.Second)
  8471. recordDate := theTime.Format("2006-01-02")
  8472. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8473. redis.Set(keyFour, "", time.Second)
  8474. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8475. redis.Set(keyFive, "", time.Second)
  8476. defer redis.Close()
  8477. }
  8478. this.ServeSuccessJSON(map[string]interface{}{
  8479. "msg": "1",
  8480. "ids": ids,
  8481. })
  8482. return
  8483. }
  8484. }
  8485. }
  8486. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8487. ids := this.GetString("ids")
  8488. idSplit := strings.Split(ids, ",")
  8489. orgId := this.GetMobileAdminUserInfo().Org.Id
  8490. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8491. if config.IsOpen == 1 {
  8492. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8493. this.ServeSuccessJSON(map[string]interface{}{
  8494. "msg": "1",
  8495. "ids": ids,
  8496. })
  8497. return
  8498. }
  8499. if config.IsOpen == 0 || config.IsOpen == 2 {
  8500. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8501. this.ServeSuccessJSON(map[string]interface{}{
  8502. "msg": "1",
  8503. "ids": ids,
  8504. })
  8505. return
  8506. }
  8507. }
  8508. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8509. ids := this.GetString("ids")
  8510. idSplit := strings.Split(ids, ",")
  8511. orgId := this.GetMobileAdminUserInfo().Org.Id
  8512. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8513. //his
  8514. if config.IsOpen == 1 {
  8515. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8516. theTime := time.Now()
  8517. advices := models.HisDoctorAdviceThirty{
  8518. CheckTime: theTime.Unix(),
  8519. Checker: checker,
  8520. UpdatedTime: time.Now().Unix(),
  8521. }
  8522. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8523. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8524. for _, item := range list {
  8525. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8526. redis := service.RedisClient()
  8527. //清空key 值
  8528. redis.Set(key, "", time.Second)
  8529. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8530. redis.Set(keyTwo, "", time.Second)
  8531. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8532. redis.Set(keyThree, "", time.Second)
  8533. recordDate := theTime.Format("2006-01-02")
  8534. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8535. redis.Set(keyFour, "", time.Second)
  8536. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8537. redis.Set(keyFive, "", time.Second)
  8538. defer redis.Close()
  8539. }
  8540. this.ServeSuccessJSON(map[string]interface{}{
  8541. "msg": "1",
  8542. "ids": ids,
  8543. })
  8544. return
  8545. }
  8546. //血透
  8547. if config.IsOpen == 0 || config.IsOpen == 2 {
  8548. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8549. theTime := time.Now()
  8550. advices := models.DoctorAdvice{
  8551. CheckTime: theTime.Unix(),
  8552. Checker: checker,
  8553. UpdatedTime: time.Now().Unix(),
  8554. }
  8555. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8556. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8557. for _, item := range list {
  8558. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8559. redis := service.RedisClient()
  8560. //清空key 值
  8561. redis.Set(key, "", time.Second)
  8562. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8563. redis.Set(keyTwo, "", time.Second)
  8564. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8565. redis.Set(keyThree, "", time.Second)
  8566. recordDate := theTime.Format("2006-01-02")
  8567. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8568. redis.Set(keyFour, "", time.Second)
  8569. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8570. redis.Set(keyFive, "", time.Second)
  8571. defer redis.Close()
  8572. }
  8573. this.ServeSuccessJSON(map[string]interface{}{
  8574. "msg": "1",
  8575. "ids": ids,
  8576. })
  8577. return
  8578. }
  8579. }
  8580. func (this *DialysisAPIController) CheckSchedule() {
  8581. patientID, _ := this.GetInt64("patient_id")
  8582. recordDateStr := this.GetString("record_date")
  8583. nurseID, _ := this.GetInt64("start_nurse")
  8584. schedual_type, _ := this.GetInt64("schedual_type")
  8585. bedID, _ := this.GetInt64("bed")
  8586. start_time := this.GetString("start_time")
  8587. fmt.Println("patientID", patientID)
  8588. fmt.Println("recordDateStr", recordDateStr)
  8589. fmt.Println("nurseID", nurseID)
  8590. fmt.Println("schedual_type------", schedual_type)
  8591. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8593. return
  8594. }
  8595. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8596. if parseStartDateErr != nil {
  8597. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8599. return
  8600. }
  8601. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8602. if parseErr != nil {
  8603. this.ErrorLog("时间解析失败:%v", parseErr)
  8604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8605. return
  8606. }
  8607. adminUserInfo := this.GetMobileAdminUserInfo()
  8608. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8609. if getPatientErr != nil {
  8610. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8612. return
  8613. } else if patient == nil {
  8614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8615. return
  8616. }
  8617. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8618. if getNurseErr != nil {
  8619. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8621. return
  8622. } else if nurse == nil {
  8623. this.ErrorLog("护士不存在")
  8624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8625. return
  8626. }
  8627. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8628. if getDeviceNumberErr != nil {
  8629. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8631. return
  8632. } else if deviceNumber == nil {
  8633. this.ErrorLog("床位号不存在")
  8634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8635. return
  8636. }
  8637. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8638. if getRecordErr != nil {
  8639. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8641. return
  8642. } else if dialysisRecord != nil {
  8643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8644. return
  8645. }
  8646. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8647. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8648. timeLayout := "2006-01-02 15:04:05"
  8649. loc, _ := time.LoadLocation("Local")
  8650. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8651. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8652. schedulestartTime := theStartTime.Unix()
  8653. scheduleendTime := theEndTime.Unix()
  8654. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8655. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8656. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8657. //查询该床位是否有人用了
  8658. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8659. if err == nil {
  8660. if schedule.ID == 0 {
  8661. this.ServeSuccessJSON(map[string]interface{}{
  8662. "status": 0,
  8663. "msg": "请求失败",
  8664. })
  8665. } else {
  8666. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8667. if order.ID > 0 { //该机位被其他人占用了
  8668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8669. return
  8670. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8671. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8672. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8673. this.ServeSuccessJSON(map[string]interface{}{
  8674. "status": 1,
  8675. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8676. })
  8677. return
  8678. } else {
  8679. this.ServeSuccessJSON(map[string]interface{}{
  8680. "status": 0,
  8681. "msg": "",
  8682. })
  8683. }
  8684. }
  8685. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8686. this.ServeSuccessJSON(map[string]interface{}{
  8687. "status": 2,
  8688. "msg": "当前机位已有患者在使用,请重新选择!",
  8689. })
  8690. }
  8691. }
  8692. } else {
  8693. this.ServeSuccessJSON(map[string]interface{}{
  8694. "status": 0,
  8695. "msg": "",
  8696. })
  8697. }
  8698. }
  8699. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8700. orgId := this.GetMobileAdminUserInfo().Org.Id
  8701. schedule_type, _ := this.GetInt64("schedule_type")
  8702. partion_type, _ := this.GetInt64("partion_type")
  8703. start_time := this.GetString("start_time")
  8704. timeLayout := "2006-01-02"
  8705. loc, _ := time.LoadLocation("Local")
  8706. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8707. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8708. _, config := service.FindXTHisRecordByOrgId(orgId)
  8709. appId := this.GetMobileAdminUserInfo().App.Id
  8710. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8711. if err == nil {
  8712. this.ServeSuccessJSON(map[string]interface{}{
  8713. "list": list,
  8714. "config": config,
  8715. "doctorList": doctorList,
  8716. })
  8717. return
  8718. } else {
  8719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8720. return
  8721. }
  8722. }
  8723. func (this *DialysisAPIController) SaveMobileInformation() {
  8724. patient_id, _ := this.GetInt64("patient_id")
  8725. record_date, _ := this.GetInt64("record_date")
  8726. startTime := this.GetString("start_time")
  8727. module, _ := this.GetInt64("module")
  8728. remark := this.GetString("remark")
  8729. timeLayout := "2006-01-02 15:04"
  8730. loc, _ := time.LoadLocation("Local")
  8731. if len(startTime) == 0 {
  8732. utils.ErrorLog("len(start_time) == 0")
  8733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8734. return
  8735. }
  8736. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8737. if err != nil {
  8738. utils.ErrorLog(err.Error())
  8739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8740. return
  8741. }
  8742. StartTime := theTime.Unix()
  8743. fmt.Println("startime-------------", StartTime)
  8744. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8745. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8746. information := models.XtDialysisInformation{
  8747. Module: module,
  8748. PatientId: patient_id,
  8749. RecordDate: record_date,
  8750. ApplicationDate: StartTime,
  8751. Creater: creater,
  8752. ApplicationStatus: 2,
  8753. Checker: 0,
  8754. CheckTime: 0,
  8755. Remark: remark,
  8756. UserOrgId: user_org_id,
  8757. Ctime: time.Now().Unix(),
  8758. Status: 1,
  8759. Mtime: 0,
  8760. }
  8761. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8762. if infor.ID == 0 {
  8763. service.SaveDialysisInformation(information)
  8764. }
  8765. if infor.ID > 0 {
  8766. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8767. }
  8768. this.ServeSuccessJSON(map[string]interface{}{
  8769. "information": information,
  8770. })
  8771. return
  8772. }
  8773. func (this *DialysisAPIController) GetMobileInformation() {
  8774. limit, _ := this.GetInt64("limit")
  8775. page, _ := this.GetInt64("page")
  8776. orgid := this.GetMobileAdminUserInfo().Org.Id
  8777. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8778. appid := this.GetMobileAdminUserInfo().App.Id
  8779. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8780. patients, _ := service.GetAllpatientThirty(orgid)
  8781. this.ServeSuccessJSON(map[string]interface{}{
  8782. "information": information,
  8783. "total": total,
  8784. "doclist": doclist,
  8785. "patients": patients,
  8786. })
  8787. return
  8788. }
  8789. func (this *DialysisAPIController) GetMobileInformationOne() {
  8790. limit, _ := this.GetInt64("limit")
  8791. page, _ := this.GetInt64("page")
  8792. orgid := this.GetMobileAdminUserInfo().Org.Id
  8793. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8794. appid := this.GetMobileAdminUserInfo().App.Id
  8795. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8796. patients, _ := service.GetAllpatientThirty(orgid)
  8797. this.ServeSuccessJSON(map[string]interface{}{
  8798. "information": information,
  8799. "total": total,
  8800. "doclist": doclist,
  8801. "patients": patients,
  8802. })
  8803. return
  8804. }
  8805. func (this *DialysisAPIController) CheckMobileInformation() {
  8806. id, _ := this.GetInt64("id")
  8807. application_status, _ := this.GetInt64("application_status")
  8808. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8809. checktime := time.Now().Unix()
  8810. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8811. if err == nil {
  8812. this.ServeSuccessJSON(map[string]interface{}{
  8813. "msg": "ok",
  8814. })
  8815. return
  8816. }
  8817. }
  8818. func (c *DialysisAPIController) GetControlMonitorList() {
  8819. partition, _ := c.GetInt64("partition")
  8820. monitorDate := c.GetString("date")
  8821. patient_id, _ := c.GetInt64("patient_id")
  8822. pat_type, _ := c.GetInt64("pat_type")
  8823. timeLayout := "2006-01-02"
  8824. loc, _ := time.LoadLocation("Local")
  8825. var theStartTime int64
  8826. if len(monitorDate) > 0 {
  8827. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8828. if err != nil {
  8829. theStartTime = 0
  8830. }
  8831. theStartTime = theTime.Unix()
  8832. }
  8833. adminInfo := c.GetMobileAdminUserInfo()
  8834. orgID := adminInfo.Org.Id
  8835. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8836. if err != nil {
  8837. c.ErrorLog("获取排班信息失败:%v", err)
  8838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8839. } else {
  8840. if len(monitor) > 0 {
  8841. //获取所有床位
  8842. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8843. //获取所有分区
  8844. zoneList, _ := service.GetAllZoneByList(orgID)
  8845. //获取透析处方
  8846. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8847. //获取透前评估
  8848. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8849. //获取上机
  8850. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8851. //获取透后
  8852. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8853. //获取透后监测
  8854. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8855. //获取所有的患者
  8856. patients, _ := service.GetAllPatientListByListOne(orgID)
  8857. //获取所有透析模式
  8858. treatments, _ := service.GetAllTreatModeByList(orgID)
  8859. //获取所有医嘱
  8860. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8861. //获取双人核对
  8862. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8863. //治疗小结
  8864. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8865. //待消毒
  8866. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8867. for key, item := range monitor {
  8868. // 获取床位信息
  8869. for _, it := range numberList {
  8870. if item.BedId == it.ID {
  8871. monitor[key].DeviceNumber = it
  8872. break
  8873. }
  8874. }
  8875. //获取分区信息
  8876. for _, it := range zoneList {
  8877. if item.PartitionId == it.ID {
  8878. monitor[key].DeviceZone = it
  8879. }
  8880. }
  8881. for _, prescription := range prescriptions {
  8882. if item.PatientId == prescription.PatientId {
  8883. monitor[key].Prescription = prescription
  8884. break
  8885. }
  8886. }
  8887. for _, it := range checkList {
  8888. if item.PatientId == it.PatientId {
  8889. monitor[key].DoubleCheck = it
  8890. break
  8891. }
  8892. }
  8893. for _, it := range summaryList {
  8894. if item.PatientId == it.PatientId {
  8895. monitor[key].TreatmentSummaryForList = it
  8896. break
  8897. }
  8898. }
  8899. // 透前评估
  8900. for _, assessmentBefore := range assessmentBefores {
  8901. if item.PatientId == assessmentBefore.PatientId {
  8902. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8903. break
  8904. }
  8905. }
  8906. // 透析上下机
  8907. for _, dialysisOrder := range dialysisOrders {
  8908. if item.PatientId == dialysisOrder.PatientId {
  8909. monitor[key].DialysisOrder = dialysisOrder
  8910. break
  8911. }
  8912. }
  8913. // 治疗小节
  8914. for _, afterDislysis := range AssessmentAfterDislysis {
  8915. if item.PatientId == afterDislysis.PatientId {
  8916. monitor[key].AssessmentAfterDislysis = afterDislysis
  8917. break
  8918. }
  8919. }
  8920. for _, it := range monitorlist {
  8921. if item.PatientId == it.PatientId {
  8922. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8923. }
  8924. }
  8925. for _, it := range adviceList {
  8926. if item.PatientId == it.PatientId {
  8927. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8928. }
  8929. }
  8930. for _, patient := range patients {
  8931. if item.PatientId == patient.ID {
  8932. monitor[key].MonitorPatients = patient
  8933. break
  8934. }
  8935. }
  8936. for _, treatment := range treatments {
  8937. if item.ModeId == treatment.ID {
  8938. monitor[key].TreatmentMode = treatment
  8939. break
  8940. }
  8941. }
  8942. for _, infor := range informationList {
  8943. if item.PatientId == infor.PatientId {
  8944. monitor[key].NewDeviceInformation = infor
  8945. break
  8946. }
  8947. }
  8948. }
  8949. }
  8950. }
  8951. patients, err := service.GetAllpatientFourty(orgID)
  8952. var mds []*models.NewMonitorDialysisScheduleList
  8953. if pat_type == 0 {
  8954. for _, item := range monitor {
  8955. mds = append(mds, item)
  8956. }
  8957. }
  8958. //待医嘱核对
  8959. if pat_type == 1 {
  8960. for _, item := range monitor {
  8961. if len(item.AdviceList) > 0 {
  8962. mds = append(mds, item)
  8963. }
  8964. }
  8965. }
  8966. //待开小结
  8967. if pat_type == 2 {
  8968. for _, item := range monitor {
  8969. if item.TreatmentSummaryForList == nil {
  8970. mds = append(mds, item)
  8971. }
  8972. }
  8973. }
  8974. //待下机
  8975. if pat_type == 3 {
  8976. for _, item := range monitor {
  8977. if item.DialysisOrder != nil {
  8978. if item.DialysisOrder.ID > 0 {
  8979. mds = append(mds, item)
  8980. }
  8981. }
  8982. }
  8983. }
  8984. //待消毒
  8985. if pat_type == 4 {
  8986. for _, item := range monitor {
  8987. if item.NewDeviceInformation == nil {
  8988. mds = append(mds, item)
  8989. }
  8990. }
  8991. }
  8992. //待双人核对
  8993. if pat_type == 5 {
  8994. for _, item := range monitor {
  8995. if item.DoubleCheck == nil {
  8996. mds = append(mds, item)
  8997. }
  8998. }
  8999. }
  9000. //医嘱未执行
  9001. if pat_type == 6 {
  9002. for _, item := range monitor {
  9003. if len(item.AdviceList) > 0 {
  9004. mds = append(mds, item)
  9005. }
  9006. }
  9007. }
  9008. //患者未签名
  9009. if pat_type == 7 {
  9010. for _, item := range monitor {
  9011. if item.DialysisOrder != nil {
  9012. if item.DialysisOrder.ID > 0 {
  9013. mds = append(mds, item)
  9014. }
  9015. }
  9016. }
  9017. }
  9018. //目标超滤于实际超滤不同
  9019. if pat_type == 8 {
  9020. for _, item := range monitor {
  9021. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9022. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9023. mds = append(mds, item)
  9024. }
  9025. }
  9026. }
  9027. }
  9028. //血压少于5次
  9029. if pat_type == 9 {
  9030. for _, item := range monitor {
  9031. if len(item.MonitoringRecord) < 5 {
  9032. mds = append(mds, item)
  9033. }
  9034. }
  9035. }
  9036. if pat_type == 10 {
  9037. for _, item := range monitor {
  9038. if len(item.MonitoringRecord) == 0 {
  9039. mds = append(mds, item)
  9040. }
  9041. }
  9042. }
  9043. if pat_type == 11 {
  9044. for _, item := range monitor {
  9045. if len(item.MonitoringRecord) > 0 {
  9046. mds = append(mds, item)
  9047. }
  9048. }
  9049. }
  9050. if pat_type == 12 {
  9051. for _, item := range monitor {
  9052. if len(item.MonitoringRecord) > 0 {
  9053. mds = append(mds, item)
  9054. }
  9055. }
  9056. }
  9057. if err == nil {
  9058. c.ServeSuccessJSON(map[string]interface{}{
  9059. "monitor": mds,
  9060. "patients": patients,
  9061. })
  9062. } else {
  9063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9064. }
  9065. }
  9066. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9067. admin_user_id, _ := c.GetInt64("admin_user_id")
  9068. timeStr := time.Now().Format("2006-01-02")
  9069. timeLayout := "2006-01-02 15:04:05"
  9070. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9071. timenow := timeStringToTime.Unix()
  9072. orgId := c.GetMobileAdminUserInfo().Org.Id
  9073. //查询当前护士的患者
  9074. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9075. var patientIds []int64
  9076. for _, item := range orderList {
  9077. patientIds = append(patientIds, item.PatientId)
  9078. }
  9079. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9080. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9081. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9082. //药品管理信息
  9083. _, drugStockConfig := service.FindHisConfig(orgId)
  9084. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9085. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9086. c.ServeSuccessJSON(map[string]interface{}{
  9087. "adviceList": adviceList,
  9088. "hisAdviceList": hisAdviceList,
  9089. "projectList": projectList,
  9090. "drugStockConfig": drugStockConfig,
  9091. "patientList": patientList,
  9092. "projectConfig": projectConfig,
  9093. })
  9094. }
  9095. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9096. patient_id, _ := c.GetInt64("patient_id")
  9097. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9098. c.ServeSuccessJSON(map[string]interface{}{
  9099. "recrods": recrods,
  9100. })
  9101. }
  9102. func (c *DialysisAPIController) ExMobileChangeSch() {
  9103. id_one, _ := c.GetInt64("id_one")
  9104. id_two, _ := c.GetInt64("id_two")
  9105. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9106. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9107. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9108. //if order2.ID > 0 {
  9109. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9110. // return
  9111. //}
  9112. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9113. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9114. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9115. if count > 0 {
  9116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9117. return
  9118. }
  9119. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9120. if count1 > 0 {
  9121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9122. return
  9123. }
  9124. }
  9125. err := service.UpdateScheduleThree(sch, sch_two)
  9126. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9127. if order.ID > 0 {
  9128. //查询该患者的排班机位
  9129. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9130. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9131. redis := service.RedisClient()
  9132. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9133. redis.Set(key, "", time.Second)
  9134. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9135. //清空key 值
  9136. redis.Set(keyOne, "", time.Second)
  9137. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9138. //return
  9139. }
  9140. if err == nil {
  9141. //去除当天患者排班中重复数据,保留最后一条数据
  9142. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9143. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9144. c.ServeSuccessJSON(map[string]interface{}{
  9145. "msg": "交换成功",
  9146. })
  9147. } else {
  9148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9149. return
  9150. }
  9151. }
  9152. func (c *DialysisAPIController) MobileCoverSch() {
  9153. id_one, _ := c.GetInt64("id_one")
  9154. id_two, _ := c.GetInt64("id_two")
  9155. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9156. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9157. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9158. if order.ID > 0 {
  9159. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9160. redis := service.RedisClient()
  9161. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9162. redis.Set(key, "", time.Second)
  9163. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9164. //清空key 值
  9165. redis.Set(keyOne, "", time.Second)
  9166. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9167. //return
  9168. }
  9169. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9170. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9171. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9172. if count > 0 {
  9173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9174. return
  9175. }
  9176. }
  9177. var new_sch models.Schedule
  9178. new_sch = sch
  9179. new_sch.BedId = sch_two.BedId
  9180. new_sch.ScheduleDate = sch_two.ScheduleDate
  9181. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9182. new_sch.PartitionId = sch_two.PartitionId
  9183. new_sch.ScheduleType = sch_two.ScheduleType
  9184. new_sch.ID = 0
  9185. //删除原来的排班
  9186. err := service.SaveSchTwo(sch, sch_two)
  9187. //生成新的排班
  9188. if err == nil {
  9189. err2 := service.SaveSch(&new_sch)
  9190. if err2 == nil {
  9191. //去除当天患者排班中重复数据,保留最后一条数据
  9192. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9193. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9194. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9195. c.ServeSuccessJSON(map[string]interface{}{
  9196. "msg": "覆盖成功",
  9197. "new_sch": new_sch,
  9198. })
  9199. } else {
  9200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9201. return
  9202. }
  9203. } else {
  9204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9205. return
  9206. }
  9207. }