dialysis_api_controller.go 374KB

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